diff options
author | Roland McGrath <roland@gnu.org> | 1996-06-28 11:42:05 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1996-06-28 11:42:05 +0000 |
commit | de6b062321f6631c49119190dc63b00a566148df (patch) | |
tree | 59482c6f7bc38de66b83752d144c1411cc5043c0 /string | |
parent | 6dbe2837567f528faa015fd0cf1536201dde5ffd (diff) | |
download | glibc-de6b062321f6631c49119190dc63b00a566148df.zip glibc-de6b062321f6631c49119190dc63b00a566148df.tar.gz glibc-de6b062321f6631c49119190dc63b00a566148df.tar.bz2 |
Fri Jun 28 07:27:10 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* string/strndup.c (strndup): Always terminate the string.
* string/string.h (strndupa): Likewise.
Thu Jun 27 14:22:31 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* stdio/Makefile (routines): Add vscanf.
* stdio-common/Makefile (routines): Remove vscanf.
* stdio-common/vscanf.c: Move to ...
* stdio/vscanf.c: here.
* rpm/Makefile (headers, install-lib, install-lib.so,
versioned, install-bin, install-sbin, install-data,
install-others): Add $(-VARIABLE).
Diffstat (limited to 'string')
-rw-r--r-- | string/string.h | 7 | ||||
-rw-r--r-- | string/strndup.c | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/string/string.h b/string/string.h index 3b6c5e9..7dbcc41 100644 --- a/string/string.h +++ b/string/string.h @@ -107,8 +107,11 @@ extern char *strndup __P ((__const char *__string, size_t __n)); #define strndupa(s, n) \ ({ \ __const char *__old = (s); \ - size_t __len = strnlen (__old) + 1; \ - memcpy (__builtin_alloca (__len), __old, __len); \ + char *__new; \ + size_t __len = strnlen (__old); \ + __new = memcpy (__builtin_alloca (__len + 1), __old, __len); \ + __new[__len] = '\0'; \ + __new; \ }) #endif diff --git a/string/strndup.c b/string/strndup.c index 213a0c0..c40d00f 100644 --- a/string/strndup.c +++ b/string/strndup.c @@ -24,13 +24,14 @@ Cambridge, MA 02139, USA. */ char * strndup (const char *s, size_t n) { - size_t len = strnlen (s) + 1; - char *new = malloc (len); + size_t len = strnlen (s); + char *new = malloc (len + 1); if (new == NULL) return NULL; memcpy (new, s, len); + new[len] = '\0'; return new; } |