aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-11-19 01:51:00 -0600
committerRob Landley <rob@landley.net>2007-11-19 01:51:00 -0600
commite15850ae972957d097eeadfd5721e3ac8f10fd4e (patch)
treefa0a4d4f4404a3476d684a3a50d3ccb9e89548db /lib/lib.c
parentefa93b987a355385d0b1a1ac4e3a0e25db63b494 (diff)
downloadtoybox-e15850ae972957d097eeadfd5721e3ac8f10fd4e.tar.gz
Replace strlcpy() with xstrcpy(), which exits if the string won't fit.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 4cbb2228..5d01efc9 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -11,22 +11,12 @@
#include "toys.h"
-#if !defined(__UCLIBC__) && !defined(__KLIBC__)
-
-// uClibc has this, and if we define our own it conflicts.
-
-// Like strncpy but always null terminated.
-void strlcpy(char *dest, char *src, size_t size)
+// Strcpy with size checking: exit if there's not enough space for the string.
+void xstrcpy(char *dest, char *src, size_t size)
{
- int len = strlen(src);
- if (size--) {
- if (len > size) len=size;
- memcpy(dest,src, len);
- dest[len] = 0;
- }
+ if (strlen(src)+1 > size) error_exit("xstrcpy");
+ strcpy(dest, src);
}
-#endif
-
void verror_msg(char *msg, int err, va_list va)
{
@@ -116,7 +106,7 @@ void *xrealloc(void *ptr, size_t size)
void *xstrndup(char *s, size_t n)
{
void *ret = xmalloc(++n);
- strlcpy(ret, s, n);
+ xstrcpy(ret, s, n);
return ret;
}