# HG changeset patch # User Rob Landley # Date 1425442015 21600 # Node ID ceb208839770b54b9d26fb460c364f094e0bd0bd # Parent 848969327d774c219ce436aa85983c1073c03622 Quick cleanup pass on tar. diff -r 848969327d77 -r ceb208839770 toys/pending/tar.c --- a/toys/pending/tar.c Mon Mar 02 20:27:50 2015 -0600 +++ b/toys/pending/tar.c Tue Mar 03 22:06:55 2015 -0600 @@ -32,6 +32,7 @@ X File with names to exclude T File with names to include */ + #define FOR_tar #include "toys.h" @@ -433,7 +434,8 @@ if (pw) u = pw->pw_uid; if (gr) g = gr->gr_gid; } - chown(file_hdr->name, u, g); + if (chown(file_hdr->name, u, g)) + perror_msg("chown %d:%d '%s'", u, g, file_hdr->name);; } if (toys.optflags & FLAG_p) // || !(toys.optflags & FLAG_no_same_permissions)) @@ -745,15 +747,10 @@ void tar_main(void) { struct archive_handler *tar_hdl; - int fd = 0, flags = O_RDONLY; + int fd = 0; struct arg_list *tmp; char **args = toys.optargs; - if (!toys.argv[1]) { - toys.exithelp++; - error_exit(NULL); - } - if (!geteuid()) toys.optflags |= FLAG_p; for (tmp = TT.exc; tmp; tmp = tmp->next) @@ -765,16 +762,16 @@ if (toys.optflags & FLAG_c) { if (!TT.inc) error_exit("empty archive"); - fd = 1, flags = O_WRONLY|O_CREAT|O_TRUNC; + fd = 1; } if ((toys.optflags & FLAG_f) && strcmp(TT.fname, "-")) - fd = xcreate(TT.fname, flags, 0666); + fd = xcreate(TT.fname, fd*(O_WRONLY|O_CREAT|O_TRUNC), 0666); if (toys.optflags & FLAG_C) xchdir(TT.dir); tar_hdl = init_handler(); tar_hdl->src_fd = fd; - if (toys.optflags & FLAG_x || toys.optflags & FLAG_t) { + if ((toys.optflags & FLAG_x) || (toys.optflags & FLAG_t)) { if (toys.optflags & FLAG_O) tar_hdl->extract_handler = extract_to_stdout; if (toys.optflags & FLAG_to_command) { signal(SIGPIPE, SIG_IGN); //will be using pipe between child & parent