diff --git a/Makefile b/Makefile index d68f602..2ad028f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC ?= gcc DEBUG ?= 0 CFLAGS = -Wall -Werror -Wextra -Wpedantic -std=c99 -Ofast \ --D_POSIX_C_SOURCE=200809L +-D_POSIX_C_SOURCE=200112L ifeq ($(DEBUG), 1) CFLAGS += -g -DDEBUG diff --git a/include/common.h b/include/common.h index 065ab4b..9660199 100644 --- a/include/common.h +++ b/include/common.h @@ -6,6 +6,7 @@ #include #include #include +#include /* enums */ enum configurations_bitshift { diff --git a/include/strdup.h b/include/strdup.h new file mode 100644 index 0000000..09ee248 --- /dev/null +++ b/include/strdup.h @@ -0,0 +1,11 @@ +#ifndef _STRDUP_H +#define _STRDUP_H + +#include +#include +#include + +/* functions definitions */ +char* strdup(const char* s); + +#endif /* _STRDUP_H */ diff --git a/src/main.c b/src/main.c index 1c98ab0..6d951f7 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,7 @@ #include "atoumax_base10.h" #include "corrupter.h" #include "file_type.h" +#include "strdup.h" /* enums */ enum arg_destinations { diff --git a/src/strdup.c b/src/strdup.c new file mode 100644 index 0000000..2c7ee5f --- /dev/null +++ b/src/strdup.c @@ -0,0 +1,17 @@ +#include "strdup.h" + +/* function implementations */ +char* strdup(const char* s) { + if (s == NULL) { + errno = EINVAL; + return NULL; + } + + char* copy = malloc((strlen(s) + 1) * sizeof(char)); + if (copy == NULL) + return NULL; + + strcpy(copy, s); + + return copy; +}