From 6ec5479db18efb738e6a6716c798028e5aa670a2 Mon Sep 17 00:00:00 2001 From: venko Date: Thu, 6 May 2021 17:15:17 -0700 Subject: [PATCH] Moves strdup function to utility file --- src/ast.c | 15 +-------------- src/ast.h | 1 - src/util.c | 16 ++++++++++++++++ src/util.h | 6 ++++++ 4 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 src/util.c create mode 100644 src/util.h diff --git a/src/ast.c b/src/ast.c index 4f33a63..d08c224 100644 --- a/src/ast.c +++ b/src/ast.c @@ -2,21 +2,8 @@ #include #include -#include -char* strdup (const char* s) -{ - size_t slen = strlen(s); - char* result = malloc(slen + 1); - - if(result == NULL) - { - return NULL; - } - - memcpy(result, s, slen+1); - return result; -} +#include "util.h" const char* SyntaxKindString(SyntaxKind syntaxKind) { diff --git a/src/ast.h b/src/ast.h index 8e49ace..5c04d76 100644 --- a/src/ast.h +++ b/src/ast.h @@ -89,7 +89,6 @@ typedef struct Node PrimitiveType primitiveType; } Node; -char* strdup (const char* s); const char* SyntaxKindString(SyntaxKind syntaxKind); uint8_t IsPrimitiveType(Node *typeNode); diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..ae1654f --- /dev/null +++ b/src/util.c @@ -0,0 +1,16 @@ +#include "util.h" + +#include + +char* strdup (const char* s) +{ + size_t slen = strlen(s); + char* result = malloc(slen + 1); + if(result == NULL) + { + return NULL; + } + + memcpy(result, s, slen+1); + return result; +} \ No newline at end of file diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..2c305ec --- /dev/null +++ b/src/util.h @@ -0,0 +1,6 @@ +#ifndef WRAITH_UTIL_H +#define WRAITH_UTIL_H + +char* strdup (const char* s); + +#endif /* WRAITH_UTIL_H */