Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / basis / Posix / FileSys / rename.c
CommitLineData
7f918cf1
CE
1#include "platform.h"
2
3C_Errno_t(C_Int_t) Posix_FileSys_rename (NullString8_t p1, NullString8_t p2) {
4 C_Errno_t(C_Int_t) res;
5 res = rename ((const char *) p1, (const char *) p2);
6#ifdef __MINGW32__
7 /* the MinGW rename() function does not remove the destination file
8 * if it exists; we emulate the Unix behavior here.
9 */
10 if ((res != 0) && (errno == EEXIST)) {
11 res = unlink ((const char *) p2);
12 if (res == 0)
13 res = rename((const char *) p1, (const char *) p2);
14 }
15#endif
16 return res;
17}