*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * 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
#include <unistd.h>
#endif
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
# include <sys/wait.h>
#endif
+#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <glib.h>
+#include <wsutil/file_util.h>
#include "globals.h"
#include <epan/filesystem.h>
fileset_filename_match_pattern(const char *fname)
{
char *pfx;
- int baselen;
- int minlen = strlen("_00001_20050418010750");
+ size_t baselen;
+ size_t minlen = strlen("_00001_20050418010750");
char *filename;
-
+
/* d:\dir1\test_00001_20050418010750.cap */
filename = g_strdup(get_basename(fname));
/* test_00001_20050418010750.cap */
pfx = strrchr(filename, '.');
- if(pfx == NULL) {
- return FALSE;
+ if(pfx == NULL) { /* suffix is optional */
+ pfx = filename + strlen(filename);
}
/* test_00001_20050418010750 */
*pfx = '\0';
while(minlen--) {
baselen--;
- if(!isdigit( (int) filename[baselen])) {
+ if(!isdigit( (guchar) filename[baselen])) {
g_free(filename);
return FALSE;
}
char *pfx2;
char *dup_f1;
char *dup_f2;
- int minlen = strlen("_00001_20050418010750");
+ size_t minlen = strlen("_00001_20050418010750");
/* just to be sure ... */
pfx1 = strrchr(dup_f1, '.');
pfx2 = strrchr(dup_f2, '.');
+ /* suffix is optional */
+ if (!pfx1) pfx1 = dup_f1 + strlen(dup_f1);
+ if (!pfx2) pfx2 = dup_f2 + strlen(dup_f2);
/* the optional suffix (file extension) must be equal */
if(strcmp(pfx1, pfx2) != 0) {
/* we know this file is part of the set, so add it */
-fileset_entry *
+static fileset_entry *
fileset_add_file(const char *dirname, const char *fname, gboolean current)
{
int fh, result;
path = g_strdup_printf("%s%s", dirname, fname);
- fh = open( path, O_RDONLY );
+ fh = ws_open( path, O_RDONLY, 0000 /* no creation so don't matter */);
if(fh != -1) {
/* Get statistics */
set.entries = g_list_append(set.entries, entry);
}
- close(fh);
+ ws_close(fh);
}
g_free(path);
}
-/* compare two list entries by creation date/time */
-gint
-fileset_compare_creation(gconstpointer a, gconstpointer b)
+/* compare two list entries by creation date/time (through filename) */
+static gint
+fileset_sort_compare(gconstpointer a, gconstpointer b)
{
const fileset_entry *entry_a = a;
const fileset_entry *entry_b = b;
- return entry_a->ctime - entry_b->ctime;
+ return strcmp(entry_a->name, entry_b->name);
}
void
fileset_add_dir(const char *fname)
{
-#if GLIB_MAJOR_VERSION < 2
- DIR *dir; /* scanned directory */
- struct dirent *file; /* current file */
- gchar *name;
-#else /* GLIB 2 */
- GDir *dir; /* scanned directory */
- GError **dummy;
+ WS_DIR *dir; /* scanned directory */
+ WS_DIRENT *file; /* current file */
const char *name;
-#endif
- fileset_entry *entry;
GString *dirname;
gchar *fname_dup;
dirname = g_string_new(fname_dup);
g_free(fname_dup);
- set.dirname = g_strdup(dirname->str);
-
+ set.dirname = g_strdup(dirname->str);
+
dirname = g_string_append_c(dirname, G_DIR_SEPARATOR);
/* is the current file probably a part of any fileset? */
if(fileset_filename_match_pattern(fname)) {
/* yes, go through the files in the directory and check if the file in question is part of the current file set */
-#if GLIB_MAJOR_VERSION < 2
- if ((dir = opendir(dirname->str)) != NULL) {
- while ((file = readdir(dir)) != NULL) {
- name = (gchar *)file->d_name;
-#else
- dummy = g_malloc(sizeof(GError *));
- *dummy = NULL;
-
- if ((dir = g_dir_open(dirname->str, 0, dummy)) != NULL) {
- while ((name = g_dir_read_name(dir)) != NULL) {
-#endif
+ if ((dir = ws_dir_open(dirname->str, 0, NULL)) != NULL) {
+ while ((file = ws_dir_read_name(dir)) != NULL) {
+ name = ws_dir_get_name(file);
if(fileset_filename_match_pattern(name) && fileset_is_file_in_set(name, get_basename(fname))) {
fileset_add_file(dirname->str, name, strcmp(name, get_basename(fname))== 0 /* current */);
}
} /* while */
-#if GLIB_MAJOR_VERSION < 2
- closedir(dir);
-#else
- g_dir_close(dir);
-#endif
+ ws_dir_close(dir);
} /* if */
-#if GLIB_MAJOR_VERSION >= 2
- g_free(dummy);
-#endif
} else {
/* no, this is a "standalone file", just add this one */
- entry = fileset_add_file(dirname->str, get_basename(fname), TRUE /* current */);
- if(entry) {
- fileset_dlg_add_file(entry);
- }
+ fileset_add_file(dirname->str, get_basename(fname), TRUE /* current */);
+ /* don't add the file to the dialog here, this will be done in fileset_update_dlg() below */
}
g_string_free(dirname, TRUE /* free_segment */);
/* sort entries by creation time */
- set.entries = g_list_sort(set.entries, fileset_compare_creation);
+ set.entries = g_list_sort(set.entries, fileset_sort_compare);
fileset_update_dlg();
}
/* get the current list entry, or NULL */
-GList *
+static GList *
fileset_get_current(void)
{
GList *le;
/* delete a single entry */
-void fileset_entry_delete(gpointer data, gpointer user_data _U_)
+static void fileset_entry_delete(gpointer data, gpointer user_data _U_)
{
fileset_entry *entry = data;