diff options
Diffstat (limited to 'package/toolbox/src/lib')
-rw-r--r-- | package/toolbox/src/lib/Makefile | 24 | ||||
-rw-r--r-- | package/toolbox/src/lib/fgetln.c | 48 | ||||
-rw-r--r-- | package/toolbox/src/lib/md5.c | 242 | ||||
-rw-r--r-- | package/toolbox/src/lib/md5.h | 48 | ||||
-rw-r--r-- | package/toolbox/src/lib/md5hlp.c | 13 | ||||
-rw-r--r-- | package/toolbox/src/lib/string.h | 9 | ||||
-rw-r--r-- | package/toolbox/src/lib/strlfun.c | 185 |
7 files changed, 569 insertions, 0 deletions
diff --git a/package/toolbox/src/lib/Makefile b/package/toolbox/src/lib/Makefile new file mode 100644 index 000000000..4954e48c4 --- /dev/null +++ b/package/toolbox/src/lib/Makefile @@ -0,0 +1,24 @@ +LIB= oadk_toolbox +SRCS+= fgetln.c +SRCS+= md5.c md5hlp.c +CLEANFILES+= lib${LIB}.a + +include ../common.mk + +OBJS+= strlcpy.o strlcat.o + +all: lib${LIB}.a + +lib${LIB}.a: ${OBJS} + ar rc $@ ${OBJS} + -ranlib $@ + +CFLAGS_strlcpy.o=-DOUTSIDE_OF_LIBKERN -DL_strlcpy +strlcpy.o: strlfun.c + ${COMPILE.c} -o $@ $< +CFLAGS_strlcat.o=-DOUTSIDE_OF_LIBKERN -DL_strlcat +strlcat.o: strlfun.c + ${COMPILE.c} -o $@ $< + +install: + # nothing to do here diff --git a/package/toolbox/src/lib/fgetln.c b/package/toolbox/src/lib/fgetln.c new file mode 100644 index 000000000..647cf9faa --- /dev/null +++ b/package/toolbox/src/lib/fgetln.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2007, 2009 + * Thorsten Glaser <tg@mirbsd.org> + * + * Provided that these terms and disclaimer and all copyright notices + * are retained or reproduced in an accompanying document, permission + * is granted to deal in this work without restriction, including un- + * limited rights to use, publicly perform, distribute, sell, modify, + * merge, give away, or sublicence. + * + * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to + * the utmost extent permitted by applicable law, neither express nor + * implied; without malicious intent or gross negligence. In no event + * may a licensor, author or contributor be held liable for indirect, + * direct, other damage, loss, or other issues arising in any way out + * of dealing in the work, even if advised of the possibility of such + * damage or existence of a defect, except proven that it results out + * of said person's immediate fault when using the work as intended. + *- + * fgetln() wrapper for operating systems with getline() – glibc + */ + +#undef _GNU_SOURCE +#define _GNU_SOURCE /* for getline() */ +#include <sys/types.h> +#include <stdio.h> +#include <string.h> + +__RCSID("$MirOS: contrib/code/mirmake/dist/contrib/fgetln.c,v 1.7 2014/12/20 22:23:29 tg Exp $"); + +char *fgetln(FILE *, size_t *); + +char * +fgetln(FILE *stream, size_t *len) +{ + static char *lb = NULL; + static size_t lbsz = 0; + + if ((*len = getline(&lb, &lbsz, stream)) != (size_t)-1) + /* getdelim ensures *len is not 0 here */ + return (lb); + + /* not required by manpage, but reference implementation does this */ + *len = 0; + + /* not required to zero lb or lbsz: getdelim manages it */ + return (NULL); +} diff --git a/package/toolbox/src/lib/md5.c b/package/toolbox/src/lib/md5.c new file mode 100644 index 000000000..ea933408d --- /dev/null +++ b/package/toolbox/src/lib/md5.c @@ -0,0 +1,242 @@ +/* $OpenBSD: md5.c,v 1.8 2005/08/08 08:05:35 espie Exp $ */ + +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to MD5Init, call MD5Update as + * needed on buffers full of bytes, and then call MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ + +#include <sys/types.h> +#include <stdint.h> +#include <string.h> +#include <md5.h> + +extern const uint8_t RFC1321_padding[64]; + +__RCSID("$MirOS: src/lib/libc/hash/md5.c,v 1.3 2009/11/09 21:36:39 tg Exp $"); + +#define PUT_64BIT_LE(cp, value) do { \ + (cp)[7] = (value) >> 56; \ + (cp)[6] = (value) >> 48; \ + (cp)[5] = (value) >> 40; \ + (cp)[4] = (value) >> 32; \ + (cp)[3] = (value) >> 24; \ + (cp)[2] = (value) >> 16; \ + (cp)[1] = (value) >> 8; \ + (cp)[0] = (value); } while (0) + +#define PUT_32BIT_LE(cp, value) do { \ + (cp)[3] = (value) >> 24; \ + (cp)[2] = (value) >> 16; \ + (cp)[1] = (value) >> 8; \ + (cp)[0] = (value); } while (0) + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +void +MD5Init(MD5_CTX *ctx) +{ + ctx->count = 0; + ctx->state[0] = 0x67452301; + ctx->state[1] = 0xefcdab89; + ctx->state[2] = 0x98badcfe; + ctx->state[3] = 0x10325476; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +void +MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len) +{ + size_t have, need; + + /* Check how many bytes we already have and how many more we need. */ + have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)); + need = MD5_BLOCK_LENGTH - have; + + /* Update bitcount */ + ctx->count += (u_int64_t)len << 3; + + if (len >= need) { + if (have != 0) { + memcpy(ctx->buffer + have, input, need); + MD5Transform(ctx->state, ctx->buffer); + input += need; + len -= need; + have = 0; + } + + /* Process data in MD5_BLOCK_LENGTH-byte chunks. */ + while (len >= MD5_BLOCK_LENGTH) { + MD5Transform(ctx->state, input); + input += MD5_BLOCK_LENGTH; + len -= MD5_BLOCK_LENGTH; + } + } + + /* Handle any remaining bytes of data. */ + if (len != 0) + memcpy(ctx->buffer + have, input, len); +} + +/* + * Pad pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +void +MD5Pad(MD5_CTX *ctx) +{ + u_int8_t count[8]; + + /* Convert count to 8 bytes in little endian order. */ + PUT_64BIT_LE(count, ctx->count); + + /* Pad out to 56 mod 64. */ + MD5Update(ctx, RFC1321_padding, 64 - (((ctx->count >> 3) + 8) & 63)); + MD5Update(ctx, count, 8); +} + +/* + * Final wrapup--call MD5Pad, fill in digest and zero out ctx. + */ +void +MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx) +{ + int i; + + MD5Pad(ctx); + if (digest != NULL) { + for (i = 0; i < 4; i++) + PUT_32BIT_LE(digest + i * 4, ctx->state[i]); + memset(ctx, 0, sizeof(*ctx)); + } +} + + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * 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]) +{ + u_int32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4]; + +#if BYTE_ORDER == LITTLE_ENDIAN + 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); + } +#endif + + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + + MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[ 9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[ 6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[ 5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[ 9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[ 8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[ 7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[ 8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[ 7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[ 9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2 ] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7 ] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5 ] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3 ] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1 ] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8 ] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6 ] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4 ] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2 ] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9 ] + 0xeb86d391, 21); + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; +} diff --git a/package/toolbox/src/lib/md5.h b/package/toolbox/src/lib/md5.h new file mode 100644 index 000000000..ac47848be --- /dev/null +++ b/package/toolbox/src/lib/md5.h @@ -0,0 +1,48 @@ +/* $MirOS: src/kern/include/md5.h,v 1.4 2014/12/20 22:28:45 tg Exp $ */ + +#ifndef SYSKERN_MD5_H +#define SYSKERN_MD5_H + +#ifdef __MirBSD__ +#include <machine/types.h> +#endif + +#define MD5_BLOCK_LENGTH 64 +#define MD5_DIGEST_LENGTH 16 +#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1) + +typedef struct MD5Context { + uint32_t state[4]; + uint64_t count; + uint8_t buffer[MD5_BLOCK_LENGTH]; +} MD5_CTX; + +__BEGIN_DECLS + +/* low-level functions */ +void MD5Init(MD5_CTX *); +void MD5Update(MD5_CTX *, const uint8_t *, size_t) + __attribute__((__bounded__(__string__, 2, 3))); +void MD5Pad(MD5_CTX *); +void MD5Final(uint8_t *, MD5_CTX *) + __attribute__((__bounded__(__minbytes__, 1, MD5_DIGEST_LENGTH))); +void MD5Transform(uint32_t *, const uint8_t *) + __attribute__((__bounded__(__minbytes__, 1, 16))) + __attribute__((__bounded__(__minbytes__, 2, MD5_BLOCK_LENGTH))); + +#if !defined(_KERNEL) && !defined(_STANDALONE) +/* high-level functions from helper.c */ +char *MD5End(MD5_CTX *, char *) + __attribute__((__bounded__(__minbytes__, 2, MD5_DIGEST_STRING_LENGTH))); +char *MD5File(const char *, char *) + __attribute__((__bounded__(__minbytes__, 2, MD5_DIGEST_STRING_LENGTH))); +char *MD5FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__, 2, MD5_DIGEST_STRING_LENGTH))); +char *MD5Data(const uint8_t *, size_t, char *) + __attribute__((__bounded__(__string__, 1, 2))) + __attribute__((__bounded__(__minbytes__, 3, MD5_DIGEST_STRING_LENGTH))); +#endif + +__END_DECLS + +#endif diff --git a/package/toolbox/src/lib/md5hlp.c b/package/toolbox/src/lib/md5hlp.c new file mode 100644 index 000000000..9c7958a73 --- /dev/null +++ b/package/toolbox/src/lib/md5hlp.c @@ -0,0 +1,13 @@ +/* collection of data, not copyrightable */ + +#include <sys/types.h> +#include <stdint.h> + +__RCSID("$MirOS: src/kern/c/miscdata.c,v 1.1 2011/11/20 18:28:09 tg Exp $"); + +const uint8_t RFC1321_padding[64] = { + 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 +}; diff --git a/package/toolbox/src/lib/string.h b/package/toolbox/src/lib/string.h new file mode 100644 index 000000000..571cba664 --- /dev/null +++ b/package/toolbox/src/lib/string.h @@ -0,0 +1,9 @@ +#ifndef LIBOADK_STRING_H +#define LIBOADK_STRING_H + +#include_next <string.h> + +size_t strlcat(char *, const char *, size_t); +size_t strlcpy(char *, const char *, size_t); + +#endif diff --git a/package/toolbox/src/lib/strlfun.c b/package/toolbox/src/lib/strlfun.c new file mode 100644 index 000000000..123eb3d12 --- /dev/null +++ b/package/toolbox/src/lib/strlfun.c @@ -0,0 +1,185 @@ +#if 0 /* comment in gmake; next line ignored by gcc */ +ifeq (0,gmake ignores from here) +#endif +/*- + * Copyright (c) 2006, 2008, 2011 + * mirabilos <m@mirbsd.org> + * + * Provided that these terms and disclaimer and all copyright notices + * are retained or reproduced in an accompanying document, permission + * is granted to deal in this work without restriction, including un- + * limited rights to use, publicly perform, distribute, sell, modify, + * merge, give away, or sublicence. + * + * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to + * the utmost extent permitted by applicable law, neither express nor + * implied; without malicious intent or gross negligence. In no event + * may a licensor, author or contributor be held liable for indirect, + * direct, other damage, loss, or other issues arising in any way out + * of dealing in the work, even if advised of the possibility of such + * damage or existence of a defect, except proven that it results out + * of said person's immediate fault when using the work as intended. + *- + * The original implementations of strlcpy(3) and strlcat(3) are from + * Todd C. Miller; the licence is reproduced below. However, this ap- + * plies only to the strlcpy(3) portion of the code, as Thorsten Gla- + * ser write the following strlcat(3) implementation according to the + * spec. Both functions below have been optimised according to sugge- + * stions from Bodo Eggert. mirabilos merged the code with strxfrm(3) + * (Unicode-only systems) and the wide character variants wcslcat(3), + * wcslcpy(3), and wcsxfrm(3). + */ + +#include <sys/types.h> +#ifndef OUTSIDE_OF_LIBKERN +#include <libckern.h> +#endif + +#ifndef __RCSID +#define __RCSID(x) static const char __rcsid[] = x +#endif + +__RCSID("$MirOS: src/kern/c/strlfun.c,v 1.5 2016/03/06 13:47:13 tg Exp $"); + +#ifdef WIDEC +#ifdef OUTSIDE_OF_LIBKERN +#ifdef __WCHAR_TYPE__ +typedef __WCHAR_TYPE__ wchar_t; +#else +#include <wchar.h> +#endif +#endif +/* wide character string functions */ +#define NUL L'\0' +#define char_t wchar_t +#define fn_len wcslen +#define fn_cat wcslcat +#define fn_cpy wcslcpy +#else +/* (multibyte) string functions */ +#define NUL '\0' +#define char_t char +#define fn_len strlen +#define fn_cat strlcat +#define fn_cpy strlcpy +#endif + +#ifdef L_strxfrm +#define strlcpy strxfrm +#define wcslcpy wcsxfrm +#define L_strlcpy +#endif + +#ifdef OUTSIDE_OF_LIBKERN +extern size_t fn_len(const char_t *); +#endif + +#ifndef __predict_true +#define __predict_true(exp) (exp) +#define __predict_false(exp) (exp) +#endif + +#ifdef L_strlcat +/* + * Appends src to string dst of size dlen (unlike strncat, dlen is the + * full size of dst, not space left). At most dlen-1 characters + * will be copied. Always NUL terminates (unless dlen <= strlen(dst)). + * Returns strlen(src) + MIN(dlen, strlen(initial dst)), without the + * trailing NUL byte counted. If retval >= dlen, truncation occurred. + */ +size_t +fn_cat(char_t *dst, const char_t *src, size_t dlen) +{ + size_t n = 0, slen; + + slen = fn_len(src); + while (__predict_true(n + 1 < dlen && dst[n] != NUL)) + ++n; + if (__predict_false(dlen == 0 || dst[n] != NUL)) + return (dlen + slen); + while (__predict_true((slen > 0) && (n < (dlen - 1)))) { + dst[n++] = *src++; + --slen; + } + dst[n] = NUL; + return (n + slen); +} +#endif + +#ifdef L_strlcpy +/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ + +/*- + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +fn_cpy(char_t *dst, const char_t *src, size_t siz) +{ + const char_t *s = src; + + if (__predict_false(siz == 0)) + goto traverse_src; + + /* copy as many chars as will fit */ + while (--siz && (*dst++ = *s++)) + ; + + /* not enough room in dst */ + if (__predict_false(siz == 0)) { + /* safe to NUL-terminate dst since we copied <= siz-1 chars */ + *dst = NUL; + traverse_src: + /* traverse rest of src */ + while (*s++) + ; + } + + /* count does not include NUL */ + return (s - src - 1); +} +#endif + +#if 0 /* gcc ignored from here; gmake stops ignoring */ +endif + +USE_WIDEC?= 1 + +LIB= libstrlfun.a +OBJS= strlcpy.o strlcat.o +ifeq (1,$(strip $(USE_WIDEC))) +OBJS+= wcslcpy.o wcslcat.o +endif +DEFS= -DOUTSIDE_OF_LIBKERN +DEFS_strlcpy.o= -DL_strlcpy +DEFS_strlcat.o= -DL_strlcat +DEFS_wcslcpy.o= -DL_strlcpy -DWIDEC +DEFS_wcslcat.o= -DL_strlcat -DWIDEC + +all: $(LIB) + +$(LIB): $(OBJS) + ar rc $(LIB) $(OBJS) + -ranlib $(LIB) + +$(OBJS): strlfun.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) $(DEFS_$@) -c -o $@ strlfun.c + +#endif /* EOF for gmake and gcc */ |