commit 73ebb5709dc2a5aaee1e676a3c1b0bb7cebcd392
parent 90767eae542f72b7069a3575bc55944cebc749b6
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Wed, 8 Apr 2015 12:28:47 +0000
- added str_nlen()
- various fixes for --enable-libc-replacements
Diffstat:
16 files changed, 25 insertions(+), 35 deletions(-)
diff --git a/src/include/skalibs/bytestr.h b/src/include/skalibs/bytestr.h
@@ -19,6 +19,7 @@
#define byte_diff(a, n, b) memcmp(a, (b), n)
#define byte_zero(p, n) memset(p, 0, n)
#define str_len(s) strlen(s)
+#define str_nlen(s, max) strnlen(s, max)
#define str_diff(a, b) strcmp(a, b)
#define str_diffn(a, b, n) strncmp(a, b, n)
#define str_copy(to, from) strlen(strcpy(to, from))
@@ -30,6 +31,7 @@ extern void byte_copyr (char *, unsigned int, char const *) ;
extern int byte_diff (char const *, unsigned int, char const *) gccattr_pure ;
extern void byte_zero (void *, unsigned int) ;
extern unsigned int str_len (char const *) gccattr_pure ;
+#define str_nlen(s, max) byte_chr(s, (max), 0)
extern int str_diff (char const *, char const *) gccattr_pure ;
extern int str_diffn (char const *, char const *, unsigned int) gccattr_pure ;
extern unsigned int str_copy (char *, char const *) ;
diff --git a/src/libstdcrypto/md5_final.c b/src/libstdcrypto/md5_final.c
@@ -21,8 +21,8 @@ void md5_final (MD5Schedule *ctx, char *digest /* 16 chars */)
else byte_zero(p, count - 8) ;
uint32_little_endian((char *)ctx->in, 14) ;
- byte_copy(ctx->in + 56, 4, (char *)&ctx->bits[0]) ;
- byte_copy(ctx->in + 60, 4, (char *)&ctx->bits[1]) ;
+ byte_copy((char *)ctx->in + 56, 4, (char *)&ctx->bits[0]) ;
+ byte_copy((char *)ctx->in + 60, 4, (char *)&ctx->bits[1]) ;
md5_transform(ctx->buf, (uint32 *)ctx->in) ;
uint32_little_endian((char *)ctx->buf, 4) ;
diff --git a/src/libstdcrypto/sha512_update.c b/src/libstdcrypto/sha512_update.c
@@ -10,7 +10,7 @@ void sha512_update (SHA512Schedule *ctx, char const *buf, unsigned int len)
ctx->len += len ;
if (pad && len >= 128 - pad)
{
- byte_copy(ctx->buf + pad, 128 - pad, buf) ;
+ byte_copy((char *)ctx->buf + pad, 128 - pad, buf) ;
buf += 128 - pad ; len -= 128 - pad ; pad = 0 ;
sha512_transform(ctx, ctx->buf) ;
}
@@ -20,5 +20,5 @@ void sha512_update (SHA512Schedule *ctx, char const *buf, unsigned int len)
sha512_transform(ctx, (unsigned char const *)buf) ;
buf += 128 ; len -= 128 ;
}
- byte_copy(ctx->buf + pad, len, buf) ;
+ byte_copy((char *)ctx->buf + pad, len, buf) ;
}
diff --git a/src/libstddjb/byte_chr.c b/src/libstddjb/byte_chr.c
@@ -17,17 +17,10 @@ unsigned int byte_chr (char const *s, unsigned int n, int c)
unsigned int byte_chr (char const *s, unsigned int n, int c)
{
+ register unsigned int i = 0 ;
register char ch = c ;
- register char const *t = s ;
-
- for (;;)
- {
- if (!n) break; if (*t == ch) break; ++t; --n;
- if (!n) break; if (*t == ch) break; ++t; --n;
- if (!n) break; if (*t == ch) break; ++t; --n;
- if (!n) break; if (*t == ch) break; ++t; --n;
- }
- return t - s ;
+ for (; i < n && *s++ != ch ; i++) ;
+ return i ;
}
#endif
diff --git a/src/libstddjb/socket_accept6.c b/src/libstddjb/socket_accept6.c
@@ -36,7 +36,7 @@ int socket_accept6_internal (int s, char *ip6, uint16 *port, unsigned int option
return -1 ;
}
#endif
- byte_copy(ip6, 16, sa.sin6_addr.s6_addr) ;
+ byte_copy(ip6, 16, (char const *)sa.sin6_addr.s6_addr) ;
uint16_unpack_big((char *)&sa.sin6_port, port) ;
return fd ;
}
diff --git a/src/libstddjb/socket_bind4.c b/src/libstddjb/socket_bind4.c
@@ -14,6 +14,6 @@ int socket_bind4 (int s, char const *ip, uint16 port)
sa.sin_family = AF_INET ;
uint16_big_endian((char *)&port, 1) ;
sa.sin_port = port ;
- byte_copy(&sa.sin_addr.s_addr, 4, ip) ;
+ byte_copy((char *)&sa.sin_addr.s_addr, 4, ip) ;
return bind(s, (struct sockaddr *)&sa, sizeof sa) ;
}
diff --git a/src/libstddjb/socket_bind6.c b/src/libstddjb/socket_bind6.c
@@ -17,7 +17,7 @@ int socket_bind6 (int s, char const *ip6, uint16 port)
byte_zero(&sa, sizeof sa) ;
sa.sin6_family = AF_INET6 ;
uint16_pack_big((char *)&sa.sin6_port, port) ;
- byte_copy(sa.sin6_addr.s6_addr, 16, ip6) ;
+ byte_copy((char *)sa.sin6_addr.s6_addr, 16, ip6) ;
return bind(s, (struct sockaddr *)&sa, sizeof sa) ;
}
diff --git a/src/libstddjb/socket_conn4.c b/src/libstddjb/socket_conn4.c
@@ -16,7 +16,7 @@ int socket_connect4 (int s, char const *ip, uint16 port)
sa.sin_family = AF_INET ;
uint16_big_endian((char *)&port, 1) ;
sa.sin_port = port ;
- byte_copy(&sa.sin_addr.s_addr, 4, ip) ;
+ byte_copy((char *)&sa.sin_addr.s_addr, 4, ip) ;
do r = connect(s, (struct sockaddr *)&sa, sizeof sa) ;
while ((r == -1) && (errno == EINTR)) ;
if ((r == -1) && (errno == EALREADY)) errno = EINPROGRESS ;
diff --git a/src/libstddjb/socket_conn6.c b/src/libstddjb/socket_conn6.c
@@ -18,7 +18,7 @@ int socket_connect6 (int s, char const *ip6, uint16 port)
byte_zero(&sa, sizeof sa) ;
sa.sin6_family = AF_INET6 ;
uint16_pack_big((char *)&sa.sin6_port,port) ;
- byte_copy(sa.sin6_addr.s6_addr, 16, ip6) ;
+ byte_copy((char *)sa.sin6_addr.s6_addr, 16, ip6) ;
do r = connect(s, (struct sockaddr *)&sa, sizeof sa) ;
while ((r == -1) && (errno == EINTR)) ;
if ((r == -1) && (errno == EALREADY)) errno = EINPROGRESS ;
diff --git a/src/libstddjb/socket_local46.c b/src/libstddjb/socket_local46.c
@@ -18,14 +18,14 @@ int socket_local46 (int s, ip46_t *ip, uint16 *port)
if (sa.sa_family == AF_INET6)
{
register struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa ;
- byte_copy(ip->ip, 16, sa6->sin6_addr.s6_addr) ;
+ byte_copy(ip->ip, 16, (char const *)sa6->sin6_addr.s6_addr) ;
uint16_unpack_big((char *)&sa6->sin6_port, port) ;
ip->is6 = 1 ;
}
else if (sa.sa_family == AF_INET)
{
register struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa ;
- byte_copy(ip->ip, 4, &sa4->sin_addr.s_addr) ;
+ byte_copy(ip->ip, 4, (char const *)&sa4->sin_addr.s_addr) ;
uint16_unpack_big((char *)&sa4->sin_port, port) ;
ip->is6 = 0 ;
}
diff --git a/src/libstddjb/socket_local6.c b/src/libstddjb/socket_local6.c
@@ -17,7 +17,7 @@ int socket_local6 (int s, char *ip, uint16 *port)
if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1)
return -1 ;
- byte_copy(ip, 16, sa.sin6_addr.s6_addr) ;
+ byte_copy(ip, 16, (char const *)sa.sin6_addr.s6_addr) ;
uint16_unpack_big((char *)&sa.sin6_port, port) ;
return 0 ;
}
diff --git a/src/libstddjb/socket_recv6.c b/src/libstddjb/socket_recv6.c
@@ -19,7 +19,7 @@ int socket_recv6 (int s, char *buf, unsigned int len, char *ip6, uint16 *port)
do r = recvfrom(s, buf, len, 0, (struct sockaddr *)&sa, &dummy) ;
while ((r == -1) && (errno == EINTR)) ;
if (r == -1) return -1 ;
- byte_copy(ip6, 16, sa.sin6_addr.s6_addr) ;
+ byte_copy(ip6, 16, (char const *)sa.sin6_addr.s6_addr) ;
uint16_unpack_big((char *)&sa.sin6_port, port) ;
return r ;
}
diff --git a/src/libstddjb/socket_remote46.c b/src/libstddjb/socket_remote46.c
@@ -18,14 +18,14 @@ int socket_remote46 (int s, ip46_t *ip, uint16 *port)
if (sa.sa_family == AF_INET6)
{
register struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa ;
- byte_copy(ip->ip, 16, sa6->sin6_addr.s6_addr) ;
+ byte_copy(ip->ip, 16, (char const *)sa6->sin6_addr.s6_addr) ;
uint16_unpack_big((char *)&sa6->sin6_port, port) ;
ip->is6 = 1 ;
}
else if (sa.sa_family == AF_INET)
{
register struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa ;
- byte_copy(ip->ip, 4, &sa4->sin_addr.s_addr) ;
+ byte_copy(ip->ip, 4, (char const *)&sa4->sin_addr.s_addr) ;
uint16_unpack_big((char *)&sa4->sin_port, port) ;
ip->is6 = 0 ;
}
diff --git a/src/libstddjb/socket_remote6.c b/src/libstddjb/socket_remote6.c
@@ -18,7 +18,7 @@ int socket_remote6 (int s, char *ip, uint16 *port)
if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1)
return -1 ;
- byte_copy(ip, 16, sa.sin6_addr.s6_addr) ;
+ byte_copy(ip, 16, (char const *)sa.sin6_addr.s6_addr) ;
uint16_unpack_big((char *)&sa.sin6_port, port) ;
return 0 ;
}
diff --git a/src/libstddjb/socket_send6.c b/src/libstddjb/socket_send6.c
@@ -18,7 +18,7 @@ int socket_send6 (int s, char const *buf, unsigned int len, char const *ip6, uin
byte_zero((char *)&sa, sizeof sa) ;
sa.sin6_family = AF_INET6 ;
uint16_pack_big((char *)&sa.sin6_port, port) ;
- byte_copy(sa.sin6_addr.s6_addr, 16, ip6) ;
+ byte_copy((char *)sa.sin6_addr.s6_addr, 16, ip6) ;
do r = sendto(s, buf, len, 0, (struct sockaddr *)&sa, sizeof sa) ;
while ((r == -1) && (errno == EINTR)) ;
return r ;
diff --git a/src/libstddjb/str_len.c b/src/libstddjb/str_len.c
@@ -8,14 +8,9 @@
unsigned int str_len (char const *s)
{
- register char const *t = s ;
- for (;;)
- {
- if (!*t) return t - s; ++t;
- if (!*t) return t - s; ++t;
- if (!*t) return t - s; ++t;
- if (!*t) return t - s; ++t;
- }
+ register unsigned int len = 0 ;
+ while (*s++) len++ ;
+ return len ;
}
#endif