Fix the problems WRT overwriting a capture file. From Joerg Mayer.
authorsharpe <sharpe@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 21 Jul 2002 16:54:22 +0000 (16:54 +0000)
committersharpe <sharpe@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 21 Jul 2002 16:54:22 +0000 (16:54 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@5898 f5534014-38df-0310-8fa8-9805f1628bb7

file.c

diff --git a/file.c b/file.c
index a08c3f0cdec74fe247f236655603acd71752b059..995ceb77f536f2ebc99df6019eb39667b20f6731 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
 /* file.c
  * File I/O routines
  *
- * $Id: file.c,v 1.282 2002/07/16 07:15:04 guy Exp $
+ * $Id: file.c,v 1.283 2002/07/21 16:54:22 sharpe Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -1725,6 +1725,7 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
   struct wtap_pkthdr hdr;
   union wtap_pseudo_header pseudo_header;
   guint8        pd[65536];
+  struct stat   infile, outfile;
 
   name_ptr = get_basename(fname);
   msg_len = strlen(name_ptr) + strlen(save_fmt) + 2;
@@ -1736,8 +1737,15 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
   /* 
    * Check that the from file is not the same as to file 
    * We do it here so we catch all cases ...
+   * Unfortunately, the file requester gives us an absolute file
+   * name and the read file name may be relative (if supplied on
+   * the command line). From Joerg Mayer.
    */
-  if (strcmp(cf->filename, fname) == 0) {
+   infile.st_ino = 1;   /* These prevent us from getting equality         */
+   outfile.st_ino = 2;  /* If one or other of the files is not accessible */
+   stat(cf->filename, &infile);
+   stat(fname, &outfile);
+   if (infile.st_ino == outfile.st_ino) {
     simple_dialog(ESD_TYPE_CRIT, NULL, 
                      "Can't save over current capture file: %s!",
                      cf->filename);