diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-06-01 08:05:12 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-06-01 08:05:12 +0000 |
commit | 129c881fcf7c8707f379a09d2ed2cdfcc178b807 (patch) | |
tree | c3e2e1a9b39235d5b89594d3947e849d9152c09a /wiretap/file_wrappers.c | |
parent | 86c69b01e7965f37eecbe6195e797a52ab81e23e (diff) |
Sigh. There appears to be no way to get Windows to allow us to rename a
file that we ourselves have open. In the "safe save" code path for
capture files, on Windows temporarily close the file descriptors for the
currently-open capture before doing the rename and then, if the rename
failed, reopen them, leaving the rest of the wtap and capture_file
structures intact.
Rename filed_open() to file_fdopen(), to make its name match what it
does a bit better (it's an fdopen()-style routine, i.e. do the
equivalent of an open with an already-open file descriptor rather than a
pathname, in the file_wrappers.c set of routines).
Remove the file_ routines from the .def file for Wiretap - they should
only be called by code inside Wiretap.
Closing a descriptor open for input has no reason to fail (closing a
descriptor open for *writing* could fail if the file is on a server and
dirty pages are pushed asynchronously to the server and synchronously on
a close), so just have file_close() return void.
svn path=/trunk/; revision=42961
Diffstat (limited to 'wiretap/file_wrappers.c')
-rw-r--r-- | wiretap/file_wrappers.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index 67437acee9..537cc1a18e 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -766,7 +766,7 @@ gz_reset(FILE_T state) } FILE_T -filed_open(int fd) +file_fdopen(int fd) { #ifdef _STATBUF_ST_BLKSIZE /* XXX, _STATBUF_ST_BLKSIZE portable? */ struct stat st; @@ -862,7 +862,7 @@ file_open(const char *path) return NULL; /* open file handle */ - ft = filed_open(fd); + ft = file_fdopen(fd); if (ft == NULL) { ws_close(fd); return NULL; @@ -1274,7 +1274,25 @@ file_clearerr(FILE_T stream) stream->eof = 0; } -int +void +file_fdclose(FILE_T file) +{ + ws_close(file->fd); + file->fd = -1; +} + +gboolean +file_fdreopen(FILE_T file, const char *path) +{ + int fd; + + if ((fd = ws_open(path, O_RDONLY|O_BINARY, 0000)) == -1) + return FALSE; + file->fd = fd; + return TRUE; +} + +void file_close(FILE_T file) { int fd = file->fd; @@ -1291,7 +1309,13 @@ file_close(FILE_T file) file->err = 0; file->err_info = NULL; g_free(file); - return ws_close(fd); + /* + * If fd is -1, somebody's done a file_closefd() on us, so + * we don't need to close the FD itself, and shouldn't do + * so. + */ + if (fd != -1) + ws_close(fd); } #ifdef HAVE_LIBZ |