all repos — mgba @ 3cd0b50bcef89c3aa81d0ef4ad536d52ef5cc138

mGBA Game Boy Advance Emulator

Add phony strndup implementation for when we do not have one
Jeffrey Pfau jeffrey@endrift.com
Tue, 30 Sep 2014 22:05:07 -0700
commit

3cd0b50bcef89c3aa81d0ef4ad536d52ef5cc138

parent

38762449ad0d38989f674ca3b7076e5c67080088

1 files changed, 15 insertions(+), 3 deletions(-)

jump to
M src/debugger/parser.csrc/debugger/parser.c

@@ -1,5 +1,17 @@

#include "parser.h" +static inline char* _strndup(const char* start, size_t len) { +#ifdef HAVE_STRNDUP + return strndup(start, len); +#else + // This is suboptimal, but anything recent should have strndup + char* out = malloc((len + 1) * sizeof(char)); + strncpy(out, start, len); + out[len] = '\0'; + return out; +#endif +} + static struct LexVector* _lexOperator(struct LexVector* lv, char operator) { struct LexVector* lvNext = malloc(sizeof(struct LexVector)); lvNext->token.type = TOKEN_OPERATOR_TYPE;

@@ -95,13 +107,13 @@ case '-':

case '*': case '/': lv->token.type = TOKEN_IDENTIFIER_TYPE; - lv->token.identifierValue = strndup(tokenStart, string - tokenStart - 1); + lv->token.identifierValue = _strndup(tokenStart, string - tokenStart - 1); lv = _lexOperator(lv, token); state = LEX_ROOT; break; case ')': lv->token.type = TOKEN_IDENTIFIER_TYPE; - lv->token.identifierValue = strndup(tokenStart, string - tokenStart - 1); + lv->token.identifierValue = _strndup(tokenStart, string - tokenStart - 1); state = LEX_EXPECT_OPERATOR; break; default:

@@ -240,7 +252,7 @@ lv->token.uintValue = next;

break; case LEX_EXPECT_IDENTIFIER: lv->token.type = TOKEN_IDENTIFIER_TYPE; - lv->token.identifierValue = strndup(tokenStart, string - tokenStart); + lv->token.identifierValue = _strndup(tokenStart, string - tokenStart); break; case LEX_EXPECT_OPERATOR: lvNext = malloc(sizeof(struct LexVector));