aboutsummaryrefslogtreecommitdiff
path: root/string
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-03-18 17:57:13 +0000
committerUlrich Drepper <drepper@redhat.com>1998-03-18 17:57:13 +0000
commit7551a1e5100c596793fa182cd26346ff971d3a4f (patch)
treef3c959a1c55505681669ebeb43fbeb5251eb6da5 /string
parent3116126871400c8737a9df0145f66534f097c06c (diff)
downloadglibc-7551a1e5100c596793fa182cd26346ff971d3a4f.tar
glibc-7551a1e5100c596793fa182cd26346ff971d3a4f.tar.gz
glibc-7551a1e5100c596793fa182cd26346ff971d3a4f.tar.bz2
glibc-7551a1e5100c596793fa182cd26346ff971d3a4f.zip
Update.
1998-03-18 Andreas Jaeger <aj@arthur.rhein-neckar.de> * manual/memory.texi (Heap Consistency Checking): Document MALLOC_CHECK_. Based on a text by Wolfram Gloger. 1998-03-18 17:11 Zack Weinberg <zack@rabi.phys.columbia.edu> * manual/Makefile: Add missing rules. 1998-03-18 Ulrich Drepper <drepper@cygnus.com> * timezone/Makefile (generated): Define to remove all stamp files. * sysdeps/generic/strsep.c: Also undefine __strsep. * string/strdup.c: Undefine __strdup and strdup first. * string/strndup.c: Likewise. * string/bits/string2.h: Correct strtok_r and strsep. Add strndup optimization. * sysdeps/generic/strsep.c: Little optimization.
Diffstat (limited to 'string')
-rw-r--r--string/bits/string2.h57
-rw-r--r--string/strdup.c5
-rw-r--r--string/strndup.c5
3 files changed, 52 insertions, 15 deletions
diff --git a/string/bits/string2.h b/string/bits/string2.h
index 4b8f161aa1..a84cede465 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -710,8 +710,8 @@ strnlen (__const char *__string, size_t __maxlen)
? (((__const unsigned char *) (sep))[0] != '\0' \
&& ((__const unsigned char *) (sep))[1] == '\0' \
? __strtok_r_1c (s, ((__const char *) (sep))[0], nextp) \
- : strtok_r (s, sep, nextp)) \
- : strtok_r (s, sep, nextp)))
+ : __strtok_r (s, sep, nextp)) \
+ : __strtok_r (s, sep, nextp)))
__STRING_INLINE char *__strtok_r_1c (char *__s, char __sep, char **__nextp);
__STRING_INLINE char *
@@ -740,7 +740,7 @@ __strtok_r_1c (char *__s, char __sep, char **__nextp)
return __result;
}
# if defined __USE_POSIX || defined __USE_MISC
-# define strtok_r(s, sep, nextp) __strtok_r (s, sep, nextp)
+# define strtok_r(s, sep, nextp) __strtok_r ((s), (sep), (nextp))
# endif
#endif
@@ -845,7 +845,7 @@ __strsep_g (char **__s, __const char *__reject)
return __retval;
}
# ifdef __USE_BSD
-# define strsep(s, reject) __strsep (s, reject)
+# define strsep(s, reject) __strsep ((s), (reject))
# endif
#endif
@@ -857,15 +857,15 @@ __strsep_g (char **__s, __const char *__reject)
# include <stdlib.h>
# define __strdup(s) \
- (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s)
- ? (((__const unsigned char *) (s))[0] == '\0'
- ? return (char *) calloc (1, 1);
- : ({ size_t len = strlen (s) + 1;
- char *retval = (char *) malloc (len);
- if (retval != NULL)
- retval = (char *) memcpy (retval, s, len);
- retval; }))
- : strdup (s)))
+ (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
+ ? (((__const unsigned char *) (s))[0] == '\0' \
+ ? (char *) calloc (1, 1) \
+ : ({ size_t __len = strlen (s) + 1; \
+ char *__retval = (char *) malloc (__len); \
+ if (__retval != NULL) \
+ __retval = (char *) memcpy (__retval, s, __len); \
+ __retval; })) \
+ : __strdup (s)))
# if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
# define strdup(s) __strdup (s)
@@ -873,6 +873,37 @@ __strsep_g (char **__s, __const char *__reject)
#endif
+#if !defined _HAVE_STRING_ARCH_strndup && !defined __STRICT_ANSI__
+
+/* We need the memory allocation functions. Including this header is
+ not allowed. */
+# include <stdlib.h>
+
+# define __strndup(s, n) \
+ (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
+ ? (((__const unsigned char *) (s))[0] == '\0' \
+ ? (char *) calloc (1, 1) \
+ : ({ size_t __len = strlen (s) + 1; \
+ size_t __n = (n); \
+ char *__retval; \
+ if (__n < __len) \
+ __len = __n; \
+ __retval = (char *) malloc (__len); \
+ if (__retval != NULL) \
+ { \
+ __retval[__len - 1] = '\0'; \
+ __retval = (char *) memcpy (__retval, s, \
+ __len - 1); \
+ } \
+ __retval; })) \
+ : __strndup ((s), (n))))
+
+# ifdef __GNU_SOURCE
+# define strndup(s, n) __strndup ((s), (n))
+# endif
+#endif
+
+
#undef __STRING_INLINE
#endif /* No string inlines. */
diff --git a/string/strdup.c b/string/strdup.c
index be3883f688..2e0852cb9e 100644
--- a/string/strdup.c
+++ b/string/strdup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -28,6 +28,9 @@ char *malloc ();
char *memcpy ();
#endif
+#undef __strdup
+#undef strdup
+
#ifndef weak_alias
# define __strdup strdup
#endif
diff --git a/string/strndup.c b/string/strndup.c
index cd971e1c6f..3f534427b4 100644
--- a/string/strndup.c
+++ b/string/strndup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -30,6 +30,9 @@
char *malloc ();
#endif
+#undef __strndup
+#undef strndup
+
#ifndef weak_alias
# define __strndup strndup
#endif