This repository has been archived on 2023-08-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

18 lines
224 B
C

/*
* strndup.c
*/
#include <string.h>
#include <stdlib.h>
char *strndup(const char *s, size_t n)
{
int l = n > strlen(s) ? strlen(s)+1 : n+1;
char *d = malloc(l);
if (d)
memcpy(d, s, l);
d[n] = '\0';
return d;
}