mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-13 14:40:22 +00:00
Merge from libarchive.googlecode.com: If we're
given an empty filename, just invoke write_open_fd() instead of re-implementing the code to use stdout.
This commit is contained in:
parent
018cd707c0
commit
625683944d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=191165
@ -71,24 +71,18 @@ archive_write_open_filename(struct archive *a, const char *filename)
|
|||||||
{
|
{
|
||||||
struct write_file_data *mine;
|
struct write_file_data *mine;
|
||||||
|
|
||||||
if (filename == NULL || filename[0] == '\0') {
|
if (filename == NULL || filename[0] == '\0')
|
||||||
mine = (struct write_file_data *)malloc(sizeof(*mine));
|
return (archive_write_open_fd(a, 1));
|
||||||
if (mine == NULL) {
|
|
||||||
archive_set_error(a, ENOMEM, "No memory");
|
mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename));
|
||||||
return (ARCHIVE_FATAL);
|
if (mine == NULL) {
|
||||||
}
|
archive_set_error(a, ENOMEM, "No memory");
|
||||||
mine->filename[0] = '\0'; /* Record that we're using stdout. */
|
return (ARCHIVE_FATAL);
|
||||||
} else {
|
|
||||||
mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename));
|
|
||||||
if (mine == NULL) {
|
|
||||||
archive_set_error(a, ENOMEM, "No memory");
|
|
||||||
return (ARCHIVE_FATAL);
|
|
||||||
}
|
|
||||||
strcpy(mine->filename, filename);
|
|
||||||
}
|
}
|
||||||
|
strcpy(mine->filename, filename);
|
||||||
mine->fd = -1;
|
mine->fd = -1;
|
||||||
return (archive_write_open(a, mine,
|
return (archive_write_open(a, mine,
|
||||||
file_open, file_write, file_close));
|
file_open, file_write, file_close));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -104,21 +98,11 @@ file_open(struct archive *a, void *client_data)
|
|||||||
/*
|
/*
|
||||||
* Open the file.
|
* Open the file.
|
||||||
*/
|
*/
|
||||||
if (mine->filename[0] != '\0') {
|
mine->fd = open(mine->filename, flags, 0666);
|
||||||
mine->fd = open(mine->filename, flags, 0666);
|
if (mine->fd < 0) {
|
||||||
if (mine->fd < 0) {
|
archive_set_error(a, errno, "Failed to open '%s'",
|
||||||
archive_set_error(a, errno, "Failed to open '%s'",
|
mine->filename);
|
||||||
mine->filename);
|
return (ARCHIVE_FATAL);
|
||||||
return (ARCHIVE_FATAL);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* NULL filename is stdout.
|
|
||||||
*/
|
|
||||||
mine->fd = 1;
|
|
||||||
/* By default, pad archive when writing to stdout. */
|
|
||||||
if (archive_write_get_bytes_in_last_block(a) < 0)
|
|
||||||
archive_write_set_bytes_in_last_block(a, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(mine->fd, &st) != 0) {
|
if (fstat(mine->fd, &st) != 0) {
|
||||||
@ -172,8 +156,7 @@ file_close(struct archive *a, void *client_data)
|
|||||||
struct write_file_data *mine = (struct write_file_data *)client_data;
|
struct write_file_data *mine = (struct write_file_data *)client_data;
|
||||||
|
|
||||||
(void)a; /* UNUSED */
|
(void)a; /* UNUSED */
|
||||||
if (mine->filename[0] != '\0')
|
close(mine->fd);
|
||||||
close(mine->fd);
|
|
||||||
free(mine);
|
free(mine);
|
||||||
return (ARCHIVE_OK);
|
return (ARCHIVE_OK);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user