Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

strndup(3) [mojave 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 *s1); char * strndup(const char *s1, size_t n); DESCRIPTION
The strdup() function allocates sufficient memory for a copy of the string s1, 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 n characters from the string s1 always NUL terminating the copied string. SEE ALSO
free(3), malloc(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)						   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. The strndup() function copies at most len characters from the string str always NUL terminating the copied string. EXAMPLES
The following will point p to an allocated area of memory containing the nul-terminated string "foobar": char *p; if ((p = strdup("foobar")) == NULL) { fprintf(stderr, "Out of memory. "); exit(1); } ERRORS
The strdup() function may fail and set the external variable errno for any of the errors specified for the library function malloc(3). SEE ALSO
free(3), malloc(3), strcpy(3), strlen(3) STANDARDS
The strdup() function conforms to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The strdup() function first appeared in 4.4BSD. The strndup() function was added in NetBSD 4.0. BSD
January 28, 2009 BSD
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