1.1 --- a/librazor/util.c Fri Jul 03 18:02:33 2009 +0100
1.2 +++ b/librazor/util.c Fri Apr 23 19:14:17 2010 +0100
1.3 @@ -31,6 +31,7 @@
1.4 #include <unistd.h>
1.5 #include <fcntl.h>
1.6 #ifdef MSWIN_API
1.7 +#include <windows.h>
1.8 #include <direct.h>
1.9 #endif
1.10 #if HAVE_SYS_MMAN_H
1.11 @@ -122,6 +123,39 @@
1.12 }
1.13
1.14 int
1.15 +razor_remove(const char *path)
1.16 +{
1.17 +#ifdef MSWIN_API
1.18 + DWORD err;
1.19 +
1.20 + if (DeleteFile(path))
1.21 + return 0;
1.22 +
1.23 + err = GetLastError();
1.24 + if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND)
1.25 + return 0;
1.26 +
1.27 + if (SetFileAttributes(path, FILE_ATTRIBUTE_NORMAL) && DeleteFile(path))
1.28 + return 0;
1.29 +
1.30 + if (RemoveDirectory(path) || GetLastError() == ERROR_DIR_NOT_EMPTY)
1.31 + return 0;
1.32 +
1.33 + /*
1.34 + * It would be tempting to use:
1.35 + * MoveFileEx(path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT)
1.36 + * but unless we can guarantee that the system will be rebooted
1.37 + * before we (or some other application) write another file with the
1.38 + * same path, this is likely to cause more problems than it solves.
1.39 + */
1.40 +
1.41 + /* Use remove() as a fallback so that errno is set appropriately */
1.42 +#endif
1.43 +
1.44 + return remove(path);
1.45 +}
1.46 +
1.47 +int
1.48 razor_write(int fd, const void *data, size_t size)
1.49 {
1.50 size_t rest;