Last change
on this file since 519 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
763 bytes
|
Line | |
---|
1 | /* |
---|
2 | FUNCTION |
---|
3 | <<swab>>---swap adjacent bytes |
---|
4 | |
---|
5 | SYNOPSIS |
---|
6 | #include <unistd.h> |
---|
7 | void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>); |
---|
8 | |
---|
9 | DESCRIPTION |
---|
10 | This function copies <[n]> bytes from the memory region |
---|
11 | pointed to by <[in]> to the memory region pointed to by |
---|
12 | <[out]>, exchanging adjacent even and odd bytes. |
---|
13 | |
---|
14 | PORTABILITY |
---|
15 | <<swab>> requires no supporting OS subroutines. |
---|
16 | */ |
---|
17 | |
---|
18 | #include <unistd.h> |
---|
19 | |
---|
20 | void |
---|
21 | swab (const void *b1, |
---|
22 | void *b2, |
---|
23 | ssize_t length) |
---|
24 | { |
---|
25 | const char *from = b1; |
---|
26 | char *to = b2; |
---|
27 | ssize_t ptr; |
---|
28 | for (ptr = 1; ptr < length; ptr += 2) |
---|
29 | { |
---|
30 | char p = from[ptr]; |
---|
31 | char q = from[ptr-1]; |
---|
32 | to[ptr-1] = p; |
---|
33 | to[ptr ] = q; |
---|
34 | } |
---|
35 | if (ptr == length) /* I.e., if length is odd, */ |
---|
36 | to[ptr-1] = 0; /* then pad with a NUL. */ |
---|
37 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.