From 1459bf3832b1440e126d96d9177b88edde883956 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sat, 11 Aug 2001 04:17:52 +0000 Subject: I just wrote a stpncpy() since someone wanted it --- include/string.h | 2 ++ libc/string/Makefile | 2 +- libc/string/string.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/string.h b/include/string.h index 7122b7959..4191f7ba1 100644 --- a/include/string.h +++ b/include/string.h @@ -22,6 +22,8 @@ extern char *strcpy __P ((char *__restrict __dest, __const char *__restrict __src)); extern char *stpcpy __P ((char *__restrict __dest, __const char *__restrict __src)); +extern char *stpncpy __P ((char *__restrict __dest, + __const char *__restrict __src, size_t __n)); /* Copy no more than N characters of SRC to DEST. */ extern char *strncpy __P ((char *__restrict __dest, __const char *__restrict __src, size_t __n)); diff --git a/libc/string/Makefile b/libc/string/Makefile index c9b70829e..748a935eb 100644 --- a/libc/string/Makefile +++ b/libc/string/Makefile @@ -26,7 +26,7 @@ include $(TOPDIR)Rules.mak MSRC=string.c MOBJ=strlen.o strcat.o strcpy.o strchr.o strcmp.o strncat.o strncpy.o \ strncmp.o strrchr.o strdup.o memcpy.o memccpy.o memset.o \ - memmove.o memcmp.o memchr.o ffs.o strnlen.o strxfrm.o stpcpy.o + memmove.o memcmp.o memchr.o ffs.o strnlen.o strxfrm.o stpcpy.o stpncpy.o ifeq ($(HAS_LOCALE),true) MOBJ += strcoll.o diff --git a/libc/string/string.c b/libc/string/string.c index d8b8e9f37..7ccc55733 100644 --- a/libc/string/string.c +++ b/libc/string/string.c @@ -79,6 +79,23 @@ char *stpcpy(char *dst, const char *src) } #endif +/********************** Function stpncpy ************************************/ + +#ifdef L_stpncpy +char *stpncpy(char *dst, const char *src, size_t len) +{ + while (len--) { + if (*src) + *dst++ = *src++; + else + *dst++ = '\0'; + } + + return dst; +} +#endif + + /********************** Function strcmp ************************************/ #ifdef L_strcmp -- cgit v1.2.3