mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-21 18:27:22 +00:00
ar: Avoid overwriting the stdout file stream pointer
This doesn't work with musl, which defines stdout as FILE * const. Instead, explicitly pass the desired output stream to ar_read_archive(). No functional change intended. Reviewed by: emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34064
This commit is contained in:
parent
d045091ea2
commit
41e6398f9b
|
@ -406,7 +406,7 @@ arscp_extract(struct list *list)
|
|||
if (!arscp_target_exist())
|
||||
return;
|
||||
arscp_mlist2argv(list);
|
||||
ar_read_archive(bsdar, 'x');
|
||||
ar_read_archive(bsdar, 'x', stdout);
|
||||
arscp_free_argv();
|
||||
arscp_free_mlist(list);
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ arscp_list(void)
|
|||
bsdar->argv = NULL;
|
||||
/* Always verbose. */
|
||||
bsdar->options |= AR_V;
|
||||
ar_read_archive(bsdar, 't');
|
||||
ar_read_archive(bsdar, 't', stdout);
|
||||
bsdar->options &= ~AR_V;
|
||||
}
|
||||
|
||||
|
@ -433,10 +433,9 @@ arscp_dir(char *archive, struct list *list, char *rlt)
|
|||
FILE *out;
|
||||
|
||||
/* If rlt != NULL, redirect output to it */
|
||||
out = NULL;
|
||||
out = stdout;
|
||||
if (rlt) {
|
||||
out = stdout;
|
||||
if ((stdout = fopen(rlt, "w")) == NULL)
|
||||
if ((out = fopen(rlt, "w")) == NULL)
|
||||
bsdar_errc(bsdar, errno, "fopen %s failed", rlt);
|
||||
}
|
||||
|
||||
|
@ -449,13 +448,12 @@ arscp_dir(char *archive, struct list *list, char *rlt)
|
|||
}
|
||||
if (verbose)
|
||||
bsdar->options |= AR_V;
|
||||
ar_read_archive(bsdar, 't');
|
||||
ar_read_archive(bsdar, 't', out);
|
||||
bsdar->options &= ~AR_V;
|
||||
|
||||
if (rlt) {
|
||||
if (fclose(stdout) == EOF)
|
||||
if (fclose(out) == EOF)
|
||||
bsdar_errc(bsdar, errno, "fclose %s failed", rlt);
|
||||
stdout = out;
|
||||
free(rlt);
|
||||
}
|
||||
free(archive);
|
||||
|
|
|
@ -330,7 +330,7 @@ main(int argc, char **argv)
|
|||
exitcode = ar_write_archive(bsdar, bsdar->mode);
|
||||
break;
|
||||
case 'p': case 't': case 'x':
|
||||
exitcode = ar_read_archive(bsdar, bsdar->mode);
|
||||
exitcode = ar_read_archive(bsdar, bsdar->mode, stdout);
|
||||
break;
|
||||
default:
|
||||
bsdar_usage();
|
||||
|
|
|
@ -115,7 +115,7 @@ struct bsdar {
|
|||
};
|
||||
|
||||
void ar_mode_script(struct bsdar *ar);
|
||||
int ar_read_archive(struct bsdar *ar, int mode);
|
||||
int ar_read_archive(struct bsdar *ar, int mode, FILE *out);
|
||||
int ar_write_archive(struct bsdar *ar, int mode);
|
||||
void bsdar_errc(struct bsdar *, int _code, const char *fmt, ...) __dead2;
|
||||
void bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...);
|
||||
|
|
|
@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
|
|||
* Handle read modes: 'x', 't' and 'p'.
|
||||
*/
|
||||
int
|
||||
ar_read_archive(struct bsdar *bsdar, int mode)
|
||||
ar_read_archive(struct bsdar *bsdar, int mode, FILE *out)
|
||||
{
|
||||
struct archive *a;
|
||||
struct archive_entry *entry;
|
||||
|
@ -123,18 +123,18 @@ ar_read_archive(struct bsdar *bsdar, int mode)
|
|||
size = archive_entry_size(entry);
|
||||
mtime = archive_entry_mtime(entry);
|
||||
(void)strmode(md, buf);
|
||||
(void)fprintf(stdout, "%s %6d/%-6d %8ju ",
|
||||
(void)fprintf(out, "%s %6d/%-6d %8ju ",
|
||||
buf + 1, uid, gid, (uintmax_t)size);
|
||||
tp = localtime(&mtime);
|
||||
(void)strftime(buf, sizeof(buf),
|
||||
"%b %e %H:%M %Y", tp);
|
||||
(void)fprintf(stdout, "%s %s", buf, name);
|
||||
(void)fprintf(out, "%s %s", buf, name);
|
||||
} else
|
||||
(void)fprintf(stdout, "%s", name);
|
||||
(void)fprintf(out, "%s", name);
|
||||
r = archive_read_data_skip(a);
|
||||
if (r == ARCHIVE_WARN || r == ARCHIVE_RETRY ||
|
||||
r == ARCHIVE_FATAL) {
|
||||
(void)fprintf(stdout, "\n");
|
||||
(void)fprintf(out, "\n");
|
||||
bsdar_warnc(bsdar, archive_errno(a), "%s",
|
||||
archive_error_string(a));
|
||||
}
|
||||
|
@ -142,14 +142,14 @@ ar_read_archive(struct bsdar *bsdar, int mode)
|
|||
if (r == ARCHIVE_FATAL)
|
||||
break;
|
||||
|
||||
(void)fprintf(stdout, "\n");
|
||||
(void)fprintf(out, "\n");
|
||||
} else {
|
||||
/* mode == 'x' || mode = 'p' */
|
||||
if (mode == 'p') {
|
||||
if (bsdar->options & AR_V) {
|
||||
(void)fprintf(stdout, "\n<%s>\n\n",
|
||||
(void)fprintf(out, "\n<%s>\n\n",
|
||||
name);
|
||||
fflush(stdout);
|
||||
fflush(out);
|
||||
}
|
||||
r = archive_read_data_into_fd(a, 1);
|
||||
} else {
|
||||
|
@ -172,7 +172,7 @@ ar_read_archive(struct bsdar *bsdar, int mode)
|
|||
}
|
||||
|
||||
if (bsdar->options & AR_V)
|
||||
(void)fprintf(stdout, "x - %s\n", name);
|
||||
(void)fprintf(out, "x - %s\n", name);
|
||||
/* Disallow absolute paths. */
|
||||
if (name[0] == '/') {
|
||||
bsdar_warnc(bsdar, 0,
|
||||
|
|
Loading…
Reference in a new issue