From 5723e501abb675701352eb3e9fd58bb3cc2c649d Mon Sep 17 00:00:00 2001 From: Jacques Vidrine Date: Tue, 29 Apr 2003 21:13:50 +0000 Subject: `Hide' strlcpy and strlcat (using the namespace.h / __weak_reference technique) so that we don't wind up calling into an application's version if the application defines them. Inspired by: qpopper's interfering and buggy version of strlcpy --- lib/libc/string/strerror.c | 8 +++++--- lib/libc/string/strlcat.c | 5 ++++- lib/libc/string/strlcpy.c | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'lib/libc/string') diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index 02fba0cfcd39..0c20ac38c289 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -37,9 +37,11 @@ static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; #include __FBSDID("$FreeBSD$"); +#include "namespace.h" #include #include #include +#include "un-namespace.h" #define UPREFIX "Unknown error: " @@ -69,8 +71,8 @@ errstr(int num, char *buf, size_t len) } while (uerr /= 10); if (num < 0) *--t = '-'; - strlcpy(buf, UPREFIX, len); - strlcat(buf, t, len); + _strlcpy(buf, UPREFIX, len); + _strlcat(buf, t, len); } int @@ -81,7 +83,7 @@ strerror_r(int errnum, char *strerrbuf, size_t buflen) errstr(errnum, strerrbuf, buflen); return (EINVAL); } - if (strlcpy(strerrbuf, sys_errlist[errnum], buflen) >= buflen) + if (_strlcpy(strerrbuf, sys_errlist[errnum], buflen) >= buflen) return (ERANGE); return (0); } diff --git a/lib/libc/string/strlcat.c b/lib/libc/string/strlcat.c index 2c2fa568e223..cd9fc433b3f6 100644 --- a/lib/libc/string/strlcat.c +++ b/lib/libc/string/strlcat.c @@ -33,9 +33,12 @@ static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp #include __FBSDID("$FreeBSD$"); +#include "namespace.h" #include #include +#include "un-namespace.h" +__weak_reference(_strlcat, strlcat); /* * Appends src to string dst of size siz (unlike strncat, siz is the * full size of dst, not space left). At most siz-1 characters @@ -44,7 +47,7 @@ __FBSDID("$FreeBSD$"); * If retval >= siz, truncation occurred. */ size_t -strlcat(dst, src, siz) +_strlcat(dst, src, siz) char *dst; const char *src; size_t siz; diff --git a/lib/libc/string/strlcpy.c b/lib/libc/string/strlcpy.c index a8a6cb7da86b..74f511d78378 100644 --- a/lib/libc/string/strlcpy.c +++ b/lib/libc/string/strlcpy.c @@ -33,15 +33,18 @@ static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp #include __FBSDID("$FreeBSD$"); +#include "namespace.h" #include #include +#include "un-namespace.h" +__weak_reference(_strlcpy, strlcpy); /* * 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 strlcpy(dst, src, siz) +size_t _strlcpy(dst, src, siz) char *dst; const char *src; size_t siz; -- cgit v1.3