|STRDUP(3)||Library Functions Manual||STRDUP(3)|
char *s, size_t
strdup() function allocates sufficient memory for a copy of the string s, does the copy, and returns a pointer to it. The pointer may subsequently be used as an argument to the function free(3).
strndup() function behaves similarly
strdup but only copies up to
maxlen characters from s. The
resulting string is always NUL-terminated.
If the memory allocation fails,
char *p; p = strdup("foobar"); if (p == NULL) err(1, NULL);
strndup() functions may fail and set the external variable errno for any of the errors specified for the library function malloc(3).
strndup() functions conform to IEEE Std 1003.1-2008 (“POSIX.1”).
strdup() macro was first used in the 4.1cBSD debugger, dbx. It was rewritten as a C function for the 4.3BSD inetd(8) and first appeared in the C library of 4.3BSD-Reno. The
strndup() function appeared in glibc 2.0, was reimplemented for NetBSD 4.0, and ported to OpenBSD 4.8.
|December 1, 2015||OpenBSD-6.2|