Moves strdup function to utility file

pull/1/head
venko 2021-05-06 17:15:17 -07:00
parent cbeb8d3ce2
commit 6ec5479db1
4 changed files with 23 additions and 15 deletions

View File

@ -2,21 +2,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
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)
{

View File

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

16
src/util.c Normal file
View File

@ -0,0 +1,16 @@
#include "util.h"
#include <string.h>
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;
}

6
src/util.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef WRAITH_UTIL_H
#define WRAITH_UTIL_H
char* strdup (const char* s);
#endif /* WRAITH_UTIL_H */