From 9ce3fcff74cc63cb1eb0d4c24c481756648d2640 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 18 May 2005 18:20:06 +0000 Subject: [PATCH] Removed getcwd() and use get_current_dir() instead. --- mojopatch.c | 2 +- platform.h | 2 +- platform_unix.c | 6 ++++++ platform_win32.c | 22 ++++++++-------------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mojopatch.c b/mojopatch.c index 3a2205f..5c74fcd 100644 --- a/mojopatch.c +++ b/mojopatch.c @@ -2254,7 +2254,7 @@ static int do_patching(void) if (*header.renamedir) { char cwdbuf[MAX_PATH]; - if (getcwd(cwdbuf, sizeof (cwdbuf)) != NULL) + if (get_current_dir(cwdbuf, sizeof (cwdbuf)) != NULL) { chdir(".."); rename(cwdbuf, header.renamedir); /* !!! FIXME: retval? */ diff --git a/platform.h b/platform.h index 9ebf569..72ff007 100644 --- a/platform.h +++ b/platform.h @@ -55,7 +55,7 @@ int file_is_directory(const char *fname); int file_is_symlink(const char *fname); file_list *make_filelist(const char *base); /* must use malloc(). */ int get_file_size(const char *fname, long *fsize); -char *get_current_dir(void); +char *get_current_dir(char *buf, size_t bufsize); char *get_realpath(const char *path); int spawn_xdelta(const char *cmdline); int update_version(const char *ver); diff --git a/platform_unix.c b/platform_unix.c index 0e3735d..9ce9403 100644 --- a/platform_unix.c +++ b/platform_unix.c @@ -522,6 +522,12 @@ int spawn_xdelta(const char *cmdline) } /* spawn_xdelta */ +char *get_current_dir(char *buf, size_t bufsize) +{ + return(getcwd(buf, bufsize)); +} /* get_current_dir */ + + static void find_basedir(int *argc, char **argv) { const char *argv0 = argv[0]; diff --git a/platform_win32.c b/platform_win32.c index 4c5135c..8ae439c 100644 --- a/platform_win32.c +++ b/platform_win32.c @@ -122,25 +122,19 @@ int get_file_size(const char *fname, long *fsize) } /* get_file_size */ -char *get_current_dir(void) +char *get_current_dir(char *buf, size_t bufsize); { - LPTSTR retval; - DWORD buflen = 0; - - buflen = GetCurrentDirectory(buflen, NULL); - retval = (LPTSTR) malloc(sizeof (TCHAR) * (buflen + 2)); - if (retval == NULL) + DWORD buflen = GetCurrentDirectory(bufsize, buf); + if (buflen <= bufsize) { - fprintf(stderr, "Error: out of memory.\n"); - return(NULL); + *buf = '\0'; + return NULL; } /* if */ - GetCurrentDirectory(buflen, retval); - - if (retval[buflen - 2] != '\\') - strcat(retval, "\\"); + if (buf[buflen - 2] != '\\') + strcat(buf, "\\"); - return((char *) retval); + return(buf); } /* get_current_dir */