Skip to content

Commit

Permalink
No need to depend on POSIX here.
Browse files Browse the repository at this point in the history
  • Loading branch information
katef committed May 31, 2024
1 parent 4ec219a commit 825a621
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/adt/xalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See LICENCE for the full copyright terms.
*/

#define _POSIX_C_SOURCE 200809L

#include <assert.h>
#include <string.h>
#include <stdlib.h>
Expand All @@ -29,13 +27,14 @@ xstrdup(const char *s)
char *
xstrndup(const char *s, size_t n)
{
char *new = strndup(s, n);
char *new;

new = malloc(n);
if (new == NULL) {
perror("strndup");
abort();
return NULL;
}

return new;
return memcpy(new, s, n);
}

void *
Expand Down

0 comments on commit 825a621

Please sign in to comment.