Skip to content

Commit

Permalink
Removed getcwd() and use get_current_dir() instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 18, 2005
1 parent 0402c09 commit 9ce3fcf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion mojopatch.c
Expand Up @@ -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? */
Expand Down
2 changes: 1 addition & 1 deletion platform.h
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions platform_unix.c
Expand Up @@ -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];
Expand Down
22 changes: 8 additions & 14 deletions platform_win32.c
Expand Up @@ -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 */


Expand Down

0 comments on commit 9ce3fcf

Please sign in to comment.