summaryrefslogtreecommitdiff
path: root/wiretap/toshiba.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2002-03-04 00:25:35 +0000
committerGuy Harris <guy@alum.mit.edu>2002-03-04 00:25:35 +0000
commitd54bd0bd6b3f8683031aae0cbf0107779ca40b58 (patch)
treeadc8f57b4cefa88b88ce35f476f4b456779cbd4b /wiretap/toshiba.c
parent7fef8be5ec6c35a80292f0d614f23dcb839a8397 (diff)
downloadwireshark-d54bd0bd6b3f8683031aae0cbf0107779ca40b58.tar.gz
Check for errors in seeks, "tell"s, and "stat()"s/"fstat()"s.
For file types where we allocate private data, add "close" routines where they were missing, to free the private data. Also fix up the code to clean up after some errors by freeing private data where that wasn't being done. Get rid of unused arguments to "wtap_dump_open_finish()". Fix indentation. svn path=/trunk/; revision=4857
Diffstat (limited to 'wiretap/toshiba.c')
-rw-r--r--wiretap/toshiba.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c
index b5b0f895a2..a644f5e566 100644
--- a/wiretap/toshiba.c
+++ b/wiretap/toshiba.c
@@ -1,6 +1,6 @@
/* toshiba.c
*
- * $Id: toshiba.c,v 1.20 2002/02/08 10:07:41 guy Exp $
+ * $Id: toshiba.c,v 1.21 2002/03/04 00:25:35 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -18,8 +18,8 @@
* 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.
- *
*/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -118,24 +118,38 @@ static int parse_toshiba_rec_hdr(wtap *wth, FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err);
/* Seeks to the beginning of the next packet, and returns the
- byte offset. Returns -1 on failure. */
-/* XXX - Handle I/O errors. */
-static long toshiba_seek_next_packet(wtap *wth)
+ byte offset. Returns -1 on failure, and sets "*err" to the error. */
+static long toshiba_seek_next_packet(wtap *wth, int *err)
{
int byte;
guint level = 0;
+ long cur_off;
while ((byte = file_getc(wth->fh)) != EOF) {
if (byte == toshiba_rec_magic[level]) {
level++;
if (level >= TOSHIBA_REC_MAGIC_SIZE) {
/* note: we're leaving file pointer right after the magic characters */
- return file_tell(wth->fh) + 1;
+ cur_off = file_tell(wth->fh);
+ if (cur_off == -1) {
+ /* Error. */
+ *err = file_error(wth->fh);
+ return -1;
+ }
+ return cur_off + 1;
}
} else {
level = 0;
}
}
+ if (file_eof(wth->fh)) {
+ /* We got an EOF. */
+ *err = 0;
+ } else {
+ /* We (presumably) got an error (there's no equivalent to "ferror()"
+ in zlib, alas, so we don't have a wrapper to check for an error). */
+ *err = file_error(wth->fh);
+ }
return -1;
}
@@ -145,9 +159,10 @@ static long toshiba_seek_next_packet(wtap *wth)
/* Look through the first part of a file to see if this is
* a Toshiba trace file.
*
- * Returns TRUE if it is, FALSE if it isn't.
+ * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
+ * if we get an I/O error, "*err" will be set to a non-zero value.
*/
-static gboolean toshiba_check_file_type(wtap *wth)
+static gboolean toshiba_check_file_type(wtap *wth, int *err)
{
char buf[TOSHIBA_LINE_LENGTH];
guint i, reclen, level, line;
@@ -178,19 +193,27 @@ static gboolean toshiba_check_file_type(wtap *wth)
}
}
else {
+ /* EOF or error. */
+ if (file_eof(wth->fh))
+ *err = 0;
+ else
+ *err = file_error(wth->fh);
return FALSE;
}
}
+ *err = 0;
return FALSE;
}
-/* XXX - return -1 on I/O error and actually do something with 'err'. */
int toshiba_open(wtap *wth, int *err)
{
/* Look for Toshiba header */
- if (!toshiba_check_file_type(wth)) {
- return 0;
+ if (!toshiba_check_file_type(wth, err)) {
+ if (*err == 0)
+ return 0;
+ else
+ return -1;
}
wth->data_offset = 0;
@@ -211,11 +234,9 @@ static gboolean toshiba_read(wtap *wth, int *err, long *data_offset)
int pkt_len;
/* Find the next packet */
- offset = toshiba_seek_next_packet(wth);
- if (offset < 1) {
- *err = 0; /* XXX - assume, for now, that it's an EOF */
+ offset = toshiba_seek_next_packet(wth, err);
+ if (offset < 1)
return FALSE;
- }
/* Parse the header */
pkt_len = parse_toshiba_rec_hdr(wth, wth->fh,