Moves strdup function to utility file
							parent
							
								
									cbeb8d3ce2
								
							
						
					
					
						commit
						6ec5479db1
					
				
							
								
								
									
										15
									
								
								src/ast.c
								
								
								
								
							
							
						
						
									
										15
									
								
								src/ast.c
								
								
								
								
							|  | @ -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) | ||||
| { | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
|  | @ -0,0 +1,6 @@ | |||
| #ifndef WRAITH_UTIL_H | ||||
| #define WRAITH_UTIL_H | ||||
| 
 | ||||
| char* strdup (const char* s); | ||||
| 
 | ||||
| #endif /* WRAITH_UTIL_H */ | ||||
		Loading…
	
		Reference in New Issue