aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/hcidump.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-10-06 18:00:57 -0700
committerGuy Harris <guy@alum.mit.edu>2014-10-07 01:01:59 +0000
commit670ebda4a6af0d30e033b0af48cfd15ce52c10eb (patch)
treeb092e44c944c4eb7566964da4cfb914e6002bd6d /wiretap/hcidump.c
parent6397ad43c2374ebde388041f2bd7ac925606a51e (diff)
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an error number pointer, and an error string pointer as arguments, and that treats a short read of any sort, including a read that returns 0 bytes, as a WTAP_ERR_SHORT_READ error, and that returns the error number and string through its last two arguments. Add wtap_read_bytes_or_eof(), which is similar, but that treats a read that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF indication. Use those in file readers; that simplifies the code and makes it less likely that somebody will fail to supply the error number and error string on a file read error. Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210 Reviewed-on: https://code.wireshark.org/review/4512 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/hcidump.c')
-rw-r--r--wiretap/hcidump.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c
index 1a508968d9..d4a6d2fc60 100644
--- a/wiretap/hcidump.c
+++ b/wiretap/hcidump.c
@@ -38,15 +38,10 @@ static gboolean hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr,
Buffer *buf, int *err, gchar **err_info)
{
struct dump_hdr dh;
- int bytes_read, packet_size;
+ int packet_size;
- bytes_read = file_read(&dh, DUMP_HDR_SIZE, fh);
- if (bytes_read != DUMP_HDR_SIZE) {
- *err = file_error(fh, err_info);
- if (*err == 0 && bytes_read != 0)
- *err = WTAP_ERR_SHORT_READ;
+ if (!wtap_read_bytes_or_eof(fh, &dh, DUMP_HDR_SIZE, err, err_info))
return FALSE;
- }
packet_size = GUINT16_FROM_LE(dh.len);
if (packet_size > WTAP_MAX_PACKET_SIZE) {
@@ -94,12 +89,9 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info)
{
struct dump_hdr dh;
guint8 type;
- int bytes_read;
- bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh);
- if (bytes_read != DUMP_HDR_SIZE) {
- *err = file_error(wth->fh, err_info);
- if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
+ if (!wtap_read_bytes(wth->fh, &dh, DUMP_HDR_SIZE, err, err_info)) {
+ if (*err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
}
@@ -108,10 +100,8 @@ int hcidump_open(wtap *wth, int *err, gchar **err_info)
|| GUINT16_FROM_LE(dh.len) < 1)
return 0;
- bytes_read = file_read(&type, 1, wth->fh);
- if (bytes_read != 1) {
- *err = file_error(wth->fh, err_info);
- if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
+ if (!wtap_read_bytes(wth->fh, &type, 1, err, err_info)) {
+ if (*err != WTAP_ERR_SHORT_READ)
return -1;
return 0;
}