Register a few more file extensions as belonging to Wireshark.
[metze/wireshark/wip.git] / wiretap / tnef.c
index aada2b9c0fc39b800ed4fca18eb6ad81f498166b..2b6266596b74df58c29839292e126de056b7ab12 100644 (file)
 
 #include <errno.h>
 
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
 #include "wtap-int.h"
 #include "file_wrappers.h"
 #include <wsutil/buffer.h>
@@ -46,7 +42,7 @@ static gboolean tnef_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
      */
     *err = WTAP_ERR_BAD_FILE;
     *err_info = g_strdup_printf("tnef: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
-                               file_size, WTAP_MAX_PACKET_SIZE);
+                                file_size, WTAP_MAX_PACKET_SIZE);
     return FALSE;
   }
   packet_size = (int)file_size;
@@ -96,24 +92,20 @@ static gboolean tnef_seek_read(wtap *wth, gint64 seek_off,
   return tnef_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
 }
 
-int tnef_open(wtap *wth, int *err, gchar **err_info)
+wtap_open_return_val tnef_open(wtap *wth, int *err, gchar **err_info)
 {
-  int bytes_read;
   guint32 magic;
 
-  bytes_read = file_read(&magic, sizeof magic, wth->fh);
-  if (bytes_read != sizeof magic) {
-    *err = file_error(wth->fh, err_info);
-    return (*err != 0) ? -1 : 0;
-  }
+  if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, err, err_info))
+    return (*err != WTAP_ERR_SHORT_READ) ? WTAP_OPEN_ERROR : WTAP_OPEN_NOT_MINE;
 
   if (GUINT32_TO_LE(magic) != TNEF_SIGNATURE)
      /* Not a tnef file */
-     return 0;
+     return WTAP_OPEN_NOT_MINE;
 
   /* seek back to the start of the file  */
   if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
-    return -1;
+    return WTAP_OPEN_ERROR;
 
   wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_TNEF;
   wth->file_encap = WTAP_ENCAP_TNEF;
@@ -121,7 +113,20 @@ int tnef_open(wtap *wth, int *err, gchar **err_info)
 
   wth->subtype_read = tnef_read;
   wth->subtype_seek_read = tnef_seek_read;
-  wth->tsprecision = WTAP_FILE_TSPREC_SEC;
+  wth->file_tsprec = WTAP_TSPREC_SEC;
 
-  return 1;
+  return WTAP_OPEN_MINE;
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local Variables:
+ * c-basic-offset: 2
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=2 tabstop=8 expandtab:
+ * :indentSize=2:tabSize=8:noTabs=true:
+ */