mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
r18652: libreplace has replacements for strndup and strnlen
metze
This commit is contained in:
parent
e3b88fb655
commit
9f3599a7ca
@ -1663,49 +1663,6 @@ int fstr_sprintf(fstring s, const char *fmt, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(HAVE_STRNDUP) || defined(BROKEN_STRNDUP)
|
||||
/**
|
||||
Some platforms don't have strndup.
|
||||
**/
|
||||
#if defined(PARANOID_MALLOC_CHECKER)
|
||||
#undef strndup
|
||||
#endif
|
||||
|
||||
char *strndup(const char *s, size_t n)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
n = strnlen(s, n);
|
||||
ret = SMB_MALLOC(n+1);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
memcpy(ret, s, n);
|
||||
ret[n] = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(PARANOID_MALLOC_CHECKER)
|
||||
#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRNLEN) || defined(BROKEN_STRNLEN)
|
||||
/**
|
||||
Some platforms don't have strnlen
|
||||
**/
|
||||
|
||||
size_t strnlen(const char *s, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
for (i=0; i<n && s[i] != '\0'; i++)
|
||||
/* noop */ ;
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
List of Strings manipulation functions
|
||||
**/
|
||||
|
Loading…
Reference in New Issue
Block a user