From d58e6fc38f6ec77e16b0c00e1309fdf983a6ca21 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Sat, 19 May 2012 02:16:40 +0200 Subject: [PATCH] using our own functions for strdup and _splitpath with the d_ prefix for all platforms for consistency --- CHANGELOG.txt | 1 + editor/kmine.c | 2 +- editor/mine.c | 2 +- include/strutil.h | 5 ++--- include/u_mem.h | 2 -- main/gamesave.c | 2 +- mem/mem.c | 10 ---------- misc/strutil.c | 14 +++++++++++--- 8 files changed, 17 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 093bd2d85..65b49a510 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20120519 -------- arch/ogl/gr.c, arch/sdl/digi_mixer_music.c, arch/sdl/jukebox.c, editor/autosave.c, editor/func.c, include/strutil.h, main/bmread.c, main/gamecntl.c, main/gamesave.c, main/hash.c, main/hud.c, main/menu.c, main/mission.c, main/multi.c, main/net_udp.c, main/newmenu.c, main/piggy.c, main/playsave.c, main/scores.c, main/songs.c, main/text.c, main/titles.c, misc/args.c, misc/physfsx.c, misc/strutil.c, texmap/scanline.c, ui/file.c: using our own functions for stricmp, strnicmp, strlwr, strupr, strrev with a d_ prefix for all platforms for consistency +editor/kmine.c, editor/mine.c, include/strutil.h, include/u_mem.h, main/gamesave.c, mem/mem.c, misc/strutil.c: using our own functions for strdup and _splitpath with the d_ prefix for all platforms for consistency 20120518 -------- diff --git a/editor/kmine.c b/editor/kmine.c index 212cc0a91..233a3a599 100644 --- a/editor/kmine.c +++ b/editor/kmine.c @@ -197,7 +197,7 @@ int med_save_situation(char * filename) // Write mine name. // strcpy(mine_name, filename); - _splitpath(filename, NULL, NULL, mine_name, NULL); + d_splitpath(filename, NULL, NULL, mine_name, NULL); set_extension(mine_name, "min"); PHYSFSX_printf(SaveFile, "%s\n", mine_name); diff --git a/editor/mine.c b/editor/mine.c index 05865c1bc..23c4e9c1e 100644 --- a/editor/mine.c +++ b/editor/mine.c @@ -66,7 +66,7 @@ int med_save_mine(char * filename) { #if 0 //ndef __linux__ char fname[20]; - _splitpath( filename, NULL, NULL, fname, NULL ); + d_splitpath( filename, NULL, NULL, fname, NULL ); sprintf( ErrorMessage, \ "ERROR: Cannot write to '%s'.\nYou probably need to check out a locked\nversion of the file. You should save\nthis under a different filename, and then\ncheck out a locked copy by typing\n\'co -l %s.lvl'\nat the DOS prompt.\n" diff --git a/include/strutil.h b/include/strutil.h index ff4fdb832..589468878 100644 --- a/include/strutil.h +++ b/include/strutil.h @@ -9,6 +9,7 @@ extern int d_strnicmp( const char *s1, const char *s2, int n ); extern void d_strlwr( char *s1 ); extern void d_strupr( char *s1 ); extern void d_strrev( char *s1 ); +extern char *d_strdup(char *str); // remove extension from filename, doesn't work with paths. void removeext(const char *filename, char *out); @@ -16,9 +17,7 @@ void removeext(const char *filename, char *out); //give a filename a new extension, doesn't work with paths with no extension already there extern void change_filename_extension( char *dest, const char *src, char *new_ext ); -#if !(defined(_WIN32)) -void _splitpath(char *name, char *drive, char *path, char *base, char *ext); -#endif +extern void _splitpath(char *name, char *drive, char *path, char *base, char *ext); // create a growing 2D array with a single growing buffer for the text // this system is likely to cause less memory fragmentation than having one malloc'd buffer per string diff --git a/include/u_mem.h b/include/u_mem.h index 95417a43a..b9efbc0d9 100644 --- a/include/u_mem.h +++ b/include/u_mem.h @@ -37,7 +37,6 @@ extern char * mem_strdup(char * str, char * var, char * file, int line ); #define d_calloc(n,size) mem_malloc((n*size),"Unknown", __FILE__,__LINE__, 1 ) #define d_realloc(ptr,size) mem_realloc((ptr),(size),"Unknown", __FILE__,__LINE__ ) #define d_free(ptr) do{ mem_free(ptr); ptr=NULL; } while(0) -#define d_strdup(str) mem_strdup((str),"Unknown",__FILE__,__LINE__) #define MALLOC( var, type, count ) (var=(type *)mem_malloc((count)*sizeof(type),#var, __FILE__,__LINE__,0 )) @@ -54,7 +53,6 @@ extern char *strdup(const char *str); #define d_calloc(n, size) calloc(n, size) #define d_realloc(ptr,size) realloc(ptr,size) #define d_free(ptr) do{ free(ptr); ptr=NULL; } while(0) -#define d_strdup(str) strdup(str) #define MALLOC( var, type, count ) (var=(type *)malloc((count)*sizeof(type))) diff --git a/main/gamesave.c b/main/gamesave.c index 87c33fe87..f62d794da 100644 --- a/main/gamesave.c +++ b/main/gamesave.c @@ -1476,7 +1476,7 @@ int save_level_sub(char * filename, int compiled_version) char ErrorMessage[256]; char fname[20]; - _splitpath( temp_filename, NULL, NULL, fname, NULL ); + d_splitpath( temp_filename, NULL, NULL, fname, NULL ); sprintf( ErrorMessage, \ "ERROR: Cannot write to '%s'.\nYou probably need to check out a locked\nversion of the file. You should save\nthis under a different filename, and then\ncheck out a locked copy by typing\n\'co -l %s.lvl'\nat the DOS prompt.\n" diff --git a/mem/mem.c b/mem/mem.c index ca9e9f4fb..bd90d4692 100644 --- a/mem/mem.c +++ b/mem/mem.c @@ -276,16 +276,6 @@ void *mem_realloc(void * buffer, unsigned int size, char * var, char * filename, return newbuffer; } -char *mem_strdup(char *str, char *var, char *filename, int line) -{ - char *newstr; - - newstr = mem_malloc(strlen(str) + 1, var, filename, line, 0); - strcpy(newstr, str); - - return newstr; -} - void mem_display_blocks() { int i, numleft; diff --git a/misc/strutil.c b/misc/strutil.c index 048a0f7b2..56e59f1d9 100644 --- a/misc/strutil.c +++ b/misc/strutil.c @@ -126,6 +126,16 @@ void d_strrev( char *s1 ) } } +char *d_strdup(char *str) +{ + char *newstr; + + newstr = d_malloc(strlen(str) + 1); + strcpy(newstr, str); + + return newstr; +} + // remove extension from filename void removeext(const char *filename, char *out) { @@ -163,8 +173,7 @@ void change_filename_extension( char *dest, const char *src, char *ext ) strcpy(p+1,ext); } -#if !(defined(_WIN32)) -void _splitpath(char *name, char *drive, char *path, char *base, char *ext) +void d_splitpath(char *name, char *drive, char *path, char *base, char *ext) { char *s, *p; @@ -214,7 +223,6 @@ void _splitpath(char *name, char *drive, char *path, char *base, char *ext) if (ext) strcpy(ext, p); } -#endif // create a growing 2D array with a single growing buffer for the text // this system is likely to cause less memory fragmentation than having one malloc'd buffer per string