aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'wiretap/file.c')
-rw-r--r--wiretap/file.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/wiretap/file.c b/wiretap/file.c
index bedaf92b6f..7a24ab3a05 100644
--- a/wiretap/file.c
+++ b/wiretap/file.c
@@ -1,6 +1,6 @@
/* file.c
*
- * $Id: file.c,v 1.24 1999/09/24 05:49:50 guy Exp $
+ * $Id: file.c,v 1.25 1999/10/05 07:06:05 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -261,3 +261,40 @@ int wtap_dump_close(wtap_dumper *wdh, int *err)
return ret;
}
+/*
+ * Routine to return a Wiretap error code (0 for no error, an errno
+ * for a file error, or a WTAP_ERR_ code for other errors) for an
+ * I/O stream.
+ */
+#ifdef HAVE_LIBZ
+int
+file_error(void *fh)
+{
+ int errnum;
+
+ gzerror(fh, &errnum);
+ switch (errnum) {
+
+ case Z_OK: /* no error */
+ return 0;
+
+ case Z_STREAM_END: /* EOF - not an error */
+ return 0;
+
+ case Z_ERRNO: /* file I/O error */
+ return errno;
+
+ default:
+ return WTAP_ERR_ZLIB + errnum;
+ }
+}
+#else /* HAVE_LIBZ */
+int
+file_error(FILE *fh)
+{
+ if (ferror(fh))
+ return errno;
+ else
+ return 0;
+}
+#endif /* HAVE_LIBZ */