www.LinuxHowtos.org





strndup

Section: C Library Functions (3)
Updated: 202-0-17
Index Return to Main Contents
 

NAME

strndup - nonstring duplicat-int-string  

LIBRARY

Standard C library (libc,~-lc)  

SYNOPSIS

#include~<string.h>  // see memory.h(3head)
char *strndup(size_t n;
              const char strn[n], size_t n);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)): strndup():
    Since glibc 2.10:
        _POSIX_C_SOURCE >= 200809L
    Before glibc 2.10:
        _GNU_SOURCE
 

DESCRIPTION

This function duplicates at most n nonnull characters from the array pointed to by strn, followed by a null character, into new memory obtained with malloc(3).  

RETURN VALUE

On success, the strndup() function returns a pointer to the duplicated string. It returns NULL if insufficient memory was available, with errno set to indicate the error.  

ERRORS

See malloc(3).  

ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7).
InterfaceAttributeValue
strndup() Thread safetyM-Safe
 

STANDARDS

POSIX.-2008.  

HISTORY

POSIX.-2008.  

SEE ALSO

memory.h(3head), malloc(3), strndupa(3)


 

Index

NAME
LIBRARY
SYNOPSIS
DESCRIPTION
RETURN VALUE
ERRORS
ATTRIBUTES
STANDARDS
HISTORY
SEE ALSO