diff options
author | Andrew Tridgell <tridge@samba.org> | 2002-04-18 03:59:02 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2002-04-18 03:59:02 +0000 |
commit | 6a9bc86d62cc9ba532392af02a5d71e50b6b0411 (patch) | |
tree | d0d44741fab9731f0bb9fbd9515d9b32b2633fe7 /source3 | |
parent | b0fbd72b41dda039d4fd1036998721ee7387cd45 (diff) | |
download | samba-6a9bc86d62cc9ba532392af02a5d71e50b6b0411.tar.gz samba-6a9bc86d62cc9ba532392af02a5d71e50b6b0411.tar.bz2 samba-6a9bc86d62cc9ba532392af02a5d71e50b6b0411.zip |
nicer strndup() function
(This used to be commit 546764f3cbbefaad312386280dd2ebbbe5b4446d)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/util_str.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index f6e579ddba..ff3559ce14 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -991,13 +991,13 @@ some platforms don't have strndup char *strndup(const char *s, size_t n) { char *ret; - int i; - for (i=0;s[i] && i<n;i++) ; - - ret = malloc(i+1); + + n = strnlen(s, n); + ret = malloc(n+1); if (!ret) return NULL; - memcpy(ret, s, i); - ret[i] = 0; + memcpy(ret, s, n); + ret[n] = 0; + return ret; } #endif |