diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2022-06-01 12:36:34 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2022-06-01 12:36:34 +0000 |
commit | e88276fdec7b3b94ec939f5eb1c8def004ee3878 (patch) | |
tree | 118f28d54fe208fe823e5e4cc775bbf377ea53a4 /src | |
parent | 37b42c179bb00d05cb47c739cb95283548f84fb2 (diff) | |
download | skalibs-e88276fdec7b3b94ec939f5eb1c8def004ee3878.tar.xz |
Rework endianness conversion primitives
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
50 files changed, 156 insertions, 99 deletions
diff --git a/src/headers/bits-bendian b/src/headers/bits-bendian index 6caf1e7..ac1169f 100644 --- a/src/headers/bits-bendian +++ b/src/headers/bits-bendian @@ -1,6 +1,8 @@ -#define uint@BITS@_little_endian(s, n) uint@BITS@_reverse((s), (n)) -#define uint@BITS@_big_endian(s, n) - #define uint@BITS@_little(u) uint@BITS@_bswap(u) #define uint@BITS@_big(u) (u) +#define uint@BITS@_littlep(u) uint@BITS@_bswapp(u) +#define uint@BITS@_bigp(u) + +#define uint@BITS@_littlen(array, n) uint@BITS@_bswapn(array, n) +#define uint@BITS@_bign(array, n) diff --git a/src/headers/bits-lendian b/src/headers/bits-lendian index 7528d46..e2358d3 100644 --- a/src/headers/bits-lendian +++ b/src/headers/bits-lendian @@ -1,6 +1,9 @@ -#define uint@BITS@_little_endian(s, n) -#define uint@BITS@_big_endian(s, n) uint@BITS@_reverse((s), (n)) - #define uint@BITS@_little(u) (u) #define uint@BITS@_big(u) uint@BITS@_bswap(u) +#define uint@BITS@_littlep(u) +#define uint@BITS@_bigp(u) uint@BITS@_bswapp(u) + +#define uint@BITS@_littlen(array, n) +#define uint@BITS@_bign(array, n) uint@BITS@_bswapn(array, n) + diff --git a/src/headers/bits-template b/src/headers/bits-template index f6cde95..306076d 100644 --- a/src/headers/bits-template +++ b/src/headers/bits-template @@ -2,8 +2,9 @@ extern void uint@BITS@_pack (char *, uint@BITS@_t) ; extern void uint@BITS@_pack_big (char *, uint@BITS@_t) ; extern void uint@BITS@_unpack (char const *, uint@BITS@_t *) ; extern void uint@BITS@_unpack_big (char const *, uint@BITS@_t *) ; -extern void uint@BITS@_reverse (char *, size_t) ; extern uint@BITS@_t uint@BITS@_bswap (uint@BITS@_t) ; +extern void uint@BITS@_bswapp (uint@BITS@_t *) ; +extern void uint@BITS@_bswapn (uint@BITS@_t *, size_t) ; #define UINT@BITS@_FMT @DFMT@ #define UINT@BITS@_OFMT @OFMT@ diff --git a/src/headers/unsigned-template b/src/headers/unsigned-template index 8ef6db4..d7496a0 100644 --- a/src/headers/unsigned-template +++ b/src/headers/unsigned-template @@ -4,9 +4,12 @@ #define @type@_unpack uint@BITS@_unpack #define @type@_unpack_big uint@BITS@_unpack_big -#define @type@_reverse uint@BITS@_reverse -#define @type@_big_endian uint@BITS@_big_endian -#define @type@_little_endian uint@BITS@_little_endian +#define @type@_little uint@BITS@_little +#define @type@_big uint@BITS@_big +#define @type@_littlep uint@BITS@_littlep +#define @type@_bigp uint@BITS@_bigp +#define @type@_littlen uint@BITS@_littlen +#define @type@_bign uint@BITS@_bign #define @TYPE@_FMT UINT@BITS@_FMT #define @TYPE@_OFMT UINT@BITS@_OFMT @@ -39,4 +42,3 @@ #define @type@_bscan(s, u) @type@_scan_base(s, (u), 2) #define @type@0_bscan(s, u) @type@0_scan_base(s, (u), 2) - diff --git a/src/libstddjb/socket_accept4.c b/src/libstddjb/socket_accept4.c index 2016777..36f3dc2 100644 --- a/src/libstddjb/socket_accept4.c +++ b/src/libstddjb/socket_accept4.c @@ -2,6 +2,7 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> @@ -14,9 +15,9 @@ int socket_accept4_internal (int s, char *ip, uint16_t *port, unsigned int options) { + int fd ; struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; - int fd ; do #ifdef SKALIBS_HASACCEPT4 fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((options & O_CLOEXEC) ? SOCK_CLOEXEC : 0)) ; @@ -34,6 +35,6 @@ int socket_accept4_internal (int s, char *ip, uint16_t *port, unsigned int optio } #endif memcpy(ip, &sa.sin_addr.s_addr, 4) ; - uint16_unpack_big((char *)&sa.sin_port, port) ; + *port = uint16_big(sa.sin_port) ; return fd ; } diff --git a/src/libstddjb/socket_accept6.c b/src/libstddjb/socket_accept6.c index f5156ca..2c18540 100644 --- a/src/libstddjb/socket_accept6.c +++ b/src/libstddjb/socket_accept6.c @@ -2,6 +2,7 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> @@ -17,9 +18,9 @@ int socket_accept6_internal (int s, char *ip6, uint16_t *port, unsigned int options) { + int fd ; struct sockaddr_in6 sa ; socklen_t dummy = sizeof sa ; - int fd ; do #ifdef SKALIBS_HASACCEPT4 fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((options & O_CLOEXEC) ? SOCK_CLOEXEC : 0)) ; @@ -37,7 +38,7 @@ int socket_accept6_internal (int s, char *ip6, uint16_t *port, unsigned int opti } #endif memcpy(ip6, sa.sin6_addr.s6_addr, 16) ; - uint16_unpack_big((char *)&sa.sin6_port, port) ; + *port = uint16_big(sa.sin6_port) ; return fd ; } diff --git a/src/libstddjb/socket_bind4.c b/src/libstddjb/socket_bind4.c index cc1a079..b654a61 100644 --- a/src/libstddjb/socket_bind4.c +++ b/src/libstddjb/socket_bind4.c @@ -1,9 +1,11 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <string.h> #include <netinet/in.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> @@ -12,8 +14,7 @@ int socket_bind4 (int s, char const *ip, uint16_t port) struct sockaddr_in sa ; memset(&sa, 0, sizeof sa) ; sa.sin_family = AF_INET ; - uint16_big_endian((char *)&port, 1) ; - sa.sin_port = port ; + sa.sin_port = uint16_big(port) ; memcpy(&sa.sin_addr.s_addr, ip, 4) ; return bind(s, (struct sockaddr *)&sa, sizeof sa) ; } diff --git a/src/libstddjb/socket_bind4r.c b/src/libstddjb/socket_bind4r.c index 6c4b7e2..e46a4bb 100644 --- a/src/libstddjb/socket_bind4r.c +++ b/src/libstddjb/socket_bind4r.c @@ -1,7 +1,9 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> + #include <skalibs/socket.h> int socket_bind4_reuse (int s, char const *ip, uint16_t port) diff --git a/src/libstddjb/socket_bind6.c b/src/libstddjb/socket_bind6.c index ca14052..6090ad9 100644 --- a/src/libstddjb/socket_bind6.c +++ b/src/libstddjb/socket_bind6.c @@ -1,10 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> #include <skalibs/ip46.h> @@ -16,7 +18,7 @@ int socket_bind6 (int s, char const *ip6, uint16_t port) struct sockaddr_in6 sa ; memset(&sa, 0, sizeof sa) ; sa.sin6_family = AF_INET6 ; - uint16_pack_big((char *)&sa.sin6_port, port) ; + sa.sin6_port = uint16_big(port) ; memcpy(sa.sin6_addr.s6_addr, ip6, 16) ; return bind(s, (struct sockaddr *)&sa, sizeof sa) ; } diff --git a/src/libstddjb/socket_bind6r.c b/src/libstddjb/socket_bind6r.c index e52876a..0854262 100644 --- a/src/libstddjb/socket_bind6r.c +++ b/src/libstddjb/socket_bind6r.c @@ -1,7 +1,9 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> + #include <skalibs/socket.h> int socket_bind6_reuse (int s, char const *ip6, uint16_t port) diff --git a/src/libstddjb/socket_conn4.c b/src/libstddjb/socket_connect4.c index ee9eacb..a6dcadf 100644 --- a/src/libstddjb/socket_conn4.c +++ b/src/libstddjb/socket_connect4.c @@ -1,21 +1,22 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <errno.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> int socket_connect4 (int s, char const *ip, uint16_t port) { - struct sockaddr_in sa ; int r ; + struct sockaddr_in sa ; memset(&sa, 0, sizeof sa) ; sa.sin_family = AF_INET ; - uint16_big_endian((char *)&port, 1) ; - sa.sin_port = port ; + sa.sin_port = uint16_big(port) ; memcpy(&sa.sin_addr.s_addr, ip, 4) ; do r = connect(s, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; diff --git a/src/libstddjb/socket_conn4_u32.c b/src/libstddjb/socket_connect4_u32.c index 6061e65..6061e65 100644 --- a/src/libstddjb/socket_conn4_u32.c +++ b/src/libstddjb/socket_connect4_u32.c diff --git a/src/libstddjb/socket_conn6.c b/src/libstddjb/socket_connect6.c index 612545d..f5186e0 100644 --- a/src/libstddjb/socket_conn6.c +++ b/src/libstddjb/socket_connect6.c @@ -1,10 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <errno.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> #include <skalibs/ip46.h> @@ -17,7 +19,7 @@ int socket_connect6 (int s, char const *ip6, uint16_t port) int r ; memset(&sa, 0, sizeof sa) ; sa.sin6_family = AF_INET6 ; - uint16_pack_big((char *)&sa.sin6_port,port) ; + sa.sin6_port = uint16_big(port) ; memcpy(sa.sin6_addr.s6_addr, ip6, 16) ; do r = connect(s, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; diff --git a/src/libstddjb/socket_connected.c b/src/libstddjb/socket_connected.c index 58ca463..2768b4c 100644 --- a/src/libstddjb/socket_connected.c +++ b/src/libstddjb/socket_connected.c @@ -1,8 +1,10 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> + #include <skalibs/allreadwrite.h> #include <skalibs/socket.h> diff --git a/src/libstddjb/socket_internal.c b/src/libstddjb/socket_internal.c index 852f323..39c6e38 100644 --- a/src/libstddjb/socket_internal.c +++ b/src/libstddjb/socket_internal.c @@ -2,6 +2,7 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <fcntl.h> diff --git a/src/libstddjb/socket_ioloop.c b/src/libstddjb/socket_ioloop.c index aa674b0..2b0f90c 100644 --- a/src/libstddjb/socket_ioloop.c +++ b/src/libstddjb/socket_ioloop.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <errno.h> + #include <skalibs/error.h> #include <skalibs/iopause.h> #include <skalibs/socket.h> diff --git a/src/libstddjb/socket_local4.c b/src/libstddjb/socket_local4.c index 03628e1..2cc0e70 100644 --- a/src/libstddjb/socket_local4.c +++ b/src/libstddjb/socket_local4.c @@ -1,9 +1,11 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> @@ -11,9 +13,8 @@ int socket_local4 (int s, char *ip, uint16_t *port) { struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; - if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) - return -1 ; + if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, &sa.sin_addr.s_addr, 4) ; - uint16_unpack_big((char *)&sa.sin_port, port) ; + *port = uint16_big(sa.sin_port) ; return 0 ; } diff --git a/src/libstddjb/socket_local46.c b/src/libstddjb/socket_local46.c index aaf1da0..0fd2c5b 100644 --- a/src/libstddjb/socket_local46.c +++ b/src/libstddjb/socket_local46.c @@ -21,14 +21,14 @@ int socket_local46 (int s, ip46 *ip, uint16_t *port) { struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa ; memcpy(ip->ip, sa6->sin6_addr.s6_addr, 16) ; - uint16_unpack_big((char *)&sa6->sin6_port, port) ; + *port = uint16_big(sa6->sin6_port) ; ip->is6 = 1 ; } else if (sa.ss_family == AF_INET) { struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa ; memcpy(ip->ip, &sa4->sin_addr.s_addr, 4) ; - uint16_unpack_big((char *)&sa4->sin_port, port) ; + *port = uint16_big(sa4->sin_port) ; ip->is6 = 0 ; } else return (errno = EAFNOSUPPORT, -1) ; diff --git a/src/libstddjb/socket_local6.c b/src/libstddjb/socket_local6.c index 7f74943..e0dd162 100644 --- a/src/libstddjb/socket_local6.c +++ b/src/libstddjb/socket_local6.c @@ -1,9 +1,11 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> #include <skalibs/ip46.h> @@ -14,10 +16,9 @@ int socket_local6 (int s, char *ip, uint16_t *port) { struct sockaddr_in6 sa ; socklen_t dummy = sizeof sa ; - if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) - return -1 ; + if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, sa.sin6_addr.s6_addr, 16) ; - uint16_unpack_big((char *)&sa.sin6_port, port) ; + *port = uint16_big(sa.sin6_port) ; return 0 ; } diff --git a/src/libstddjb/socket_recv4.c b/src/libstddjb/socket_recv4.c index 844cc0b..afaaa9a 100644 --- a/src/libstddjb/socket_recv4.c +++ b/src/libstddjb/socket_recv4.c @@ -1,22 +1,24 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <errno.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> ssize_t socket_recv4 (int s, char *buf, size_t len, char *ip, uint16_t *port) { + ssize_t r ; struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; - ssize_t r ; do r = recvfrom(s, buf, len, 0, (struct sockaddr *)&sa, &dummy) ; while ((r == -1) && (errno == EINTR)) ; if (r == -1) return -1 ; memcpy(ip, &sa.sin_addr, 4) ; - uint16_unpack_big((char *)&sa.sin_port, port) ; + *port = uint16_big(sa.sin_port) ; return r ; } diff --git a/src/libstddjb/socket_recv6.c b/src/libstddjb/socket_recv6.c index 2c9733f..fccb4f5 100644 --- a/src/libstddjb/socket_recv6.c +++ b/src/libstddjb/socket_recv6.c @@ -1,10 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> #include <string.h> + #include <skalibs/uint16.h> #include <skalibs/ip46.h> #include <skalibs/socket.h> @@ -20,7 +22,7 @@ ssize_t socket_recv6 (int s, char *buf, size_t len, char *ip6, uint16_t *port) while ((r == -1) && (errno == EINTR)) ; if (r == -1) return -1 ; memcpy(ip6, sa.sin6_addr.s6_addr, 16) ; - uint16_unpack_big((char *)&sa.sin6_port, port) ; + *port = uint16_big(sa.sin6_port) ; return r ; } diff --git a/src/libstddjb/socket_remote4.c b/src/libstddjb/socket_remote4.c index 19b8756..7d8613b 100644 --- a/src/libstddjb/socket_remote4.c +++ b/src/libstddjb/socket_remote4.c @@ -1,9 +1,11 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> @@ -11,9 +13,8 @@ int socket_remote4 (int s, char *ip, uint16_t *port) { struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; - if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) - return -1 ; + if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, &sa.sin_addr.s_addr, 4) ; - uint16_unpack_big((char *)&sa.sin_port, port) ; + *port = uint16_big(sa.sin_port) ; return 0 ; } diff --git a/src/libstddjb/socket_remote46.c b/src/libstddjb/socket_remote46.c index d0f1548..1a2d924 100644 --- a/src/libstddjb/socket_remote46.c +++ b/src/libstddjb/socket_remote46.c @@ -21,14 +21,14 @@ int socket_remote46 (int s, ip46 *ip, uint16_t *port) { struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa ; memcpy(ip->ip, sa6->sin6_addr.s6_addr, 16) ; - uint16_unpack_big((char *)&sa6->sin6_port, port) ; + *port = uint16_big(sa6->sin6_port) ; ip->is6 = 1 ; } else if (sa.ss_family == AF_INET) { struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa ; memcpy(ip->ip, &sa4->sin_addr.s_addr, 4) ; - uint16_unpack_big((char *)&sa4->sin_port, port) ; + *port = uint16_big(sa4->sin_port) ; ip->is6 = 0 ; } else return (errno = EAFNOSUPPORT, -1) ; diff --git a/src/libstddjb/socket_remote6.c b/src/libstddjb/socket_remote6.c index 6736581..411d222 100644 --- a/src/libstddjb/socket_remote6.c +++ b/src/libstddjb/socket_remote6.c @@ -1,10 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> + #include <skalibs/uint16.h> #include <skalibs/ip46.h> #include <skalibs/socket.h> @@ -15,10 +17,9 @@ int socket_remote6 (int s, char *ip, uint16_t *port) { struct sockaddr_in6 sa ; socklen_t dummy = sizeof sa ; - if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) - return -1 ; + if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, sa.sin6_addr.s6_addr, 16) ; - uint16_unpack_big((char *)&sa.sin6_port, port) ; + *port = uint16_big(sa.sin6_port) ; return 0 ; } diff --git a/src/libstddjb/socket_send4.c b/src/libstddjb/socket_send4.c index cc358cf..81e991f 100644 --- a/src/libstddjb/socket_send4.c +++ b/src/libstddjb/socket_send4.c @@ -1,20 +1,22 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <errno.h> + #include <skalibs/uint16.h> #include <skalibs/socket.h> ssize_t socket_send4 (int s, char const *buf, size_t len, char const *ip, uint16_t port) { - struct sockaddr_in sa ; ssize_t r ; + struct sockaddr_in sa ; memset(&sa, 0, sizeof sa) ; sa.sin_family = AF_INET ; - uint16_pack_big((char *)&sa.sin_port, port) ; + sa.sin_port = uint16_big(port) ; memcpy(&sa.sin_addr, ip, 4) ; do r = sendto(s, buf, len, 0, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; diff --git a/src/libstddjb/socket_send6.c b/src/libstddjb/socket_send6.c index 807f2a0..6eb276b 100644 --- a/src/libstddjb/socket_send6.c +++ b/src/libstddjb/socket_send6.c @@ -1,10 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <string.h> #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> + #include <skalibs/uint16.h> #include <skalibs/ip46.h> #include <skalibs/socket.h> @@ -13,11 +15,11 @@ ssize_t socket_send6 (int s, char const *buf, size_t len, char const *ip6, uint16_t port) { - struct sockaddr_in6 sa ; ssize_t r ; + struct sockaddr_in6 sa ; memset(&sa, 0, sizeof sa) ; sa.sin6_family = AF_INET6 ; - uint16_pack_big((char *)&sa.sin6_port, port) ; + sa.sin6_port = uint16_big(port) ; memcpy(sa.sin6_addr.s6_addr, ip6, 16) ; do r = sendto(s, buf, len, 0, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; diff --git a/src/libstddjb/socket_delay.c b/src/libstddjb/socket_tcpnodelay.c index 7d1a8db..5ea10b0 100644 --- a/src/libstddjb/socket_delay.c +++ b/src/libstddjb/socket_tcpnodelay.c @@ -1,9 +1,11 @@ /* ISC license. */ #include <skalibs/nonposix.h> + #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> + #include <skalibs/socket.h> int socket_tcpnodelay (int s) diff --git a/src/libstddjb/socket_tryr.c b/src/libstddjb/socket_tryreservein.c index 26c04b2..26c04b2 100644 --- a/src/libstddjb/socket_tryr.c +++ b/src/libstddjb/socket_tryreservein.c diff --git a/src/libstddjb/socket_waitconn.c b/src/libstddjb/socket_waitconn.c index a69fed8..9a8ac3d 100644 --- a/src/libstddjb/socket_waitconn.c +++ b/src/libstddjb/socket_waitconn.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <errno.h> + #include <skalibs/allreadwrite.h> #include <skalibs/iopause.h> #include <skalibs/socket.h> diff --git a/src/libstddjb/uint16_bswapn.c b/src/libstddjb/uint16_bswapn.c new file mode 100644 index 0000000..0d51e0b --- /dev/null +++ b/src/libstddjb/uint16_bswapn.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <stddef.h> + +#include <skalibs/uint16.h> + +void uint16_bswapn (uint16_t *x, size_t n) +{ + while (n--) uint16_bswapp(x++) ; +} diff --git a/src/libstddjb/uint16_bswapp.c b/src/libstddjb/uint16_bswapp.c new file mode 100644 index 0000000..5d235cb --- /dev/null +++ b/src/libstddjb/uint16_bswapp.c @@ -0,0 +1,8 @@ +/* ISC license. */ + +#include <skalibs/uint16.h> + +void uint16_bswapp (uint16_t *x) +{ + *x = uint16_bswap(*x) ; +} diff --git a/src/libstddjb/uint16_pack.c b/src/libstddjb/uint16_pack.c index e7ffe24..353c421 100644 --- a/src/libstddjb/uint16_pack.c +++ b/src/libstddjb/uint16_pack.c @@ -2,10 +2,11 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint16.h> void uint16_pack (char *s, uint16_t u) { - u = uint16_little(u) ; + uint16_littlep(u) ; memcpy(s, &u, sizeof(uint16_t)) ; } diff --git a/src/libstddjb/uint16_pack_big.c b/src/libstddjb/uint16_pack_big.c index c24f78f..68342ba 100644 --- a/src/libstddjb/uint16_pack_big.c +++ b/src/libstddjb/uint16_pack_big.c @@ -2,10 +2,11 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint16.h> void uint16_pack_big (char *s, uint16_t u) { - u = uint16_big(u) ; + uint16_bigp(&u) ; memcpy(s, &u, sizeof(uint16_t)) ; } diff --git a/src/libstddjb/uint16_reverse.c b/src/libstddjb/uint16_reverse.c deleted file mode 100644 index 4fa0a7b..0000000 --- a/src/libstddjb/uint16_reverse.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint16.h> - -void uint16_reverse (char *s, size_t n) -{ - while (n--) - { - char c = s[0] ; - s[0] = s[1] ; - s[1] = c ; - s += 2 ; - } -} diff --git a/src/libstddjb/uint16_unpack.c b/src/libstddjb/uint16_unpack.c index ea31ebc..8c06b36 100644 --- a/src/libstddjb/uint16_unpack.c +++ b/src/libstddjb/uint16_unpack.c @@ -2,6 +2,7 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint16.h> void uint16_unpack (char const *s, uint16_t *u) diff --git a/src/libstddjb/uint16_unpack_big.c b/src/libstddjb/uint16_unpack_big.c index 3f6f0df..b09abcd 100644 --- a/src/libstddjb/uint16_unpack_big.c +++ b/src/libstddjb/uint16_unpack_big.c @@ -2,6 +2,7 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint16.h> void uint16_unpack_big (char const *s, uint16_t *u) diff --git a/src/libstddjb/uint32_bswapn.c b/src/libstddjb/uint32_bswapn.c new file mode 100644 index 0000000..faf731d --- /dev/null +++ b/src/libstddjb/uint32_bswapn.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <stddef.h> + +#include <skalibs/uint32.h> + +void uint32_bswapn (uint32_t *x, size_t n) +{ + while (n--) uint32_bswapp(x++) ; +} diff --git a/src/libstddjb/uint32_bswapp.c b/src/libstddjb/uint32_bswapp.c new file mode 100644 index 0000000..b18e80b --- /dev/null +++ b/src/libstddjb/uint32_bswapp.c @@ -0,0 +1,8 @@ +/* ISC license. */ + +#include <skalibs/uint32.h> + +void uint32_bswapp (uint32_t *x) +{ + *x = uint32_bswap(*x) ; +} diff --git a/src/libstddjb/uint32_pack.c b/src/libstddjb/uint32_pack.c index a06ccf1..b38bfeb 100644 --- a/src/libstddjb/uint32_pack.c +++ b/src/libstddjb/uint32_pack.c @@ -2,10 +2,11 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint32.h> void uint32_pack (char *s, uint32_t u) { - u = uint32_little(u) ; + uint32_littlep(u) ; memcpy(s, &u, sizeof(uint32_t)) ; } diff --git a/src/libstddjb/uint32_pack_big.c b/src/libstddjb/uint32_pack_big.c index e861e7e..33bf9da 100644 --- a/src/libstddjb/uint32_pack_big.c +++ b/src/libstddjb/uint32_pack_big.c @@ -2,10 +2,11 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint32.h> void uint32_pack_big (char *s, uint32_t u) { - u = uint32_big(u) ; + uint32_bigp(&u) ; memcpy(s, &u, sizeof(uint32_t)) ; } diff --git a/src/libstddjb/uint32_reverse.c b/src/libstddjb/uint32_reverse.c deleted file mode 100644 index 2d3f915..0000000 --- a/src/libstddjb/uint32_reverse.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <string.h> -#include <skalibs/uint32.h> - -void uint32_reverse (char *s, size_t n) -{ - while (n--) - { - uint32_t x ; - memcpy(&x, s, sizeof(uint32_t)) ; - x = uint32_bswap(x) ; - memcpy(s, &x, sizeof(uint32_t)) ; - s += sizeof(uint32_t) ; - } -} diff --git a/src/libstddjb/uint32_unpack.c b/src/libstddjb/uint32_unpack.c index 78aca79..9d86ac3 100644 --- a/src/libstddjb/uint32_unpack.c +++ b/src/libstddjb/uint32_unpack.c @@ -2,6 +2,7 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint32.h> void uint32_unpack (char const *s, uint32_t *u) diff --git a/src/libstddjb/uint32_unpack_big.c b/src/libstddjb/uint32_unpack_big.c index 307141f..f31540a 100644 --- a/src/libstddjb/uint32_unpack_big.c +++ b/src/libstddjb/uint32_unpack_big.c @@ -2,6 +2,7 @@ #include <stdint.h> #include <string.h> + #include <skalibs/uint32.h> void uint32_unpack_big (char const *s, uint32_t *u) diff --git a/src/libstddjb/uint64_bswapn.c b/src/libstddjb/uint64_bswapn.c new file mode 100644 index 0000000..afb7d1d --- /dev/null +++ b/src/libstddjb/uint64_bswapn.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <stddef.h> + +#include <skalibs/uint64.h> + +void uint64_bswapn (uint64_t *x, size_t n) +{ + while (n--) uint64_bswapp(x++) ; +} diff --git a/src/libstddjb/uint64_bswapp.c b/src/libstddjb/uint64_bswapp.c new file mode 100644 index 0000000..0afc549 --- /dev/null +++ b/src/libstddjb/uint64_bswapp.c @@ -0,0 +1,8 @@ +/* ISC license. */ + +#include <skalibs/uint64.h> + +void uint64_bswapp (uint64_t *x) +{ + *x = uint64_bswap(*x) ; +} diff --git a/src/libstddjb/uint64_pack.c b/src/libstddjb/uint64_pack.c index 18033da..5e8025c 100644 --- a/src/libstddjb/uint64_pack.c +++ b/src/libstddjb/uint64_pack.c @@ -1,10 +1,11 @@ /* ISC license. */ #include <string.h> + #include <skalibs/uint64.h> void uint64_pack (char *s, uint64_t u) { - u = uint64_little(u) ; + uint64_littlep(&u) ; memcpy(s, &u, sizeof(uint64_t)) ; } diff --git a/src/libstddjb/uint64_pack_big.c b/src/libstddjb/uint64_pack_big.c index c0bbcd7..811bd8f 100644 --- a/src/libstddjb/uint64_pack_big.c +++ b/src/libstddjb/uint64_pack_big.c @@ -1,10 +1,11 @@ /* ISC license. */ #include <string.h> + #include <skalibs/uint64.h> void uint64_pack_big (char *s, uint64_t u) { - u = uint64_big(u) ; + uint64_bigp(&u) ; memcpy(s, &u, sizeof(uint64_t)) ; } diff --git a/src/libstddjb/uint64_reverse.c b/src/libstddjb/uint64_reverse.c deleted file mode 100644 index a870b31..0000000 --- a/src/libstddjb/uint64_reverse.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint64.h> - -void uint64_reverse (char *s, size_t n) -{ - while (n--) - { - uint64_t x ; - memcpy(&x, s, sizeof(uint64_t)) ; - x = uint64_bswap(x) ; - memcpy(s, &x, sizeof(uint64_t)) ; - s += sizeof(uint64_t) ; - } -} diff --git a/src/libstddjb/uint64_unpack.c b/src/libstddjb/uint64_unpack.c index ca7aad9..bea378a 100644 --- a/src/libstddjb/uint64_unpack.c +++ b/src/libstddjb/uint64_unpack.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <string.h> + #include <skalibs/uint64.h> void uint64_unpack (char const *s, uint64_t *u) diff --git a/src/libstddjb/uint64_unpack_big.c b/src/libstddjb/uint64_unpack_big.c index f4e7d52..43ea79e 100644 --- a/src/libstddjb/uint64_unpack_big.c +++ b/src/libstddjb/uint64_unpack_big.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <string.h> + #include <skalibs/uint64.h> void uint64_unpack_big (char const *s, uint64_t *u) |