bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xstring.h


From: Bruno Haible
Subject: Re: xstring.h
Date: Sat, 10 May 2008 04:20:17 +0200
User-agent: KMail/1.5.4

Eric Blake wrote:
> |   /* Return a substring of the given string, len bytes long starting at
> str.  */
> |   char * xsubstring (const char *str, size_t len);
> 
> How is this different from [x]strndup?  At least strndup is standardized.

For xsubstring, the caller guarantees that the len bytes are not NUL; the
function then returns a string of length == len.

strndup is a glibc (not POSIX) function. I find the semantics of strndup,
strnlen, and strncmp always hard to remember. This complexity is not needed
here: When you are extracting a substring, you already know that the string
does not end before (str + len).

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]