2008-10-11 07:35:26 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
|
|
|
#include "Evil.h"
|
2008-11-21 14:57:45 -08:00
|
|
|
#include "evil_private.h"
|
|
|
|
|
2013-06-18 23:47:20 -07:00
|
|
|
#undef rename
|
2008-10-11 07:35:26 -07:00
|
|
|
|
2013-06-18 23:47:20 -07:00
|
|
|
int
|
|
|
|
evil_rename(const char *src, const char* dst)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(dst, &st) < 0)
|
|
|
|
return rename(src, dst);
|
|
|
|
|
|
|
|
if (stat(src, &st) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (S_ISDIR(st.st_mode))
|
|
|
|
{
|
|
|
|
rmdir(dst);
|
|
|
|
return rename(src, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISREG(st.st_mode))
|
|
|
|
{
|
|
|
|
unlink(dst);
|
|
|
|
return rename(src, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|