X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=man3%2Fstrdup.3;fp=man3%2Fstrdup.3;h=8ac67e0a60e04c560fa1281ac589b0c19f641c53;hp=0000000000000000000000000000000000000000;hb=5dffc6a444fc022d7cca6bff4033d471a757aa57;hpb=c454b5c6ac2e92d8963b96b3e508a13026c58c45 diff --git a/man3/strdup.3 b/man3/strdup.3 new file mode 100644 index 0000000..8ac67e0 --- /dev/null +++ b/man3/strdup.3 @@ -0,0 +1,59 @@ +.\" This file is part of the Public Domain C Library (PDCLib). +.\" Permission is granted to use, modify, and / or redistribute at will. +.\" +.Dd +.Dt strdup 3 +.Os + +.Sh NAME +.Nm strdup +.Nd string duplication + +.Sh SYNOPSIS +.Sy #define _XOPEN_SOURCE || _POSIX_C_SOURCE >= 200809L +.In string.h +.Fn "char *strdup" "const char *str" +.Pp +.Sy #define _POSIX_C_SOURCE >= 200809L +.In string.h +.Fn "char *strndup" "const char *str" "size_t len" + +.Sh DESCRIPTION +.Fn strdup +allocates a new buffer of sufficient size as to be able to hold the entirety of +.Va str , +including the terminating character, and copies the contents of +.Va str +into it. + +.Pp +.Fn strndup +allocates a buffer large enough to contain +.Va len +characters, plus a trailing null character, or sufficient to contain the +entirety of +.Va str +including the trailing null character, whichever is smaller. The first +.Va len +characters of +.Va str +are then copied into it, and a null character appended. + +.Pp +The buffers returned by these functions must be released by a call to +.Fn free . + +.Sh SEE ALSO +.Xr free 3 +.Xr malloc 3 +.Xr strcpy 3 +.Xr strncpy 3 + +.Sh STANDARDS +.Fn strdup +first specified in +.St -xpg3 . +Moved into POSIX, and +.Fn strndup +added, with +.St -p1003.1-2008 . \ No newline at end of file