From c6e8791e8dd08d9ccaf30e33eec9cacd561f7e13 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Sun, 8 Mar 2015 19:03:02 -0400 Subject: [PATCH] "SDL_" everything --- src/osapi/osregistry.cpp | 89 +++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/src/osapi/osregistry.cpp b/src/osapi/osregistry.cpp index 5899bb8..79c1be3 100644 --- a/src/osapi/osregistry.cpp +++ b/src/osapi/osregistry.cpp @@ -2,9 +2,6 @@ #include "osregistry.h" #include "cfile.h" #include "version.h" -#undef malloc -#undef free -#undef strdup #include #include @@ -69,7 +66,7 @@ static char *read_line_from_file(CFILE *fp) int buflen, len, eol; buflen = 80; - buf = (char *)malloc(buflen); + buf = (char *)SDL_malloc(buflen); buf_start = buf; eol = 0; @@ -80,7 +77,7 @@ static char *read_line_from_file(CFILE *fp) if (cfgets(buf_start, 80, fp) == NULL) { if (buf_start == buf) { - free(buf); + SDL_free(buf); return NULL; } else { *buf_start = 0; @@ -88,7 +85,7 @@ static char *read_line_from_file(CFILE *fp) } } - len = strlen(buf_start); + len = SDL_strlen(buf_start); if (buf_start[len-1] == '\n') { buf_start[len-1] = 0; @@ -96,7 +93,7 @@ static char *read_line_from_file(CFILE *fp) } else { buflen += 80; - buf = (char *)realloc(buf, buflen); + buf = (char *)SDL_realloc(buf, buflen); /* be sure to skip over the proper amount of nulls */ buf_start = buf+(buflen-80)-(buflen/80)+1; @@ -123,22 +120,22 @@ static char *trim_string(char *str) *ptr = 0; ptr = str; - len = strlen(str); + len = SDL_strlen(str); if (len > 0) { ptr += len-1; } - while ((ptr > str) && isspace(*ptr)) { + while ((ptr > str) && SDL_isspace(*ptr)) { ptr--; } - + if (*ptr) { ptr++; *ptr = 0; } ptr = str; - while (*ptr && isspace(*ptr)) { + while (*ptr && SDL_isspace(*ptr)) { ptr++; } @@ -151,7 +148,7 @@ static Profile *profile_read(const char *file) if (fp == NULL) return NULL; - Profile *profile = (Profile *)malloc(sizeof(Profile)); + Profile *profile = (Profile *)SDL_malloc(sizeof(Profile)); profile->sections = NULL; Section **sp_ptr = &(profile->sections); @@ -173,10 +170,10 @@ static Profile *profile_read(const char *file) *pend = 0; if (*ptr) { - sp = (Section *)malloc(sizeof(Section)); + sp = (Section *)SDL_malloc(sizeof(Section)); sp->next = NULL; - sp->name = strdup(ptr); + sp->name = SDL_strdup(ptr); sp->pairs = NULL; *sp_ptr = sp; @@ -200,10 +197,10 @@ static Profile *profile_read(const char *file) if (key && *key && value /* && *value */) { if (sp != NULL) { - KeyValue *kvp = (KeyValue *)malloc(sizeof(KeyValue)); + KeyValue *kvp = (KeyValue *)SDL_malloc(sizeof(KeyValue)); - kvp->key = strdup(key); - kvp->value = strdup(value); + kvp->key = SDL_strdup(key); + kvp->value = SDL_strdup(value); kvp->next = NULL; @@ -214,7 +211,7 @@ static Profile *profile_read(const char *file) } // else it's just a comment or empty string } - free(str); + SDL_free(str); } cfclose(fp); @@ -235,26 +232,26 @@ static void profile_free(Profile *profile) while (kvp != NULL) { KeyValue *kvt = kvp; - free(kvp->key); - free(kvp->value); + SDL_free(kvp->key); + SDL_free(kvp->value); kvp = kvp->next; - free(kvt); + SDL_free(kvt); } - free(sp->name); + SDL_free(sp->name); sp = sp->next; - free(st); + SDL_free(st); } - free(profile); + SDL_free(profile); } static Profile *profile_update(Profile *profile, const char *section, const char *key, const char *value) { if (profile == NULL) { - profile = (Profile *)malloc(sizeof(Profile)); + profile = (Profile *)SDL_malloc(sizeof(Profile)); profile->sections = NULL; } @@ -264,21 +261,21 @@ static Profile *profile_update(Profile *profile, const char *section, const char Section **sp_ptr = &(profile->sections); Section *sp = profile->sections; while (sp != NULL) { - if (strcmp(section, sp->name) == 0) { + if (SDL_strcmp(section, sp->name) == 0) { KeyValue **kvp_ptr = &(sp->pairs); kvp = sp->pairs; while (kvp != NULL) { - if (strcmp(key, kvp->key) == 0) { - free(kvp->value); + if (SDL_strcmp(key, kvp->key) == 0) { + SDL_free(kvp->value); if (value == NULL) { *kvp_ptr = kvp->next; - free(kvp->key); - free(kvp); + SDL_free(kvp->key); + SDL_free(kvp); } else { - kvp->value = strdup(value); + kvp->value = SDL_strdup(value); } /* all done */ @@ -291,10 +288,10 @@ static Profile *profile_update(Profile *profile, const char *section, const char if (value != NULL) { /* key not found */ - kvp = (KeyValue *)malloc(sizeof(KeyValue)); + kvp = (KeyValue *)SDL_malloc(sizeof(KeyValue)); kvp->next = NULL; - kvp->key = strdup(key); - kvp->value = strdup(value); + kvp->key = SDL_strdup(key); + kvp->value = SDL_strdup(value); } *kvp_ptr = kvp; @@ -308,14 +305,14 @@ static Profile *profile_update(Profile *profile, const char *section, const char } /* section not found */ - sp = (Section *)malloc(sizeof(Section)); + sp = (Section *)SDL_malloc(sizeof(Section)); sp->next = NULL; - sp->name = strdup(section); + sp->name = SDL_strdup(section); - kvp = (KeyValue *)malloc(sizeof(KeyValue)); + kvp = (KeyValue *)SDL_malloc(sizeof(KeyValue)); kvp->next = NULL; - kvp->key = strdup(key); - kvp->value = strdup(value); + kvp->key = SDL_strdup(key); + kvp->value = SDL_strdup(value); sp->pairs = kvp; @@ -331,11 +328,11 @@ static const char *profile_get_value(Profile *profile, const char *section, cons Section *sp = profile->sections; while (sp != NULL) { - if (strcmp(section, sp->name) == 0) { + if (SDL_strcmp(section, sp->name) == 0) { KeyValue *kvp = sp->pairs; while (kvp != NULL) { - if (strcmp(key, kvp->key) == 0) { + if (SDL_strcmp(key, kvp->key) == 0) { return kvp->value; } kvp = kvp->next; @@ -364,12 +361,12 @@ static void profile_save(Profile *profile, const char *file) Section *sp = profile->sections; while (sp != NULL) { - SDL_snprintf(tmp_string_data, sizeof(tmp_string_data), NOX("[%s]\n"), sp->name); + SDL_snprintf(tmp_string_data, SDL_arraysize(tmp_string_data), "[%s]\n", sp->name); cfputs(tmp_string_data, fp); KeyValue *kvp = sp->pairs; while (kvp != NULL) { - SDL_snprintf(tmp_string_data, sizeof(tmp_string_data), NOX("%s=%s\n"), kvp->key, kvp->value); + SDL_snprintf(tmp_string_data, SDL_arraysize(tmp_string_data), "%s=%s\n", kvp->key, kvp->value); cfputs(tmp_string_data, fp); kvp = kvp->next; } @@ -391,7 +388,7 @@ const char *os_config_read_string(const char *section, const char *name, const c const char *ptr = profile_get_value(p, section, name); if ( (ptr != NULL) && SDL_strlen(ptr) ) { - SDL_strlcpy(tmp_string_data, ptr, sizeof(tmp_string_data)); + SDL_strlcpy(tmp_string_data, ptr, SDL_arraysize(tmp_string_data)); default_value = tmp_string_data; } @@ -409,7 +406,7 @@ unsigned int os_config_read_uint(const char *section, const char *name, unsigned const char *ptr = profile_get_value(p, section, name); if ( (ptr != NULL) && SDL_strlen(ptr) ) { - default_value = atoi(ptr); + default_value = SDL_atoi(ptr); } profile_free(p); @@ -433,7 +430,7 @@ void os_config_write_uint(const char *section, const char *name, unsigned int va { static char buf[21]; - SDL_snprintf(buf, 20, "%u", value); + SDL_snprintf(buf, SDL_arraysize(buf), "%u", value); Profile *p = profile_read(PROFILE_NAME); -- 2.39.2