* libc/include/string.h: Add prototypes for stpcpy and stpncpy.
* libc/string/Makefile.am (ELIX_SOURCES): Add stpcpy.c and stpncpy.c. (CHEWOUT_FILES): Add stpcpy.def and stpncpy.def. * libc/string/Makefile.in: Regenerate. * libc/string/stpcpy.c: New file. * libc/string/stpncpy.c: New file. * libc/string/strings.tex: Add stpcpy and stpncpy.
This commit is contained in:
		| @@ -1,3 +1,14 @@ | |||||||
|  | 2007-06-28  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* libc/include/string.h: Add prototypes for stpcpy and stpncpy. | ||||||
|  | 	* libc/string/Makefile.am (ELIX_SOURCES): Add stpcpy.c and | ||||||
|  | 	stpncpy.c. | ||||||
|  | 	(CHEWOUT_FILES): Add stpcpy.def and stpncpy.def. | ||||||
|  | 	* libc/string/Makefile.in: Regenerate. | ||||||
|  | 	* libc/string/stpcpy.c: New file. | ||||||
|  | 	* libc/string/stpncpy.c: New file. | ||||||
|  | 	* libc/string/strings.tex: Add stpcpy and stpncpy. | ||||||
|  |  | ||||||
| 2007-06-27  Eric Blake  <ebb9@byu.net> | 2007-06-27  Eric Blake  <ebb9@byu.net> | ||||||
|  |  | ||||||
| 	Support __func__ in assert, as required by C99. | 	Support __func__ in assert, as required by C99. | ||||||
|   | |||||||
| @@ -60,6 +60,8 @@ _PTR	 _EXFUN(mempcpy,(_PTR, const _PTR, size_t)); | |||||||
| extern void *memmem (__const void *, size_t,  __const void *, size_t); | extern void *memmem (__const void *, size_t,  __const void *, size_t); | ||||||
| #endif | #endif | ||||||
| char 	*_EXFUN(rindex,(const char *, int)); | char 	*_EXFUN(rindex,(const char *, int)); | ||||||
|  | char 	*_EXFUN(stpcpy,(char *, const char *)); | ||||||
|  | char 	*_EXFUN(stpncpy,(char *, const char *, size_t)); | ||||||
| int	 _EXFUN(strcasecmp,(const char *, const char *)); | int	 _EXFUN(strcasecmp,(const char *, const char *)); | ||||||
| char	*_EXFUN(strcasestr,(const char *, const char *)); | char	*_EXFUN(strcasestr,(const char *, const char *)); | ||||||
| char 	*_EXFUN(strdup,(const char *)); | char 	*_EXFUN(strdup,(const char *)); | ||||||
|   | |||||||
| @@ -77,6 +77,8 @@ ELIX_SOURCES = \ | |||||||
| 	bcmp.c \ | 	bcmp.c \ | ||||||
| 	memccpy.c \ | 	memccpy.c \ | ||||||
| 	mempcpy.c \ | 	mempcpy.c \ | ||||||
|  | 	stpcpy.c \ | ||||||
|  | 	stpncpy.c \ | ||||||
| 	strndup.c \ | 	strndup.c \ | ||||||
| 	strcasestr.c \ | 	strcasestr.c \ | ||||||
| 	strndup_r.c | 	strndup_r.c | ||||||
| @@ -105,7 +107,7 @@ index.def	rindex.def	strcspn.def	strpbrk.def swab.def \ | |||||||
| memchr.def	strcat.def	strerror.def	strerror_r.def strrchr.def \ | memchr.def	strcat.def	strerror.def	strerror_r.def strrchr.def \ | ||||||
| memcmp.def	strchr.def	strlen.def	strnlen.def strspn.def \ | memcmp.def	strchr.def	strlen.def	strnlen.def strspn.def \ | ||||||
| strcasecmp.def	strncasecmp.def strcasestr.def	strlwr.def  strupr.def \ | strcasecmp.def	strncasecmp.def strcasestr.def	strlwr.def  strupr.def \ | ||||||
| memccpy.def 	mempcpy.def \ | memccpy.def 	mempcpy.def	stpcpy.def	stpncpy.def \ | ||||||
| wcscat.def	wcschr.def	wcscmp.def	wcscoll.def \ | wcscat.def	wcschr.def	wcscmp.def	wcscoll.def \ | ||||||
| wcscpy.def	wcscspn.def \ | wcscpy.def	wcscspn.def \ | ||||||
| wcslcat.def	wcslcpy.def	wcslen.def	wcsncat.def \ | wcslcat.def	wcslcpy.def	wcslen.def	wcsncat.def \ | ||||||
|   | |||||||
| @@ -90,6 +90,8 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \ | |||||||
| @ELIX_LEVEL_1_FALSE@am__objects_2 = lib_a-bcmp.$(OBJEXT) \ | @ELIX_LEVEL_1_FALSE@am__objects_2 = lib_a-bcmp.$(OBJEXT) \ | ||||||
| @ELIX_LEVEL_1_FALSE@	lib_a-memccpy.$(OBJEXT) \ | @ELIX_LEVEL_1_FALSE@	lib_a-memccpy.$(OBJEXT) \ | ||||||
| @ELIX_LEVEL_1_FALSE@	lib_a-mempcpy.$(OBJEXT) \ | @ELIX_LEVEL_1_FALSE@	lib_a-mempcpy.$(OBJEXT) \ | ||||||
|  | @ELIX_LEVEL_1_FALSE@	lib_a-stpcpy.$(OBJEXT) \ | ||||||
|  | @ELIX_LEVEL_1_FALSE@	lib_a-stpncpy.$(OBJEXT) \ | ||||||
| @ELIX_LEVEL_1_FALSE@	lib_a-strndup.$(OBJEXT) \ | @ELIX_LEVEL_1_FALSE@	lib_a-strndup.$(OBJEXT) \ | ||||||
| @ELIX_LEVEL_1_FALSE@	lib_a-strcasestr.$(OBJEXT) \ | @ELIX_LEVEL_1_FALSE@	lib_a-strcasestr.$(OBJEXT) \ | ||||||
| @ELIX_LEVEL_1_FALSE@	lib_a-strndup_r.$(OBJEXT) | @ELIX_LEVEL_1_FALSE@	lib_a-strndup_r.$(OBJEXT) | ||||||
| @@ -100,19 +102,20 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) | |||||||
| libstring_la_LIBADD = | libstring_la_LIBADD = | ||||||
| am__objects_3 = bcopy.lo bzero.lo index.lo memchr.lo memcmp.lo \ | am__objects_3 = bcopy.lo bzero.lo index.lo memchr.lo memcmp.lo \ | ||||||
| 	memcpy.lo memmove.lo memset.lo rindex.lo strcasecmp.lo \ | 	memcpy.lo memmove.lo memset.lo rindex.lo strcasecmp.lo \ | ||||||
| 	strcat.lo strchr.lo strcmp.lo strcoll.lo strcpy.lo strcspn.lo \ | 	strcat.lo strchr.lo strcmp.lo strcoll.lo strcpy.lo \ | ||||||
| 	strdup.lo strdup_r.lo strerror.lo strerror_r.lo strlcat.lo \ | 	strcspn.lo strdup.lo strdup_r.lo strerror.lo strerror_r.lo \ | ||||||
| 	strlcpy.lo strlen.lo strlwr.lo strncasecmp.lo strncat.lo \ | 	strlcat.lo strlcpy.lo strlen.lo strlwr.lo strncasecmp.lo \ | ||||||
| 	strncmp.lo strncpy.lo strnlen.lo strpbrk.lo strrchr.lo \ | 	strncat.lo strncmp.lo strncpy.lo strnlen.lo strpbrk.lo \ | ||||||
| 	strsep.lo strspn.lo strtok.lo strtok_r.lo strupr.lo strxfrm.lo \ | 	strrchr.lo strsep.lo strspn.lo strtok.lo strtok_r.lo \ | ||||||
| 	strstr.lo swab.lo u_strerr.lo wcscat.lo wcschr.lo wcscmp.lo \ | 	strupr.lo strxfrm.lo strstr.lo swab.lo u_strerr.lo wcscat.lo \ | ||||||
| 	wcscoll.lo wcscpy.lo wcscspn.lo wcslcat.lo wcslcpy.lo \ | 	wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo wcscspn.lo \ | ||||||
| 	wcslen.lo wcsncat.lo wcsncmp.lo wcsncpy.lo wcsnlen.lo \ | 	wcslcat.lo wcslcpy.lo wcslen.lo wcsncat.lo wcsncmp.lo \ | ||||||
| 	wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo wcswidth.lo \ | 	wcsncpy.lo wcsnlen.lo wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo \ | ||||||
| 	wcwidth.lo wmemchr.lo wmemcmp.lo wmemcpy.lo wmemmove.lo \ | 	wcswidth.lo wcwidth.lo wmemchr.lo wmemcmp.lo wmemcpy.lo \ | ||||||
| 	wmemset.lo | 	wmemmove.lo wmemset.lo | ||||||
| @ELIX_LEVEL_1_FALSE@am__objects_4 = bcmp.lo memccpy.lo mempcpy.lo \ | @ELIX_LEVEL_1_FALSE@am__objects_4 = bcmp.lo memccpy.lo mempcpy.lo \ | ||||||
| @ELIX_LEVEL_1_FALSE@	strndup.lo strcasestr.lo strndup_r.lo | @ELIX_LEVEL_1_FALSE@	stpcpy.lo stpncpy.lo strndup.lo \ | ||||||
|  | @ELIX_LEVEL_1_FALSE@	strcasestr.lo strndup_r.lo | ||||||
| @USE_LIBTOOL_TRUE@am_libstring_la_OBJECTS = $(am__objects_3) \ | @USE_LIBTOOL_TRUE@am_libstring_la_OBJECTS = $(am__objects_3) \ | ||||||
| @USE_LIBTOOL_TRUE@	$(am__objects_4) | @USE_LIBTOOL_TRUE@	$(am__objects_4) | ||||||
| libstring_la_OBJECTS = $(am_libstring_la_OBJECTS) | libstring_la_OBJECTS = $(am_libstring_la_OBJECTS) | ||||||
| @@ -360,6 +363,8 @@ GENERAL_SOURCES = \ | |||||||
|  |  | ||||||
| @ELIX_LEVEL_1_FALSE@ELIX_SOURCES = \ | @ELIX_LEVEL_1_FALSE@ELIX_SOURCES = \ | ||||||
| @ELIX_LEVEL_1_FALSE@	bcmp.c \ | @ELIX_LEVEL_1_FALSE@	bcmp.c \ | ||||||
|  | @ELIX_LEVEL_1_FALSE@	stpcpy.c \ | ||||||
|  | @ELIX_LEVEL_1_FALSE@	stpncpy.c \ | ||||||
| @ELIX_LEVEL_1_FALSE@	memccpy.c \ | @ELIX_LEVEL_1_FALSE@	memccpy.c \ | ||||||
| @ELIX_LEVEL_1_FALSE@	mempcpy.c \ | @ELIX_LEVEL_1_FALSE@	mempcpy.c \ | ||||||
| @ELIX_LEVEL_1_FALSE@	strndup.c \ | @ELIX_LEVEL_1_FALSE@	strndup.c \ | ||||||
| @@ -383,7 +388,7 @@ index.def	rindex.def	strcspn.def	strpbrk.def swab.def \ | |||||||
| memchr.def	strcat.def	strerror.def	strerror_r.def strrchr.def \ | memchr.def	strcat.def	strerror.def	strerror_r.def strrchr.def \ | ||||||
| memcmp.def	strchr.def	strlen.def	strnlen.def strspn.def \ | memcmp.def	strchr.def	strlen.def	strnlen.def strspn.def \ | ||||||
| strcasecmp.def	strncasecmp.def strcasestr.def	strlwr.def  strupr.def \ | strcasecmp.def	strncasecmp.def strcasestr.def	strlwr.def  strupr.def \ | ||||||
| memccpy.def 	mempcpy.def \ | memccpy.def 	mempcpy.def	stpcpy.def	stpncpy.def \ | ||||||
| wcscat.def	wcschr.def	wcscmp.def	wcscoll.def \ | wcscat.def	wcschr.def	wcscmp.def	wcscoll.def \ | ||||||
| wcscpy.def	wcscspn.def \ | wcscpy.def	wcscspn.def \ | ||||||
| wcslcat.def	wcslcpy.def	wcslen.def	wcsncat.def \ | wcslcat.def	wcslcpy.def	wcslen.def	wcsncat.def \ | ||||||
| @@ -865,6 +870,18 @@ lib_a-mempcpy.o: mempcpy.c | |||||||
| lib_a-mempcpy.obj: mempcpy.c | lib_a-mempcpy.obj: mempcpy.c | ||||||
| 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mempcpy.obj `if test -f 'mempcpy.c'; then $(CYGPATH_W) 'mempcpy.c'; else $(CYGPATH_W) '$(srcdir)/mempcpy.c'; fi` | 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mempcpy.obj `if test -f 'mempcpy.c'; then $(CYGPATH_W) 'mempcpy.c'; else $(CYGPATH_W) '$(srcdir)/mempcpy.c'; fi` | ||||||
|  |  | ||||||
|  | lib_a-stpcpy.o: stpcpy.c | ||||||
|  | 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpcpy.o `test -f 'stpcpy.c' || echo '$(srcdir)/'`stpcpy.c | ||||||
|  |  | ||||||
|  | lib_a-stpcpy.obj: stpcpy.c | ||||||
|  | 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpcpy.obj `if test -f 'stpcpy.c'; then $(CYGPATH_W) 'stpcpy.c'; else $(CYGPATH_W) '$(srcdir)/stpcpy.c'; fi` | ||||||
|  |  | ||||||
|  | lib_a-stpncpy.o: stpncpy.c | ||||||
|  | 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpncpy.o `test -f 'stpncpy.c' || echo '$(srcdir)/'`stpncpy.c | ||||||
|  |  | ||||||
|  | lib_a-stpncpy.obj: stpncpy.c | ||||||
|  | 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-stpncpy.obj `if test -f 'stpncpy.c'; then $(CYGPATH_W) 'stpncpy.c'; else $(CYGPATH_W) '$(srcdir)/stpncpy.c'; fi` | ||||||
|  |  | ||||||
| lib_a-strndup.o: strndup.c | lib_a-strndup.o: strndup.c | ||||||
| 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strndup.o `test -f 'strndup.c' || echo '$(srcdir)/'`strndup.c | 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strndup.o `test -f 'strndup.c' || echo '$(srcdir)/'`strndup.c | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										91
									
								
								newlib/libc/string/stpcpy.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								newlib/libc/string/stpcpy.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | |||||||
|  | /* | ||||||
|  | FUNCTION | ||||||
|  | 	<<stpcpy>>---copy string returning a pointer to its end | ||||||
|  |  | ||||||
|  | INDEX | ||||||
|  | 	stpcpy | ||||||
|  |  | ||||||
|  | ANSI_SYNOPSIS | ||||||
|  | 	#include <string.h> | ||||||
|  | 	char *stpcpy(char *<[dst]>, const char *<[src]>); | ||||||
|  |  | ||||||
|  | TRAD_SYNOPSIS | ||||||
|  | 	#include <string.h> | ||||||
|  | 	char *stpcpy(<[dst]>, <[src]>) | ||||||
|  | 	char *<[dst]>; | ||||||
|  | 	char *<[src]>; | ||||||
|  |  | ||||||
|  | DESCRIPTION | ||||||
|  | 	<<stpcpy>> copies the string pointed to by <[src]> | ||||||
|  | 	(including the terminating null character) to the array | ||||||
|  | 	pointed to by <[dst]>. | ||||||
|  |  | ||||||
|  | RETURNS | ||||||
|  | 	This function returns a pointer to the end of the destination string, | ||||||
|  | 	thus pointing to the trailing '\0'. | ||||||
|  |  | ||||||
|  | PORTABILITY | ||||||
|  | <<stpcpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4. | ||||||
|  |  | ||||||
|  | <<stpcpy>> requires no supporting OS subroutines. | ||||||
|  |  | ||||||
|  | QUICKREF | ||||||
|  | 	stpcpy gnu | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | #include <string.h> | ||||||
|  | #include <limits.h> | ||||||
|  |  | ||||||
|  | /*SUPPRESS 560*/ | ||||||
|  | /*SUPPRESS 530*/ | ||||||
|  |  | ||||||
|  | /* Nonzero if either X or Y is not aligned on a "long" boundary.  */ | ||||||
|  | #define UNALIGNED(X, Y) \ | ||||||
|  |   (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) | ||||||
|  |  | ||||||
|  | #if LONG_MAX == 2147483647L | ||||||
|  | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) | ||||||
|  | #else | ||||||
|  | #if LONG_MAX == 9223372036854775807L | ||||||
|  | /* Nonzero if X (a long int) contains a NULL byte. */ | ||||||
|  | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) | ||||||
|  | #else | ||||||
|  | #error long int is not a 32bit or 64bit type. | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #ifndef DETECTNULL | ||||||
|  | #error long int is not a 32bit or 64bit byte | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | char* | ||||||
|  | _DEFUN (stpcpy, (dst, src), | ||||||
|  | 	char *dst _AND | ||||||
|  | 	_CONST char *src) | ||||||
|  | { | ||||||
|  | #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) | ||||||
|  |   long *aligned_dst; | ||||||
|  |   _CONST long *aligned_src; | ||||||
|  |  | ||||||
|  |   /* If SRC or DEST is unaligned, then copy bytes.  */ | ||||||
|  |   if (!UNALIGNED (src, dst)) | ||||||
|  |     { | ||||||
|  |       aligned_dst = (long*)dst; | ||||||
|  |       aligned_src = (long*)src; | ||||||
|  |  | ||||||
|  |       /* SRC and DEST are both "long int" aligned, try to do "long int" | ||||||
|  |          sized copies.  */ | ||||||
|  |       while (!DETECTNULL(*aligned_src)) | ||||||
|  |         { | ||||||
|  |           *aligned_dst++ = *aligned_src++; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |       dst = (char*)aligned_dst; | ||||||
|  |       src = (char*)aligned_src; | ||||||
|  |     } | ||||||
|  | #endif /* not PREFER_SIZE_OVER_SPEED */ | ||||||
|  |  | ||||||
|  |   while ((*dst++ = *src++)) | ||||||
|  |     ; | ||||||
|  |   return --dst; | ||||||
|  | } | ||||||
							
								
								
									
										114
									
								
								newlib/libc/string/stpncpy.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								newlib/libc/string/stpncpy.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,114 @@ | |||||||
|  | /* | ||||||
|  | FUNCTION | ||||||
|  | 	<<stpncpy>>---counted copy string returning a pointer to its end | ||||||
|  |  | ||||||
|  | INDEX | ||||||
|  | 	stpncpy | ||||||
|  |  | ||||||
|  | ANSI_SYNOPSIS | ||||||
|  | 	#include <string.h> | ||||||
|  | 	char *stpncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>); | ||||||
|  |  | ||||||
|  | TRAD_SYNOPSIS | ||||||
|  | 	#include <string.h> | ||||||
|  | 	char *stpncpy(<[dst]>, <[src]>, <[length]>) | ||||||
|  | 	char *<[dst]>; | ||||||
|  | 	char *<[src]>; | ||||||
|  | 	size_t <[length]>; | ||||||
|  |  | ||||||
|  | DESCRIPTION | ||||||
|  | 	<<stpncpy>> copies not more than <[length]> characters from the | ||||||
|  | 	the string pointed to by <[src]> (including the terminating | ||||||
|  | 	null character) to the array pointed to by <[dst]>.  If the | ||||||
|  | 	string pointed to by <[src]> is shorter than <[length]> | ||||||
|  | 	characters, null characters are appended to the destination | ||||||
|  | 	array until a total of <[length]> characters have been | ||||||
|  | 	written. | ||||||
|  |  | ||||||
|  | RETURNS | ||||||
|  | 	This function returns a pointer to the end of the destination string, | ||||||
|  | 	thus pointing to the trailing '\0', or, if the destination string is | ||||||
|  | 	not null-terminated, pointing to dst + n. | ||||||
|  |  | ||||||
|  | PORTABILITY | ||||||
|  | <<stpncpy>> is a GNU extension, candidate for inclusion into POSIX/SUSv4. | ||||||
|  |  | ||||||
|  | <<stpncpy>> requires no supporting OS subroutines. | ||||||
|  |  | ||||||
|  | QUICKREF | ||||||
|  | 	stpncpy gnu | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | #include <string.h> | ||||||
|  | #include <limits.h> | ||||||
|  |  | ||||||
|  | /*SUPPRESS 560*/ | ||||||
|  | /*SUPPRESS 530*/ | ||||||
|  |  | ||||||
|  | /* Nonzero if either X or Y is not aligned on a "long" boundary.  */ | ||||||
|  | #define UNALIGNED(X, Y) \ | ||||||
|  |   (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) | ||||||
|  |  | ||||||
|  | #if LONG_MAX == 2147483647L | ||||||
|  | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) | ||||||
|  | #else | ||||||
|  | #if LONG_MAX == 9223372036854775807L | ||||||
|  | /* Nonzero if X (a long int) contains a NULL byte. */ | ||||||
|  | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) | ||||||
|  | #else | ||||||
|  | #error long int is not a 32bit or 64bit type. | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #ifndef DETECTNULL | ||||||
|  | #error long int is not a 32bit or 64bit byte | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #define TOO_SMALL(LEN) ((LEN) < sizeof (long)) | ||||||
|  |  | ||||||
|  | char * | ||||||
|  | _DEFUN (stpncpy, (dst, src), | ||||||
|  | 	char *dst _AND | ||||||
|  | 	_CONST char *src _AND | ||||||
|  | 	size_t count) | ||||||
|  | { | ||||||
|  |   char *ret = NULL; | ||||||
|  |  | ||||||
|  | #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) | ||||||
|  |   long *aligned_dst; | ||||||
|  |   _CONST long *aligned_src; | ||||||
|  |  | ||||||
|  |   /* If SRC and DEST is aligned and count large enough, then copy words.  */ | ||||||
|  |   if (!UNALIGNED (src, dst) && !TOO_SMALL (count)) | ||||||
|  |     { | ||||||
|  |       aligned_dst = (long*)dst; | ||||||
|  |       aligned_src = (long*)src; | ||||||
|  |  | ||||||
|  |       /* SRC and DEST are both "long int" aligned, try to do "long int" | ||||||
|  | 	 sized copies.  */ | ||||||
|  |       while (count >= sizeof (long int) && !DETECTNULL(*aligned_src)) | ||||||
|  | 	{ | ||||||
|  | 	  count -= sizeof (long int); | ||||||
|  | 	  *aligned_dst++ = *aligned_src++; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |       dst = (char*)aligned_dst; | ||||||
|  |       src = (char*)aligned_src; | ||||||
|  |     } | ||||||
|  | #endif /* not PREFER_SIZE_OVER_SPEED */ | ||||||
|  |  | ||||||
|  |   while (count > 0) | ||||||
|  |     { | ||||||
|  |       --count; | ||||||
|  |       if ((*dst++ = *src++) == '\0') | ||||||
|  | 	{ | ||||||
|  | 	  ret = dst - 1; | ||||||
|  | 	  break; | ||||||
|  | 	} | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   while (count-- > 0) | ||||||
|  |     *dst++ = '\0'; | ||||||
|  |  | ||||||
|  |   return ret ? ret : dst; | ||||||
|  | } | ||||||
| @@ -18,6 +18,8 @@ managing areas of memory.  The corresponding declarations are in | |||||||
| * mempcpy::	Copy memory regions and locate end | * mempcpy::	Copy memory regions and locate end | ||||||
| * memset::      Set an area of memory | * memset::      Set an area of memory | ||||||
| * rindex::      Reverse search for character in string | * rindex::      Reverse search for character in string | ||||||
|  | * stpcpy::      Copy string returning a pointer to its end | ||||||
|  | * stpncpy::     Counted copy string returning a pointer to its end | ||||||
| * strcasecmp::	Compare strings ignoring case | * strcasecmp::	Compare strings ignoring case | ||||||
| * strcasestr::	Find string segment ignoring case | * strcasestr::	Find string segment ignoring case | ||||||
| * strcat::      Concatenate strings | * strcat::      Concatenate strings | ||||||
| @@ -81,6 +83,12 @@ managing areas of memory.  The corresponding declarations are in | |||||||
| @page | @page | ||||||
| @include string/rindex.def | @include string/rindex.def | ||||||
|  |  | ||||||
|  | @page | ||||||
|  | @include string/stpcpy.def | ||||||
|  |  | ||||||
|  | @page | ||||||
|  | @include string/stpncpy.def | ||||||
|  |  | ||||||
| @page | @page | ||||||
| @include string/strcasecmp.def | @include string/strcasecmp.def | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user