diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-06-27 18:38:13 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-06-27 18:38:13 +0000 |
commit | 7cfb61a9b9d4d229afc86b347be4b4f696159b61 (patch) | |
tree | 028a85142b5dcf820d4a79533ebb325b81e54117 /lib/libarchive/archive_write_open_fd.c | |
parent | 34ed55636f92a39a90a92eadbea5f89e0b642b23 (diff) | |
download | FreeBSD-src-7cfb61a9b9d4d229afc86b347be4b4f696159b61.zip FreeBSD-src-7cfb61a9b9d4d229afc86b347be4b4f696159b61.tar.gz |
Clean up some consistent confusion between "dev" and "rdev."
Mostly, these were being used correctly even though a lot of
variables and function names were mis-named.
In the process, I found and fixed a couple of latent bugs and
added a guard against adding an archive to itself.
Diffstat (limited to 'lib/libarchive/archive_write_open_fd.c')
-rw-r--r-- | lib/libarchive/archive_write_open_fd.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/libarchive/archive_write_open_fd.c b/lib/libarchive/archive_write_open_fd.c index 21c7074..ae8c2e2 100644 --- a/lib/libarchive/archive_write_open_fd.c +++ b/lib/libarchive/archive_write_open_fd.c @@ -64,8 +64,9 @@ static int file_open(struct archive *a, void *client_data) { struct write_fd_data *mine; - struct stat st; + struct stat st, *pst; + pst = NULL; mine = client_data; /* @@ -75,12 +76,14 @@ file_open(struct archive *a, void *client_data) */ if (mine->fd >= 0 && a->bytes_in_last_block < 0) { /* Last block will be fully padded. */ - fstat(mine->fd, &st); - if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || - S_ISFIFO(st.st_mode)) - archive_write_set_bytes_in_last_block(a, 0); - else - archive_write_set_bytes_in_last_block(a, 1); + if (fstat(mine->fd, &st) == 0) { + pst = &st; + if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || + S_ISFIFO(st.st_mode)) + archive_write_set_bytes_in_last_block(a, 0); + else + archive_write_set_bytes_in_last_block(a, 1); + } } if (mine->fd == 1) { @@ -94,6 +97,13 @@ file_open(struct archive *a, void *client_data) return (ARCHIVE_FATAL); } + if (pst == NULL && fstat(mine->fd, &st) == 0) + pst = &st; + if (pst == NULL) { + archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); } |