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
