Removed getcwd() and use get_current_dir() instead.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 18 May 2005 18:20:06 +0000
changeset 89 0befb9dfdee4
parent 88 666e481f610c
child 90 1b004ccf775b
Removed getcwd() and use get_current_dir() instead.
mojopatch.c
platform.h
platform_unix.c
platform_win32.c
--- a/mojopatch.c	Wed May 18 17:54:56 2005 +0000
+++ b/mojopatch.c	Wed May 18 18:20:06 2005 +0000
@@ -2254,7 +2254,7 @@
             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? */
--- a/platform.h	Wed May 18 17:54:56 2005 +0000
+++ b/platform.h	Wed May 18 18:20:06 2005 +0000
@@ -55,7 +55,7 @@
 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);
--- a/platform_unix.c	Wed May 18 17:54:56 2005 +0000
+++ b/platform_unix.c	Wed May 18 18:20:06 2005 +0000
@@ -522,6 +522,12 @@
 } /* 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];
--- a/platform_win32.c	Wed May 18 17:54:56 2005 +0000
+++ b/platform_win32.c	Wed May 18 18:20:06 2005 +0000
@@ -122,25 +122,19 @@
 } /* 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 (buf[buflen - 2] != '\\')
+        strcat(buf, "\\");
 
-    if (retval[buflen - 2] != '\\')
-        strcat(retval, "\\");
-
-    return((char *) retval);
+    return(buf);
 } /* get_current_dir */