From 8c9edf12800bc6d68894dc457e7ebaf994429da8 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 16 Jun 2013 00:20:00 +0000 Subject: Have the seek-read routines take a Buffer rather than a guint8 pointer as the "where to put the packet data" argument. This lets more of the libwiretap code be common between the read and seek-read code paths, and also allows for more flexibility in the "fill in the data" path - we can expand the buffer as needed in both cases. svn path=/trunk/; revision=49949 --- wiretap/5views.c | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) (limited to 'wiretap/5views.c') diff --git a/wiretap/5views.c b/wiretap/5views.c index b1deabc451..9336cd4333 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -104,12 +104,10 @@ typedef struct static gboolean _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset); static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, - struct wtap_pkthdr *phdr, guint8 *pd, int length, + struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err, gchar **err_info); static int _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, struct wtap_pkthdr *phdr, int *err, gchar **err_info); -static gboolean _5views_read_rec_data(FILE_T fh, guint8 *pd, int length, - int *err, gchar **err_info); static gboolean _5views_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err); static gboolean _5views_dump_close(wtap_dumper *wdh, int *err); @@ -239,17 +237,13 @@ _5views_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) return FALSE; } - buffer_assure_space(wth->frame_buffer, wth->phdr.caplen); - if (!_5views_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), - wth->phdr.caplen, err, err_info)) - return FALSE; /* Read error */ - - return TRUE; + return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, + wth->phdr.caplen, err, err_info); } static gboolean _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, - guint8 *pd, int length, int *err, gchar **err_info) + Buffer *buf, int length, int *err, gchar **err_info) { t_5VW_TimeStamped_Header TimeStamped_Header; @@ -266,10 +260,8 @@ _5views_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, /* * Read the packet data. */ - if (!_5views_read_rec_data(wth->random_fh, pd, length, err, err_info)) - return FALSE; - - return TRUE; + return wtap_read_packet_bytes(wth->random_fh, buf, length, + err, err_info); } /* Read the header of the next packet. Return TRUE on success, FALSE @@ -322,24 +314,6 @@ _5views_read_header(wtap *wth, FILE_T fh, t_5VW_TimeStamped_Header *hdr, return TRUE; } -static gboolean -_5views_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err, - gchar **err_info) -{ - int bytes_read; - - errno = WTAP_ERR_CANT_READ; - bytes_read = file_read(pd, length, fh); - - if (bytes_read != length) { - *err = file_error(fh, err_info); - if (*err == 0) - *err = WTAP_ERR_SHORT_READ; - return FALSE; - } - return TRUE; -} - typedef struct { guint32 nframes; } _5views_dump_t; -- cgit v1.2.1