summaryrefslogtreecommitdiff
path: root/savefile.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-10-31 16:43:46 -0700
committerGuy Harris <guy@alum.mit.edu>2017-10-31 16:43:46 -0700
commitee4e10fc6a5a9f97438284758c02e64131b03a01 (patch)
tree6788b63d9811a6e10d7cb4fa92c5caba2d45794f /savefile.c
parenta16ca2786d56bff6cab41dd1542a387c77bb7370 (diff)
downloadlibpcap-ee4e10fc6a5a9f97438284758c02e64131b03a01.tar.gz
Handle fopen() and fopen_s() differently.
If we have fopen_s(), define pcap_fopen as fopen_s(). Otherwise, have a pcap_fopen() routine, which is a wrapper for fopen() and has the same signature as fopen_s(). Use pcap_fopen() - and don't worry about "b" in the mode argument, it's required by C90.
Diffstat (limited to 'savefile.c')
-rw-r--r--savefile.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/savefile.c b/savefile.c
index 2629f972..c5467c01 100644
--- a/savefile.c
+++ b/savefile.c
@@ -44,6 +44,8 @@
#include <stdlib.h>
#include <string.h>
+#include "fopen.h"
+
#include "pcap-int.h"
#ifdef HAVE_OS_PROTO_H
@@ -245,22 +247,6 @@ sf_cleanup(pcap_t *p)
pcap_freecode(&p->fcode);
}
-/*
-* fopen's safe version on Windows.
-*/
-#ifdef _MSC_VER
-FILE *fopen_safe(const char *filename, const char* mode)
-{
- FILE *fp = NULL;
- errno_t errno;
- errno = fopen_s(&fp, filename, mode);
- if (errno == 0)
- return fp;
- else
- return NULL;
-}
-#endif
-
pcap_t *
pcap_open_offline_with_tstamp_precision(const char *fname, u_int precision,
char *errbuf)
@@ -285,14 +271,12 @@ pcap_open_offline_with_tstamp_precision(const char *fname, u_int precision,
#endif
}
else {
-#if !defined(_WIN32) && !defined(MSDOS)
- fp = fopen(fname, "r");
-#else
- fp = fopen(fname, "rb");
-#endif
- if (fp == NULL) {
+ int err;
+
+ err = pcap_fopen(&fp, fname, "rb");
+ if (err != 0) {
pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", fname,
- pcap_strerror(errno));
+ pcap_strerror(err));
return (NULL);
}
}