diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-09-28 16:45:23 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-09-28 23:45:58 +0000 |
commit | 48a66835ee4f319ba7806a542bb2cf1f16a2ac06 (patch) | |
tree | f4b86d49b651fc55047f16d98b1c2401238e03ec /wiretap/file_wrappers.c | |
parent | a3ce2336b2a0e684a94d1e0046556bc0b42748f2 (diff) |
Use wtap_read_bytes() to skip over bytes when reading a record.
Allow file_read() to take a null pointer as a buffer argument; a null
argument means "do everything except copy the bytes from the file to the
user buffer". That means that wtap_read_bytes() and
wtap_read_bytes_or_eof() also support a null pointer as a buffer
argument.
Use wtap_read_bytes() with a null buffer argument rather than
file_skip() to skip forward over data.
This fixes some places where files were mis-identified as ERF files, as
the ERF open heuristics now get a short "read" error if they try to skip
over more bytes than exist in the file.
Change-Id: I4f73499d877c1f582e2bcf9b045034880cb09622
Reviewed-on: https://code.wireshark.org/review/17974
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/file_wrappers.c')
-rw-r--r-- | wiretap/file_wrappers.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index fa4b21c961..c466c5f223 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -1145,21 +1145,6 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err) return file->pos + offset; } -/* - * Skip forward the specified number of bytes in the file. - * Currently implemented as a wrapper around file_seek(), - * but if, for example, we ever add support for reading - * sequentially from a pipe, this could instead just skip - * forward by reading the bytes in question. - */ -gboolean -file_skip(FILE_T file, gint64 delta, int *err) -{ - if (file_seek(file, delta, SEEK_CUR, err) == -1) - return FALSE; - return TRUE; -} - gint64 file_tell(FILE_T stream) { @@ -1206,16 +1191,25 @@ file_read(void *buf, unsigned int len, FILE_T file) return -1; } - /* get len bytes to buf, or less than len if at the end */ + /* + * Get len bytes to buf, or less than len if at the end; + * if buf is null, just throw the bytes away. + */ got = 0; do { if (file->have) { /* We have stuff in the output buffer; copy what we have. */ n = file->have > len ? len : file->have; - memcpy(buf, file->next, n); + if (buf != NULL) { + memcpy(buf, file->next, n); + buf = (char *)buf + n; + } file->next += n; file->have -= n; + len -= n; + got += n; + file->pos += n; } else if (file->err) { /* We have nothing in the output buffer, and we have an error that may not have been @@ -1236,13 +1230,7 @@ file_read(void *buf, unsigned int len, FILE_T file) in the output buffer. */ if (fill_out_buffer(file) == -1) return -1; - continue; /* no progress yet -- go back to memcpy() above */ } - /* update progress */ - len -= n; - buf = (char *)buf + n; - got += n; - file->pos += n; } while (len); return (int)got; |