Mercurial > pidgin.yaz
changeset 4905:86037d6bf80f
[gaim-migrate @ 5239]
wgaim_rename
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Sat, 29 Mar 2003 01:11:08 +0000 |
parents | e61a072f4425 |
children | f6e896d73e34 |
files | src/win32/libc_interface.c src/win32/libc_interface.h |
diffstat | 2 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <stdio.h> #include <errno.h> #include <sys/timeb.h> +#include <sys/stat.h> #include <time.h> #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; + } + +}
--- 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)