diff --git a/DataStr/List.cpp b/DataStr/List.cpp index cd3e00b93da02bc8690744f16399af8274e0db23..117747c7782bc7737b368b39b2df3708c8bc74aa 100644 --- a/DataStr/List.cpp +++ b/DataStr/List.cpp @@ -1,4 +1,4 @@ -/* $Id: List.cpp,v 1.8 2000-11-27 17:13:42 geuzaine Exp $ */ +/* $Id: List.cpp,v 1.9 2000-11-28 08:19:28 geuzaine Exp $ */ #include <stdlib.h> #include <stdio.h> @@ -341,18 +341,20 @@ void List_Copy(List_T *a , List_T *b){ } } -void swap_doubles(double *array, unsigned int n){ - unsigned int i, c; - double x; - char *px, *pp; +void swap_bytes(char *array, int size, int n){ + int i, c; + char *x, *a; + x = (char*)Malloc(size); + for (i = 0; i < n; i++) { - x = array[i]; - px = (char *) &x; - pp = (char *) (array+i); - for (c = 0; c < sizeof(double); ++c) - pp[sizeof(double)-1-c] = px[c]; + a = &array[i*size]; + memcpy(x, a, size); + for (c = 0; c < size; c++) + a[size-1-c] = x[c]; } + + Free(x); } List_T *List_CreateFromFile(int n, int size, FILE *file, int format, int swap){ @@ -369,13 +371,7 @@ List_T *List_CreateFromFile(int n, int size, FILE *file, int format, int swap){ return liste; case LIST_FORMAT_BINARY : fread(liste->array, size, n, file); - if(swap){ - if(size != sizeof(double)){ - Msg(ERROR, "Swapping Bytes only done for doubles"); - return NULL; - } - swap_doubles((double*)liste->array, n); - } + if(swap) swap_bytes(liste->array, size, n); return liste; default : Msg(ERROR, "Unknown List Format");