Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

strndup(3) [freebsd man page]

STRDUP(3)						   BSD Library Functions Manual 						 STRDUP(3)

NAME
strdup, strndup -- save a copy of a string LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * strdup(const char *str); char * strndup(const char *str, size_t len); DESCRIPTION
The strdup() function allocates sufficient memory for a copy of the string str, does the copy, and returns a pointer to it. The pointer may subsequently be used as an argument to the function free(3). If insufficient memory is available, NULL is returned and errno is set to ENOMEM. The strndup() function copies at most len characters from the string str always NUL terminating the copied string. SEE ALSO
free(3), malloc(3), wcsdup(3) HISTORY
The strdup() function first appeared in 4.4BSD. The strndup() function was added in FreeBSD 7.2. BSD
December 5, 2008 BSD

Check Out this Related Man Page

STRDUP(3)						     Linux Programmer's Manual							 STRDUP(3)

NAME
strdup, strndup, strdupa, strndupa - duplicate a string SYNOPSIS
#include <string.h> char *strdup(const char *s); #define _GNU_SOURCE #include <string.h> char *strndup(const char *s, size_t n); char *strdupa(const char *s); char *strndupa(const char *s, size_t n); DESCRIPTION
The strdup() function returns a pointer to a new string which is a duplicate of the string s. Memory for the new string is obtained with malloc(3), and can be freed with free(3). The strndup() function is similar, but only copies at most n characters. If s is longer than n, only n characters are copied, and a termi- nating NUL is added. strdupa and strndupa are similar, but use alloca(3) to allocate the buffer. They are only available when using the GNU GCC suite, and suf- fer from the same limitations described in alloca(3). RETURN VALUE
The strdup() function returns a pointer to the duplicated string, or NULL if insufficient memory was available. ERRORS
ENOMEM Insufficient memory available to allocate duplicate string. CONFORMING TO
SVID 3, BSD 4.3. strndup(), strdupa(), and strndupa() are GNU extensions. SEE ALSO
alloca(3), calloc(3), free(3), malloc(3), realloc(3) GNU
1993-04-12 STRDUP(3)
Man Page

5 More Discussions You Might Find Interesting

1. AIX

Samba on AIX 4.3

I have 11 AIX (a mix of 4.3.3.0 and 4.3.2.0) on which I succesfully installed a Samba server. On two other systems, the smbd start command generates the following error message. Anybody ? itocroot@TAGEN010: /usr/local/samba/bin $ ./smbd start exec(): 0509-036 Cannot load program ./smbd because... (0 Replies)
Discussion started by: Frans Graux
0 Replies

2. Programming

How to allocate memory to a string in C?

hi I want to take string as a input from user and the string is very very length. From the lengthy string i have to substring take first 16 letters, then next 8 letters,................... Please guide me how to write program to take lengthy string from user and sub string it. Thanks (4 Replies)
Discussion started by: atharalikhan
4 Replies

3. Programming

How to write data to file in C?

Hi I want to open a file and write data in the following manner. Header String 1 String 2 String 3 String 4 String 5 ... (4 Replies)
Discussion started by: AAKhan
4 Replies

4. Programming

Why segmentation(coredump) in the following code in C?

hi I have a method which returns char*. In this method am using switch case. I am getting segmentation error in case 49 and my code is case 49: if(intFlag == 0210) { iiIDCode = atoi(getsubstring(sReq,262,2)); l =... (7 Replies)
Discussion started by: AAKhan
7 Replies

5. UNIX for Beginners Questions & Answers

Compiling GCC 6.3.0 - Error with Library

First of all -- thanks for being patient with me. I hope I'm submitting this correctly. Also I haven't done UNIX Admin since the early 1990's. I'm actually a DBA. But, since I'm the one in the office with the UNIX experience, I'm the SA. I haven't been able to compile GCC 6.3.0 which I need... (9 Replies)
Discussion started by: PJ_Namias
9 Replies