Improve file position handling on Big Engian machines

Added swap_HALFs(dest, src, len) function to byteswap.c.

Calc can now handle Big Engian file position sizes that are a
multiple of BASEB bits in length.  Before handle Big Engian file
positions could only be 32 and 64 bits in length.  This will allow,
for example, a Big Engian file position size of 128 (assuming that
128/BASEB is is an integer).
This commit is contained in:
Landon Curt Noll
2022-11-28 15:13:16 -08:00
parent 3e084d9fb9
commit e6fc1a92a9
4 changed files with 61 additions and 4 deletions

View File

@@ -40,7 +40,7 @@
* dest - pointer to where the swapped src will be put or
* NULL to allocate the storage
* src - pointer to a HALF array to swap
* len - length of the src HALF array
* len - length of the src HALF array in HALFs
*
* returns:
* pointer to where the swapped src has been put
@@ -276,7 +276,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* dest - pointer to where the swapped src will be put or
* NULL to allocate the storage
* src - pointer to a HALF array to swap
* len - length of the src HALF array
* len - length of the src HALF array in HALFs
*
* returns:
* pointer to where the swapped src has been put
@@ -309,6 +309,50 @@ swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len)
}
/*
* swap_HALFs - swap HALFs in an array of HALFs
*
* given:
* dest - pointer to where the swapped src will be put or
* NULL to allocate the storage
* src - pointer to a HALF array to swap
* len - length of the src HALF array in HALFs
*
* returns:
* pointer to where the swapped src has been put
*/
HALF *
swap_HALFs(HALF *dest, HALF *src, LEN len)
{
HALF *s; /* src swap pointer */
HALF *d; /* dest swap pointer */
HALF *ret;
LEN i;
/*
* allocate storage if needed
*/
if (dest == NULL) {
dest = alloc(len);
}
ret = dest;
/*
* swap HALFs in the array
*/
s = src;
d = &dest[len-1];
for (i=0; i < len; ++i, --d, ++s) {
*d = *s;
}
/*
* return the result
*/
return ret;
}
/*
* swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE
*