Get rid of C++/C99-style comments.
[metze/wireshark/wip.git] / fileset.c
index e6b63e9fca5f9de0a63b488d98c0ed47f70aea7f..869ae26b09f8c1e6f5c2392d6de7b75247ccd995 100644 (file)
--- a/fileset.c
+++ b/fileset.c
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #include "globals.h"
 
 #include <epan/filesystem.h>
+#include <epan/strutil.h>
 
 #include "fileset.h"
 
 
 
 typedef struct _fileset {
-  GList   *entries;
-  char    *dirname;
+    GList   *entries;
+    char    *dirname;
 } fileset;
 
 /* this is the fileset's global data */
-fileset set = { NULL, NULL};
+static fileset set = { NULL, NULL};
 
 
 /* is this a probable file of a file set (does the naming pattern match)? */
@@ -127,7 +126,7 @@ fileset_filename_match_pattern(const char *fname)
 
 /* 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;
@@ -171,13 +170,57 @@ fileset_is_file_in_set(const char *fname1, const char *fname2)
     return TRUE;
 }
 
+/* GCompareFunc helper for g_list_find_custom() */
+static gint
+fileset_find_by_path(gconstpointer a, gconstpointer b)
+{
+    const fileset_entry *entry;
+    const char *path;
+
+    entry = (const fileset_entry *) a;
+    path  = (const char *) b;
+
+    return g_strcmp0(entry->fullname, path);
+}
+
+/* update the time and size of this file in the list */
+void
+fileset_update_file(const char *path)
+{
+    int fh, result;
+    ws_statb64 buf;
+    fileset_entry *entry = NULL;
+    GList *entry_list;
+
+    fh = ws_open( path, O_RDONLY, 0000 /* no creation so don't matter */);
+    if(fh !=  -1) {
+
+        /* Get statistics */
+        result = ws_fstat64( fh, &buf );
+
+        /* Show statistics if they are valid */
+        if( result == 0 ) {
+            entry_list = g_list_find_custom(set.entries, path,
+                                            fileset_find_by_path);
+
+            if (entry_list) {
+                entry = (fileset_entry *) entry_list->data;
+                entry->ctime    = buf.st_ctime;
+                entry->mtime    = buf.st_mtime;
+                entry->size     = buf.st_size;
+            }
+        }
+
+        ws_close(fh);
+    }
+}
 
 /* we know this file is part of the set, so add it */
 static fileset_entry *
 fileset_add_file(const char *dirname, const char *fname, gboolean current)
 {
     int fh, result;
-    struct stat buf;
+    ws_statb64 buf;
     char *path;
     fileset_entry *entry = NULL;
 
@@ -188,7 +231,7 @@ fileset_add_file(const char *dirname, const char *fname, gboolean current)
     if(fh !=  -1) {
 
         /* Get statistics */
-        result = fstat( fh, &buf );
+        result = ws_fstat64( fh, &buf );
 
         /* Show statistics if they are valid */
         if( result == 0 ) {
@@ -225,7 +268,7 @@ fileset_sort_compare(gconstpointer a, gconstpointer b)
 
 
 /* add all file set entries to the dialog */
-void fileset_update_dlg(void)
+void fileset_update_dlg(void *window)
 {
     GList         *le;
 
@@ -233,7 +276,7 @@ void fileset_update_dlg(void)
     /* add all entires to the dialog */
     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);
     }
 }
@@ -241,7 +284,7 @@ void fileset_update_dlg(void)
 
 /* 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 */
@@ -263,8 +306,8 @@ fileset_add_dir(const char *fname)
     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 ((dir = ws_dir_open(dirname->str, 0, NULL)) != NULL) {
-               while ((file = ws_dir_read_name(dir)) != NULL) {
-                   name = ws_dir_get_name(file);
+            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 */);
                 }
@@ -283,7 +326,7 @@ fileset_add_dir(const char *fname)
     /* sort entries by creation time */
     set.entries = g_list_sort(set.entries, fileset_sort_compare);
 
-    fileset_update_dlg();
+    fileset_update_dlg(window);
 }
 
 
@@ -388,5 +431,3 @@ void fileset_delete(void)
         set.dirname = NULL;
     }
 }
-
-