summaryrefslogtreecommitdiff
path: root/wiretap/camins.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/camins.c
parent6397ad43c2374ebde388041f2bd7ac925606a51e (diff)
downloadwireshark-670ebda4a6af0d30e033b0af48cfd15ce52c10eb.tar.gz
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/camins.c')
-rw-r--r--wiretap/camins.c33
1 files changed, 7 insertions, 26 deletions
diff --git a/wiretap/camins.c b/wiretap/camins.c
index d5aafe9fcc..82657f2e2b 100644
--- a/wiretap/camins.c
+++ b/wiretap/camins.c
@@ -107,26 +107,6 @@ typedef enum {
#define DVB_CI_PSEUDO_HDR_HOST_TO_CAM 0xFE
-/* read a block of data from the camins file and handle the errors */
-static gboolean
-read_block(FILE_T fh, guint8 *buf, guint16 buf_len, int *err, gchar **err_info)
-{
- int bytes_read;
-
- bytes_read = file_read((void *)buf, buf_len, fh);
- if (bytes_read != buf_len) {
- *err = file_error(fh, err_info);
- /* bytes_read==0 is end of file */
- if (bytes_read>0 && *err == 0) {
- *err = WTAP_ERR_SHORT_READ;
- }
- return FALSE;
- }
-
- return TRUE;
-}
-
-
/* find the transaction type for the data bytes of the next packet
and the number of data bytes in that packet
the fd is moved such that it can be used in a subsequent call
@@ -146,7 +126,7 @@ find_next_pkt_dat_type_len(FILE_T fh,
RESET_STAT_VALS;
do {
- if (read_block(fh, block, sizeof(block), err, err_info) == FALSE) {
+ if (!wtap_read_bytes_or_eof(fh, block, sizeof(block), err, err_info)) {
RESET_STAT_VALS;
return FALSE;
}
@@ -212,7 +192,7 @@ read_packet_data(FILE_T fh, guint8 dat_trans_type, guint8 *buf, guint16 dat_len,
p = buf;
while (bytes_count < dat_len) {
- if (read_block(fh, block, sizeof(block), err, err_info) == FALSE)
+ if (!wtap_read_bytes_or_eof(fh, block, sizeof(block), err, err_info))
break;
if (block[1] == dat_trans_type) {
@@ -324,14 +304,15 @@ int camins_open(wtap *wth, int *err, gchar **err_info _U_)
guint8 found_start_blocks = 0;
guint8 count = 0;
guint8 block[2];
- int bytes_read;
/* all CAM Inspector files I've looked at have at least two blocks of
0x00 0xE1 within the first 20 bytes */
do {
- bytes_read = file_read(block, sizeof(block), wth->fh);
- if (bytes_read != sizeof(block))
- break;
+ if (!wtap_read_bytes(wth->fh, block, sizeof(block), err, err_info)) {
+ if (*err == WTAP_ERR_SHORT_READ)
+ break;
+ return -1;
+ }
if (block[0]==0x00 && block[1] == 0xE1)
found_start_blocks++;