/* fileset.c
* Routines for handling file sets
*
- * $Id$
- *
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
-#include "config.h"
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
-#ifdef HAVE_DIRENT_H
-#include <dirent.h>
-#endif
-
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
+#include <config.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#include <stdio.h>
#include <string.h>
-#include <ctype.h>
#include <glib.h>
#include <wsutil/file_util.h>
-#include "globals.h"
+#include <wsutil/filesystem.h>
-#include <epan/filesystem.h>
+#include <epan/strutil.h>
#include "fileset.h"
-
-
typedef struct _fileset {
GList *entries;
char *dirname;
} fileset;
-/* this is the fileset's global data */
+/*
+ * This is the fileset's global data.
+ *
+ * XXX This should probably be per-main-window instead of global.
+ */
static fileset set = { NULL, NULL};
+/*
+ * Given a stat structure, get the creation time of the file if available,
+ * or 0 if not.
+ */
+#ifdef _WIN32
+ /* Microsoft's documentation says this is the creation time */
+ #define ST_CREATE_TIME(statb) ((statb).st_ctime)
+#else /* _WIN32 */
+ /* UN*X - do we have a creation time? */
+ #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
+ #define ST_CREATE_TIME(statb) ((statb).st_birthtime)
+ #elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
+ #define ST_CREATE_TIME(statb) ((statb).__st_birthtime)
+ #else /* nothing */
+ #define ST_CREATE_TIME(statb) (0)
+ #endif /* creation time on UN*X */
+#endif /* _WIN32 */
/* is this a probable file of a file set (does the naming pattern match)? */
gboolean
while(minlen--) {
baselen--;
- if(!isdigit( (guchar) filename[baselen])) {
+ if(!g_ascii_isdigit( filename[baselen])) {
g_free(filename);
return FALSE;
}
/* test, if both files could be in the same file set */
/* (the filenames must already be in correct shape) */
-gboolean
+static gboolean
fileset_is_file_in_set(const char *fname1, const char *fname2)
{
char *pfx1;
if (entry_list) {
entry = (fileset_entry *) entry_list->data;
- entry->ctime = buf.st_ctime;
+ entry->ctime = ST_CREATE_TIME(buf);
entry->mtime = buf.st_mtime;
entry->size = buf.st_size;
}
entry->fullname = g_strdup(path);
entry->name = g_strdup(fname);
- entry->ctime = buf.st_ctime;
+ entry->ctime = ST_CREATE_TIME(buf);
entry->mtime = buf.st_mtime;
entry->size = buf.st_size;
entry->current = current;
/* add all file set entries to the dialog */
-void fileset_update_dlg(void)
+void fileset_update_dlg(void *window)
{
GList *le;
-
- /* add all entires to the dialog */
+ /* Add all entries to the dialog. */
+ fileset_dlg_begin_add_file(window);
le = g_list_first(set.entries);
while(le) {
- fileset_dlg_add_file((fileset_entry *)le->data);
+ fileset_dlg_add_file((fileset_entry *)le->data, window);
le = g_list_next(le);
}
+ fileset_dlg_end_add_file(window);
}
/* walk through the directory of the loaded file and add every file matching the current file */
void
-fileset_add_dir(const char *fname)
+fileset_add_dir(const char *fname, void *window)
{
WS_DIR *dir; /* scanned directory */
WS_DIRENT *file; /* current file */
/* get (convert) directory name, but don't touch the given string */
- fname_dup = get_dirname(g_strdup(fname));
- dirname = g_string_new(fname_dup);
+ fname_dup = g_strdup(fname);
+ dirname = g_string_new(get_dirname(fname_dup));
g_free(fname_dup);
set.dirname = g_strdup(dirname->str);
/* sort entries by creation time */
set.entries = g_list_sort(set.entries, fileset_sort_compare);
- fileset_update_dlg();
+ fileset_update_dlg(window);
}
fileset_entry *entry;
- /* add all entires to the dialog */
+ /* add all entries to the dialog */
le = g_list_first(set.entries);
while(le) {
entry = (fileset_entry *)le->data;
}
}
-
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */