diff -r 6e93e5485947 -r ed134fdfe95f librazor/util.c --- a/librazor/util.c Fri Jul 03 18:02:33 2009 +0100 +++ b/librazor/util.c Wed Apr 28 11:59:02 2010 +0100 @@ -31,6 +31,7 @@ #include #include #ifdef MSWIN_API +#include #include #endif #if HAVE_SYS_MMAN_H @@ -122,6 +123,39 @@ } int +razor_remove(const char *path) +{ +#ifdef MSWIN_API + DWORD err; + + if (DeleteFile(path)) + return 0; + + err = GetLastError(); + if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) + return 0; + + if (SetFileAttributes(path, FILE_ATTRIBUTE_NORMAL) && DeleteFile(path)) + return 0; + + if (RemoveDirectory(path) || GetLastError() == ERROR_DIR_NOT_EMPTY) + return 0; + + /* + * It would be tempting to use: + * MoveFileEx(path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) + * but unless we can guarantee that the system will be rebooted + * before we (or some other application) write another file with the + * same path, this is likely to cause more problems than it solves. + */ + + /* Use remove() as a fallback so that errno is set appropriately */ +#endif + + return remove(path); +} + +int razor_write(int fd, const void *data, size_t size) { size_t rest;