forked from osmocom/wireshark
Replace lseek/fstat by ws_lseek64/ws_fstat64
lseek returns an off_t type which is system-dependent. Use ws_lseek64 in favor of lseek as that supports 64-bit quanities. Use ws_fstat64 instead of stat to support 64-bit file sizes on Windows. For the majority of the changes, this makes no difference as they do not apply to Windows ("ifndef _WIN32"; availability of st_blksize). There are no other users of "struct stat" besides the portability code in wsutil. Forbid the use of fstat and lseek in checkAPIs. Change-Id: I17b930ab9543f21a9d3100f3795d250c9b9ae459 Reviewed-on: https://code.wireshark.org/review/3198 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
c3e42cc6b4
commit
0492921adc
|
@ -781,7 +781,7 @@ FILE_F
|
|||
file_fdopen(int fd)
|
||||
{
|
||||
#ifdef _STATBUF_ST_BLKSIZE /* XXX, _STATBUF_ST_BLKSIZE portable? */
|
||||
struct stat st;
|
||||
ws_statb64 st;
|
||||
#endif
|
||||
int want = GZBUFSIZE;
|
||||
FILE_F state;
|
||||
|
@ -812,7 +812,7 @@ file_fdopen(int fd)
|
|||
gz_reset(state);
|
||||
|
||||
#ifdef _STATBUF_ST_BLKSIZE
|
||||
if (fstat(fd, &st) >= 0) {
|
||||
if (ws_fstat64(fd, &st) >= 0) {
|
||||
/*
|
||||
* Yes, st_blksize can be bigger than an int; apparently,
|
||||
* it's a long on LP64 Linux, for example.
|
||||
|
|
|
@ -3148,7 +3148,7 @@ read_asn1_type_table(const char *filename)
|
|||
int ret;
|
||||
guint size = 0;
|
||||
guchar *data;
|
||||
struct stat file_stat;
|
||||
ws_statb64 file_stat;
|
||||
static guint mylogh = 0;
|
||||
|
||||
if ((filename == 0) || (strlen(filename) == 0))
|
||||
|
@ -3170,7 +3170,7 @@ read_asn1_type_table(const char *filename)
|
|||
report_open_failure(filename, errno, FALSE);
|
||||
return;
|
||||
}
|
||||
ret = fstat(fileno(f), &file_stat);
|
||||
ret = ws_fstat64(fileno(f), &file_stat);
|
||||
if (ret!=-1)
|
||||
size = (int)file_stat.st_size;
|
||||
if (size == 0) {
|
||||
|
|
|
@ -1960,9 +1960,9 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
|
|||
*/
|
||||
#ifndef _WIN32
|
||||
if (print_packet_info) {
|
||||
struct stat stat_stdout, stat_stderr;
|
||||
ws_statb64 stat_stdout, stat_stderr;
|
||||
|
||||
if (fstat(1, &stat_stdout) == 0 && fstat(2, &stat_stderr) == 0) {
|
||||
if (ws_fstat64(1, &stat_stdout) == 0 && ws_fstat64(2, &stat_stderr) == 0) {
|
||||
if (stat_stdout.st_dev == stat_stderr.st_dev &&
|
||||
stat_stdout.st_ino == stat_stderr.st_ino) {
|
||||
fflush(stdout);
|
||||
|
|
|
@ -119,6 +119,8 @@ my %APIs = (
|
|||
'remove',
|
||||
'fopen',
|
||||
'freopen',
|
||||
'fstat',
|
||||
'lseek',
|
||||
# Misc
|
||||
'tmpnam', # use mkstemp
|
||||
'_snwprintf' # use StringCchPrintf
|
||||
|
|
4
tshark.c
4
tshark.c
|
@ -3417,9 +3417,9 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
|
|||
*/
|
||||
#ifndef _WIN32
|
||||
if (print_packet_info) {
|
||||
struct stat stat_stdout, stat_stderr;
|
||||
ws_statb64 stat_stdout, stat_stderr;
|
||||
|
||||
if (fstat(1, &stat_stdout) == 0 && fstat(2, &stat_stderr) == 0) {
|
||||
if (ws_fstat64(1, &stat_stdout) == 0 && ws_fstat64(2, &stat_stderr) == 0) {
|
||||
if (stat_stdout.st_dev == stat_stderr.st_dev &&
|
||||
stat_stdout.st_ino == stat_stderr.st_ino) {
|
||||
fflush(stdout);
|
||||
|
|
|
@ -2191,11 +2191,11 @@ static gboolean wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, g
|
|||
cant_seek = TRUE;
|
||||
} else {
|
||||
fd = fileno((FILE *)wdh->fh);
|
||||
if (lseek(fd, 1, SEEK_CUR) == -1)
|
||||
if (ws_lseek64(fd, 1, SEEK_CUR) == (off_t) -1)
|
||||
cant_seek = TRUE;
|
||||
else {
|
||||
/* Undo the seek. */
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
ws_lseek64(fd, 0, SEEK_SET);
|
||||
cant_seek = FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -781,7 +781,7 @@ FILE_T
|
|||
file_fdopen(int fd)
|
||||
{
|
||||
#ifdef _STATBUF_ST_BLKSIZE /* XXX, _STATBUF_ST_BLKSIZE portable? */
|
||||
struct stat st;
|
||||
ws_statb64 st;
|
||||
#endif
|
||||
int want = GZBUFSIZE;
|
||||
FILE_T state;
|
||||
|
@ -812,7 +812,7 @@ file_fdopen(int fd)
|
|||
gz_reset(state);
|
||||
|
||||
#ifdef _STATBUF_ST_BLKSIZE
|
||||
if (fstat(fd, &st) >= 0) {
|
||||
if (ws_fstat64(fd, &st) >= 0) {
|
||||
/*
|
||||
* Yes, st_blksize can be bigger than an int; apparently,
|
||||
* it's a long on LP64 Linux, for example.
|
||||
|
|
Loading…
Reference in New Issue