libft
Functions
ft_strndup.c File Reference
#include "libft.h"
#include <stdlib.h>
+ Include dependency graph for ft_strndup.c:

Go to the source code of this file.

Functions

char * ft_strndup (const char *s1, size_t len)
 Makes a new string and copies up to len characters to it. More...
 

Function Documentation

◆ ft_strndup()

char* ft_strndup ( const char *  s1,
size_t  len 
)

Makes a new string and copies up to len characters to it.

Allocate sufficient memory for a string of len characters, do the copy of len characters, NULL terminate the string, and return a pointer to it. The pointer may subsequently be used as an argument to the function free.

Parameters
s1String to be copied from.
lenNumber of characters to copy.
Returns
String of length len with copied characters or NULL if allocation failed.
Remarks
If s1 contains less than len characters, behaviour is undefined.

Definition at line 30 of file ft_strndup.c.