summaryrefslogtreecommitdiff
path: root/sys/src/cmd/gzip
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-07-21 17:36:02 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2021-07-21 17:36:02 +0000
commit403149d7de4dbe4cc4b1fd9cb3a164e51dbccc15 (patch)
tree3d17aedc0c1da86ccb20db16a8be28bf4ac97029 /sys/src/cmd/gzip
parent28057f67a04fc9e666cdb698d811c9d26c94f28c (diff)
gzip, bzip2: add -n flag to suppress modification timestamp
Diffstat (limited to 'sys/src/cmd/gzip')
-rw-r--r--sys/src/cmd/gzip/gzip.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/sys/src/cmd/gzip/gzip.c b/sys/src/cmd/gzip/gzip.c
index 2ba8c22c4..b085deda2 100644
--- a/sys/src/cmd/gzip/gzip.c
+++ b/sys/src/cmd/gzip/gzip.c
@@ -4,7 +4,7 @@
#include <flate.h>
#include "gzip.h"
-static int gzipf(char*, int);
+static int gzipf(char*, int, int);
static int gzip(char*, long, int, Biobuf*);
static int crcread(void *fd, void *buf, int n);
static int gzwrite(void *bout, void *buf, int n);
@@ -21,7 +21,7 @@ static int verbose;
void
usage(void)
{
- fprint(2, "usage: gzip [-vcD] [-1-9] [file ...]\n");
+ fprint(2, "usage: gzip [-vcnD] [-1-9] [file ...]\n");
exits("usage");
}
@@ -29,9 +29,11 @@ void
main(int argc, char *argv[])
{
int i, ok, stdout;
+ long mtime;
level = 6;
stdout = 0;
+ mtime = time(nil);
ARGBEGIN{
case 'D':
debug++;
@@ -42,6 +44,9 @@ main(int argc, char *argv[])
case 'c':
stdout = 1;
break;
+ case 'n':
+ mtime = 0;
+ break;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
level = ARGC() - '0';
@@ -58,18 +63,18 @@ main(int argc, char *argv[])
if(argc == 0){
Binit(&bout, 1, OWRITE);
- ok = gzip(nil, time(0), 0, &bout);
+ ok = gzip(nil, mtime, 0, &bout);
Bterm(&bout);
}else{
ok = 1;
for(i = 0; i < argc; i++)
- ok &= gzipf(argv[i], stdout);
+ ok &= gzipf(argv[i], !mtime, stdout);
}
exits(ok ? nil: "errors");
}
static int
-gzipf(char *file, int stdout)
+gzipf(char *file, int nomtime, int stdout)
{
Dir *dir;
char ofile[256], *f, *s;
@@ -120,7 +125,7 @@ gzipf(char *file, int stdout)
fprint(2, "compressing %s to %s\n", file, ofile);
Binit(&bout, ofd, OWRITE);
- ok = gzip(file, dir->mtime, ifd, &bout);
+ ok = gzip(file, nomtime ? 0 : dir->mtime, ifd, &bout);
if(!ok || Bflush(&bout) < 0){
fprint(2, "gzip: error writing %s: %r\n", ofile);
if(!stdout)