blob: 70ea464c2c287253406fbfc49d480b3f2a10fee4 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <unistd.h>
2#include <sys/types.h>
3#include <byteswap.h>
4
5/* Updated implementation based on byteswap.h from Miles Bader
6 * <miles@gnu.org>. This should be much faster on arches with machine
7 * specific, optimized definitions in include/bits/byteswap.h (i.e. on
8 * x86, use the bswap instruction on i486 and better boxes). For
9 * platforms that lack such support, this should be no slower than it
10 * was before... */
11void swab (const void *source, void *dest, ssize_t count)
12{
13 const unsigned short *from = source, *from_end = from + (count >> 1);
14 unsigned short junk;
15 unsigned short *to = dest;
16
17 while (from < from_end) {
18 /* Don't put '*from++'into the bswap_16() macros
19 * or mad things will happen on macro expansion */
20 junk=*from++;
21 *to++ = bswap_16 (junk);
22 }
23}