summaryrefslogtreecommitdiffstats
path: root/src/psearchn.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-05-19 19:26:20 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-05-19 19:26:20 +0200
commit26bdf36adb93789e7159577e53c9e426bb7a27cd (patch)
tree1d53d946c38ceeb45c0a7d3a6d47a5c4aa73c373 /src/psearchn.c
parent2542701f2e675bb364d8c3f04ffe6bed71f0ce1a (diff)
Fix windows compilation regression introduced in 1471f47a5c5b9d69863ec496bd7a57a9b0081d89
Diffstat (limited to 'src/psearchn.c')
-rw-r--r--src/psearchn.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/psearchn.c b/src/psearchn.c
index 6dfd93e..0c1fd9b 100644
--- a/src/psearchn.c
+++ b/src/psearchn.c
@@ -25,6 +25,9 @@
#endif
#include <stdio.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -37,6 +40,13 @@
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
+#ifdef HAVE_WINDEF_H
+#include <windef.h>
+#endif
+#ifdef HAVE_WINBASE_H
+#include <stdarg.h>
+#include <winbase.h>
+#endif
#include "types.h"
#include "common.h"
#include "intrf.h"
@@ -64,6 +74,39 @@ extern const file_hint_t file_hint_tar;
extern const file_hint_t file_hint_dir;
extern file_check_list_t file_check_list;
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+/* Live antivirus protection may open file as soon as they are created by *
+ * PhotoRec. PhotoRec will not be able to overwrite a file as long as the *
+ * antivirus is scanning it, so let's wait a little bit if the creation *
+ * failed. */
+
+#ifndef HAVE_SLEEP
+#define sleep(x) Sleep((x)*1000)
+#endif
+
+static FILE *fopen_with_retry(const char *path, const char *mode)
+{
+ FILE *handle;
+ if((handle=fopen(path, mode))!=NULL)
+ return handle;
+#ifdef __MINGW32__
+ Sleep(1000);
+#else
+ sleep(1);
+#endif
+ if((handle=fopen(path, mode))!=NULL)
+ return handle;
+#ifdef __MINGW32__
+ Sleep(2000);
+#else
+ sleep(2);
+#endif
+ if((handle=fopen(path, mode))!=NULL)
+ return handle;
+ return NULL;
+}
+#endif
+
pstatus_t photorec_aux(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
uint64_t offset;