summaryrefslogtreecommitdiffstats
path: root/source3/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2002-04-18 03:59:02 +0000
committerAndrew Tridgell <tridge@samba.org>2002-04-18 03:59:02 +0000
commit6a9bc86d62cc9ba532392af02a5d71e50b6b0411 (patch)
treed0d44741fab9731f0bb9fbd9515d9b32b2633fe7 /source3/lib
parentb0fbd72b41dda039d4fd1036998721ee7387cd45 (diff)
downloadsamba-6a9bc86d62cc9ba532392af02a5d71e50b6b0411.tar.gz
samba-6a9bc86d62cc9ba532392af02a5d71e50b6b0411.tar.xz
samba-6a9bc86d62cc9ba532392af02a5d71e50b6b0411.zip
nicer strndup() function
(This used to be commit 546764f3cbbefaad312386280dd2ebbbe5b4446d)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_str.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index f6e579ddba1..ff3559ce148 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