1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-12-29 16:40:40 +05:30

downgrade POSIX C source version to 2001-12

Implement `strdup` to not require version 2008-09
This commit is contained in:
Intel A80486DX2-66 2024-08-06 22:49:43 +03:00
parent c707657459
commit ee1dff912b
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
5 changed files with 31 additions and 1 deletions

View File

@ -2,7 +2,7 @@ CC ?= gcc
DEBUG ?= 0 DEBUG ?= 0
CFLAGS = -Wall -Werror -Wextra -Wpedantic -std=c99 -Ofast \ CFLAGS = -Wall -Werror -Wextra -Wpedantic -std=c99 -Ofast \
-D_POSIX_C_SOURCE=200809L -D_POSIX_C_SOURCE=200112L
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
CFLAGS += -g -DDEBUG CFLAGS += -g -DDEBUG

View File

@ -6,6 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
/* enums */ /* enums */
enum configurations_bitshift { enum configurations_bitshift {

11
include/strdup.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _STRDUP_H
#define _STRDUP_H
#include <errno.h>
#include <stdlib.h>
#include <string.h>
/* functions definitions */
char* strdup(const char* s);
#endif /* _STRDUP_H */

View File

@ -23,6 +23,7 @@
#include "atoumax_base10.h" #include "atoumax_base10.h"
#include "corrupter.h" #include "corrupter.h"
#include "file_type.h" #include "file_type.h"
#include "strdup.h"
/* enums */ /* enums */
enum arg_destinations { enum arg_destinations {

17
src/strdup.c Normal file
View File

@ -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;
}