]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mingw: fix issues in pcap directory code
authorVictor Julien <victor@inliniac.net>
Mon, 11 Dec 2017 12:32:47 +0000 (13:32 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 20 Dec 2017 15:23:31 +0000 (16:23 +0100)
Fix issues with 'stat' and explicitly skip . and ..

src/source-pcap-file-directory-helper.c

index fdeb898504776786624c94db6fdd5906f88d17fb..7367442c964e0a6dbf318fef6f077c6f45b4d0fc 100644 (file)
@@ -229,17 +229,31 @@ TmEcode PcapDetermineDirectoryOrFile(char *filename, DIR **directory)
 
 int PcapDirectoryGetModifiedTime(char const *file, struct timespec *out)
 {
+#ifdef OS_WIN32
+    struct _stat buf;
+#else
     struct stat buf;
+#endif /* OS_WIN32 */
     int ret;
 
     if (file == NULL)
         return -1;
 
+#ifdef OS_WIN32
+    if((ret = _stat(file, &buf)) != 0)
+        return ret;
+#else
     if ((ret = stat(file, &buf)) != 0)
         return ret;
+#endif
 
 #ifdef OS_DARWIN
     *out = buf.st_mtimespec;
+#elif OS_WIN32
+    struct timespec ts;
+    memset(&ts, 0, sizeof(ts));
+    ts.tv_sec = buf.st_mtime;
+    *out = ts;
 #else
     *out = buf.st_mtim;
 #endif
@@ -316,9 +330,15 @@ TmEcode PcapDirectoryPopulateBuffer(PcapFileDirectoryVars *pv,
     PendingFile *file_to_add = NULL;
 
     while ((dir = readdir(pv->directory)) != NULL) {
+#ifndef OS_WIN32
         if (dir->d_type != DT_REG) {
             continue;
         }
+#endif
+        if (strcmp(dir->d_name, ".") == 0 ||
+            strcmp(dir->d_name, "..") == 0) {
+            continue;
+        }
 
         char pathbuff[PATH_MAX] = {0};