diff options
Diffstat (limited to 'lib/compat')
-rw-r--r-- | lib/compat/Makefile.am | 6 | ||||
-rw-r--r-- | lib/compat/compat.h | 6 | ||||
-rw-r--r-- | lib/compat/getopt.c | 2 | ||||
-rw-r--r-- | lib/compat/md5.c | 20 | ||||
-rw-r--r-- | lib/compat/md5.h | 14 | ||||
-rw-r--r-- | lib/compat/scandir.c | 6 | ||||
-rw-r--r-- | lib/compat/strchrnul.c | 37 |
7 files changed, 71 insertions, 20 deletions
diff --git a/lib/compat/Makefile.am b/lib/compat/Makefile.am index 1d5840a25..4477c27b4 100644 --- a/lib/compat/Makefile.am +++ b/lib/compat/Makefile.am @@ -10,6 +10,8 @@ noinst_LTLIBRARIES = libcompat-test.la libcompat.la libcompat_test_la_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_LIBCOMPAT=1 libcompat_test_la_SOURCES = \ compat.h \ + md5.c md5.h \ + strchrnul.c \ strnlen.c \ strndup.c \ strsignal.c \ @@ -56,6 +58,10 @@ if !HAVE_STRNLEN libcompat_la_SOURCES += strnlen.c endif +if !HAVE_STRCHRNUL +libcompat_la_SOURCES += strchrnul.c +endif + if !HAVE_STRNDUP libcompat_la_SOURCES += strndup.c endif diff --git a/lib/compat/compat.h b/lib/compat/compat.h index 320ffdbc9..c1aa60180 100644 --- a/lib/compat/compat.h +++ b/lib/compat/compat.h @@ -109,6 +109,8 @@ extern "C" { #define asprintf test_asprintf #undef vasprintf #define vasprintf test_vasprintf +#undef strchrnul +#define strchrnul test_strchrnul #undef strndup #define strndup test_strndup #undef strnlen @@ -139,6 +141,10 @@ int vasprintf(char **str, const char *fmt, va_list args) LIBCOMPAT_ATTR_VPRINTF(2); #endif +#if TEST_LIBCOMPAT || !defined(HAVE_STRCHRNUL) +char *strchrnul(const char *s, int c); +#endif + #if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN) size_t strnlen(const char *s, size_t n); #endif diff --git a/lib/compat/getopt.c b/lib/compat/getopt.c index 4c52b8b82..b13f81454 100644 --- a/lib/compat/getopt.c +++ b/lib/compat/getopt.c @@ -88,7 +88,7 @@ USA. */ #endif /* XXX: Disable intl support, because we do not carry the translations anyway - * and this pulls indirectly libintl, wich we do not want to impose. */ + * and this pulls indirectly libintl, which we do not want to impose. */ #ifndef _ #define _(msgid) (msgid) #endif diff --git a/lib/compat/md5.c b/lib/compat/md5.c index 3da18c98e..7da974635 100644 --- a/lib/compat/md5.c +++ b/lib/compat/md5.c @@ -41,7 +41,7 @@ (cp)[1] = (value) >> 8; \ (cp)[0] = (value); } while (0) -static u_int8_t PADDING[MD5_BLOCK_LENGTH] = { +static uint8_t PADDING[MD5_BLOCK_LENGTH] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -75,7 +75,7 @@ MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len) need = MD5_BLOCK_LENGTH - have; /* Update bitcount */ - ctx->count += (u_int64_t)len << 3; + ctx->count += (uint64_t)len << 3; if (len >= need) { if (have != 0) { @@ -106,7 +106,7 @@ MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len) void MD5Pad(MD5_CTX *ctx) { - u_int8_t count[8]; + uint8_t count[8]; size_t padlen; /* Convert count to 8 bytes in little endian order. */ @@ -156,19 +156,19 @@ MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx) * the data and converts bytes into longwords for this routine. */ void -MD5Transform(u_int32_t state[4], const u_int8_t block[MD5_BLOCK_LENGTH]) +MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH]) { - u_int32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4]; + uint32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4]; #ifndef WORDS_BIGENDIAN memcpy(in, block, sizeof(in)); #else for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) { - in[a] = (u_int32_t)( - (u_int32_t)(block[a * 4 + 0]) | - (u_int32_t)(block[a * 4 + 1]) << 8 | - (u_int32_t)(block[a * 4 + 2]) << 16 | - (u_int32_t)(block[a * 4 + 3]) << 24); + in[a] = (uint32_t)( + (uint32_t)(block[a * 4 + 0]) | + (uint32_t)(block[a * 4 + 1]) << 8 | + (uint32_t)(block[a * 4 + 2]) << 16 | + (uint32_t)(block[a * 4 + 3]) << 24); } #endif diff --git a/lib/compat/md5.h b/lib/compat/md5.h index f6243603d..b5247d527 100644 --- a/lib/compat/md5.h +++ b/lib/compat/md5.h @@ -15,20 +15,22 @@ #ifndef _MD5_H_ #define _MD5_H_ +#include <stdint.h> + #define MD5_BLOCK_LENGTH 64 #define MD5_DIGEST_LENGTH 16 #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1) typedef struct MD5Context { - u_int32_t state[4]; /* state */ - u_int64_t count; /* number of bits, mod 2^64 */ - u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ + uint32_t state[4]; /* state */ + uint64_t count; /* number of bits, mod 2^64 */ + uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ } MD5_CTX; void MD5Init(MD5_CTX *); -void MD5Update(MD5_CTX *, const u_int8_t *, size_t); +void MD5Update(MD5_CTX *, const uint8_t *, size_t); void MD5Pad(MD5_CTX *); -void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *); -void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH]); +void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *); +void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH]); #endif /* _MD5_H_ */ diff --git a/lib/compat/scandir.c b/lib/compat/scandir.c index 4765d7dcb..8771de093 100644 --- a/lib/compat/scandir.c +++ b/lib/compat/scandir.c @@ -72,13 +72,13 @@ scandir(const char *dir, struct dirent ***namelist, avail *= 2; else avail = 20; - newlist = realloc(list, avail * sizeof(struct dirent *)); + newlist = realloc(list, avail * sizeof(*newlist)); if (!newlist) return cleanup(d, list, used); list = newlist; } - m = malloc(sizeof(struct dirent) + strlen(e->d_name)); + m = malloc(sizeof(*m) + strlen(e->d_name)); if (!m) return cleanup(d, list, used); *m = *e; @@ -91,7 +91,7 @@ scandir(const char *dir, struct dirent ***namelist, closedir(d); if (list != NULL && cmp != NULL) - qsort(list, used, sizeof(struct dirent *), cmp); + qsort(list, used, sizeof(list[0]), cmp); *namelist = list; diff --git a/lib/compat/strchrnul.c b/lib/compat/strchrnul.c new file mode 100644 index 000000000..b072e1ad3 --- /dev/null +++ b/lib/compat/strchrnul.c @@ -0,0 +1,37 @@ +/* + * libcompat - system compatibility library + * + * Copyright © 2018 Guillem Jover <guillem@debian.org> + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include <string.h> +#include <stdlib.h> + +#include "compat.h" + +char * +strchrnul(const char *s, int c) +{ + char *match; + + match = strchr(s, c); + if (match) + return match; + + return (char *)s + strlen(s); +} |