# HG changeset patch # User Herman Bloggs # Date 1048900268 0 # Node ID 86037d6bf80f7d95cfa7f697a6df51111bdf1c93 # Parent e61a072f44253fc1bb5ee7ae7370d299e71ab187 [gaim-migrate @ 5239] wgaim_rename committer: Tailor Script diff -r e61a072f4425 -r 86037d6bf80f src/win32/libc_interface.c --- a/src/win32/libc_interface.c Fri Mar 28 16:22:19 2003 +0000 +++ b/src/win32/libc_interface.c Sat Mar 29 01:11:08 2003 +0000 @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "libc_internal.h" @@ -291,3 +292,52 @@ return res; } + +/* stdio.h */ + +int wgaim_rename (const char *oldname, const char *newname) { + struct _stat oldstat, newstat; + + if(_stat(oldname, &oldstat) == 0) { + /* newname exists */ + if(_stat(newname, &newstat) == 0) { + /* oldname is a dir */ + if(_S_ISDIR(oldstat.st_mode)) { + if(!_S_ISDIR(newstat.st_mode)) { + return rename(oldname, newname); + } + /* newname is a dir */ + else { + /* This is not quite right.. If newname is empty and + is not a sub dir of oldname, newname should be + deleted and oldname should be renamed. + */ + debug_printf("Warning: wgaim_rename does not behave here as it should\n"); + return rename(oldname, newname); + } + } + /* oldname is not a dir */ + else { + /* newname is a dir */ + if(_S_ISDIR(newstat.st_mode)) { + errno = EISDIR; + return -1; + } + /* newname is not a dir */ + else { + remove(newname); + rename(oldname, newname); + } + } + } + /* newname doesn't exist */ + else + return rename(oldname, newname); + } + else { + /* oldname doesn't exist */ + errno = ENOENT; + return -1; + } + +} diff -r e61a072f4425 -r 86037d6bf80f src/win32/libc_interface.h --- a/src/win32/libc_interface.h Fri Mar 28 16:22:19 2003 +0000 +++ b/src/win32/libc_interface.h Sat Mar 29 01:11:08 2003 +0000 @@ -81,6 +81,10 @@ #define snprintf _snprintf #define vsnprintf _vsnprintf +extern int wgaim_rename(const char *oldname, const char *newname); +#define rename( oldname, newname ) \ +wgaim_rename( ## oldname ##, ## newname ## ) + /* sys/stat.h */ #define mkdir(a,b) _mkdir((a)) #define fchmod(a,b)