aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/commview.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/commview.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/commview.c')
-rw-r--r--wiretap/commview.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/wiretap/commview.c b/wiretap/commview.c
index e0c24326d1..b9154d965d 100644
--- a/wiretap/commview.c
+++ b/wiretap/commview.c
@@ -208,24 +208,42 @@ static gboolean
commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err,
gchar **err_info)
{
- wtap_file_read_expected_bytes(&cv_hdr->data_len, 2, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->source_data_len, 2, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->version, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->year, 2, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->month, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->day, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->hours, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->minutes, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->seconds, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->usecs, 4, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->flags, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->signal_level_percent, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->rate, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->band, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->channel, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->direction, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->signal_level_dbm, 1, fh, err, err_info);
- wtap_file_read_expected_bytes(&cv_hdr->noise_level, 1, fh, err, err_info);
+ if (!wtap_read_bytes_or_eof(fh, &cv_hdr->data_len, 2, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->source_data_len, 2, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->version, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->year, 2, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->month, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->day, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->hours, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->minutes, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->seconds, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->usecs, 4, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->flags, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->signal_level_percent, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->rate, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->band, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->channel, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->direction, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->signal_level_dbm, 1, err, err_info))
+ return FALSE;
+ if (!wtap_read_bytes(fh, &cv_hdr->noise_level, 1, err, err_info))
+ return FALSE;
/* Convert multi-byte values from little endian to host endian format */
cv_hdr->data_len = GUINT16_FROM_LE(cv_hdr->data_len);