summaryrefslogtreecommitdiff
path: root/src/lib/evil/evil_stdio.c
blob: 5919d0c47470f825600d997727861ea9e7882209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */

#include <direct.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "evil_macro.h"
#include "evil_stdio.h"
#include "evil_private.h"

#undef rename

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;
}

int
evil_mkdir(const char *dirname, mode_t mode EVIL_UNUSED)
{
   return _mkdir(dirname);
}