X-Git-Url: https://git.saurik.com/apple/file_cmds.git/blobdiff_plain/864a4b6e4495e8bb9744303352b4f19fccc90738..refs/heads/master:/compress/compress.c diff --git a/compress/compress.c b/compress/compress.c index 03311f9..97c70f2 100644 --- a/compress/compress.c +++ b/compress/compress.c @@ -10,10 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,8 +27,9 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static const char copyright[] = +__used static const char copyright[] = "@(#) Copyright (c) 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif @@ -44,11 +41,12 @@ static char sccsid[] = "@(#)compress.c 8.2 (Berkeley) 1/7/94"; #endif #include -__FBSDID("$FreeBSD: src/usr.bin/compress/compress.c,v 1.21 2003/06/14 13:41:31 trhodes Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/compress/compress.c,v 1.23 2010/12/11 08:32:16 joel Exp $"); #include #include #include +#include #include #include @@ -57,6 +55,7 @@ __FBSDID("$FreeBSD: src/usr.bin/compress/compress.c,v 1.21 2003/06/14 13:41:31 t #include #include #include +#include #include "zopen.h" @@ -135,8 +134,9 @@ main(int argc, char *argv[]) exit (eval); } - if (cat == 1 && argc > 1) - errx(1, "the -c option permits only a single file argument"); + /* + * The UNIX standard requires that `uncompress -c` be able to have multiple file parameters given. + */ for (; *argv; ++argv) switch(style) { @@ -205,7 +205,7 @@ compress(const char *in, const char *out, int bits) { size_t nr; struct stat isb, sb; - FILE *ifp, *ofp; + FILE *ifp = NULL, *ofp = NULL; int exists, isreg, oreg; u_char buf[1024]; @@ -216,7 +216,6 @@ compress(const char *in, const char *out, int bits) } isreg = oreg = !exists || S_ISREG(sb.st_mode); - ifp = ofp = NULL; if ((ifp = fopen(in, "r")) == NULL) { cwarn("%s", in); return; @@ -308,7 +307,7 @@ decompress(const char *in, const char *out, int bits) } isreg = oreg = !exists || S_ISREG(sb.st_mode); - ifp = ofp = NULL; + ofp = NULL; if ((ifp = zopen(in, "r", bits)) == NULL) { cwarn("%s", in); return; @@ -384,14 +383,21 @@ err: if (ofp) { void setfile(const char *name, struct stat *fs) { - static struct timeval tv[2]; + struct attrlist ts_req = {}; + struct { + struct timespec mtime; + struct timespec atime; + } set_ts; fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO; - TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); - TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); - if (utimes(name, tv)) - cwarn("utimes: %s", name); + ts_req.bitmapcount = ATTR_BIT_MAP_COUNT; + ts_req.commonattr = ATTR_CMN_MODTIME | ATTR_CMN_ACCTIME; + set_ts.mtime = fs->st_mtimespec; + set_ts.atime = fs->st_atimespec; + + if (setattrlist(name, &ts_req, &set_ts, sizeof(set_ts), 0)) + cwarn("setattrlist: %s", name); /* * Changing the ownership probably won't succeed, unless we're root @@ -415,14 +421,23 @@ int permission(const char *fname) { int ch, first; + char resp[] = {'\0', '\0'}; if (!isatty(fileno(stderr))) return (0); (void)fprintf(stderr, "overwrite %s? ", fname); + + /* Load user specified locale */ + setlocale(LC_MESSAGES, ""); + first = ch = getchar(); while (ch != '\n' && ch != EOF) ch = getchar(); - return (first == 'y'); + + /* only care about first character */ + resp[0] = first; + + return (rpmatch(resp) == 1); } void @@ -433,7 +448,7 @@ usage(int iscompress) "usage: compress [-cfv] [-b bits] [file ...]\n"); else (void)fprintf(stderr, - "usage: uncompress [-cfv] [-b bits] [file ...]\n"); + "usage: uncompress [-cfv] [file ...]\n"); exit(1); }