Fixed stdin/stdout paths so things like
tar cvf - /etc/* | gzip -c9 >test.tgz will now work. Fix thanks to Dave Cinege <dcinege@psychosis.com> with some adjustments by me to be mroe GNU-like. -Erik
This commit is contained in:
parent
bf960f58e2
commit
ea824fb937
@ -569,19 +569,20 @@ local int get_method (int in);
|
|||||||
int gunzip_main(int argc, char **argv)
|
int gunzip_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int file_count; /* number of files to precess */
|
int file_count; /* number of files to precess */
|
||||||
int to_stdout = 0;
|
int tostdout = 0;
|
||||||
int fromstdin = 0;
|
int fromstdin = 0;
|
||||||
int result;
|
int result;
|
||||||
int inFileNum;
|
int inFileNum;
|
||||||
int outFileNum;
|
int outFileNum;
|
||||||
int delInputFile = 0;
|
int delInputFile = 0;
|
||||||
|
int force = 0;
|
||||||
struct stat statBuf;
|
struct stat statBuf;
|
||||||
char *delFileName;
|
char *delFileName;
|
||||||
char ifname[MAX_PATH_LEN + 1]; /* input file name */
|
char ifname[MAX_PATH_LEN + 1]; /* input file name */
|
||||||
char ofname[MAX_PATH_LEN + 1]; /* output file name */
|
char ofname[MAX_PATH_LEN + 1]; /* output file name */
|
||||||
|
|
||||||
if (strcmp(applet_name, "zcat") == 0) {
|
if (strcmp(applet_name, "zcat") == 0) {
|
||||||
to_stdout = 1;
|
tostdout = 1;
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fromstdin = 1;
|
fromstdin = 1;
|
||||||
}
|
}
|
||||||
@ -590,23 +591,32 @@ int gunzip_main(int argc, char **argv)
|
|||||||
/* Parse any options */
|
/* Parse any options */
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
while (--argc > 0 && **(++argv) == '-') {
|
||||||
if (*((*argv) + 1) == '\0') {
|
if (*((*argv) + 1) == '\0') {
|
||||||
fromstdin = 1;
|
tostdout = 1;
|
||||||
to_stdout = 1;
|
|
||||||
}
|
}
|
||||||
while (*(++(*argv))) {
|
while (*(++(*argv))) {
|
||||||
switch (**argv) {
|
switch (**argv) {
|
||||||
case 'c':
|
case 'c':
|
||||||
to_stdout = 1;
|
tostdout = 1;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
test_mode = 1;
|
test_mode = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
force = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(gunzip_usage);
|
usage(gunzip_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (argc <= 0)
|
||||||
|
fromstdin = 1;
|
||||||
|
|
||||||
|
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
||||||
|
fatalError( "data not read from terminal. Use -f to force it.\n");
|
||||||
|
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||||
|
fatalError( "data not written to terminal. Use -f to force it.\n");
|
||||||
|
|
||||||
|
|
||||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
@ -644,7 +654,7 @@ int gunzip_main(int argc, char **argv)
|
|||||||
ifile_size = -1L; /* convention for unknown size */
|
ifile_size = -1L; /* convention for unknown size */
|
||||||
} else {
|
} else {
|
||||||
/* Open up the input file */
|
/* Open up the input file */
|
||||||
if (*argv == '\0')
|
if (argc <= 0)
|
||||||
usage(gunzip_usage);
|
usage(gunzip_usage);
|
||||||
if (strlen(*argv) > MAX_PATH_LEN) {
|
if (strlen(*argv) > MAX_PATH_LEN) {
|
||||||
errorMsg(name_too_long);
|
errorMsg(name_too_long);
|
||||||
@ -667,7 +677,7 @@ int gunzip_main(int argc, char **argv)
|
|||||||
ifile_size = statBuf.st_size;
|
ifile_size = statBuf.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (to_stdout == 1) {
|
if (tostdout == 1) {
|
||||||
/* And get to work */
|
/* And get to work */
|
||||||
strcpy(ofname, "stdout");
|
strcpy(ofname, "stdout");
|
||||||
outFileNum = fileno(stdout);
|
outFileNum = fileno(stdout);
|
||||||
@ -741,7 +751,7 @@ int gunzip_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* ========================================================================
|
/* ========================================================================
|
||||||
* Check the magic number of the input file and update ofname if an
|
* Check the magic number of the input file and update ofname if an
|
||||||
* original name was given and to_stdout is not set.
|
* original name was given and tostdout is not set.
|
||||||
* Return the compression method, -1 for error, -2 for warning.
|
* Return the compression method, -1 for error, -2 for warning.
|
||||||
* Set inptr to the offset of the next byte to be processed.
|
* Set inptr to the offset of the next byte to be processed.
|
||||||
* Updates time_stamp if there is one and --no-time is not used.
|
* Updates time_stamp if there is one and --no-time is not used.
|
||||||
|
@ -1801,6 +1801,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
char *delFileName;
|
char *delFileName;
|
||||||
int tostdout = 0;
|
int tostdout = 0;
|
||||||
int fromstdin = 0;
|
int fromstdin = 0;
|
||||||
|
int force = 0;
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
usage(gzip_usage);
|
usage(gzip_usage);
|
||||||
@ -1808,7 +1809,6 @@ int gzip_main(int argc, char **argv)
|
|||||||
/* Parse any options */
|
/* Parse any options */
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
while (--argc > 0 && **(++argv) == '-') {
|
||||||
if (*((*argv) + 1) == '\0') {
|
if (*((*argv) + 1) == '\0') {
|
||||||
fromstdin = 1;
|
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
}
|
}
|
||||||
while (*(++(*argv))) {
|
while (*(++(*argv))) {
|
||||||
@ -1816,11 +1816,25 @@ int gzip_main(int argc, char **argv)
|
|||||||
case 'c':
|
case 'c':
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
force = 1;
|
||||||
|
break;
|
||||||
|
/* Ignore 1-9 (compression level) options */
|
||||||
|
case '1': case '2': case '3': case '4': case '5':
|
||||||
|
case '6': case '7': case '8': case '9':
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(gzip_usage);
|
usage(gzip_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (argc <= 0)
|
||||||
|
fromstdin = 1;
|
||||||
|
|
||||||
|
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
||||||
|
fatalError( "data not read from terminal. Use -f to force it.\n");
|
||||||
|
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||||
|
fatalError( "data not written to terminal. Use -f to force it.\n");
|
||||||
|
|
||||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
@ -1860,7 +1874,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
ifile_size = -1L; /* convention for unknown size */
|
ifile_size = -1L; /* convention for unknown size */
|
||||||
} else {
|
} else {
|
||||||
/* Open up the input file */
|
/* Open up the input file */
|
||||||
if (*argv == '\0')
|
if (argc <= 0)
|
||||||
usage(gzip_usage);
|
usage(gzip_usage);
|
||||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
strncpy(ifname, *argv, MAX_PATH_LEN);
|
||||||
|
|
||||||
|
28
gunzip.c
28
gunzip.c
@ -569,19 +569,20 @@ local int get_method (int in);
|
|||||||
int gunzip_main(int argc, char **argv)
|
int gunzip_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int file_count; /* number of files to precess */
|
int file_count; /* number of files to precess */
|
||||||
int to_stdout = 0;
|
int tostdout = 0;
|
||||||
int fromstdin = 0;
|
int fromstdin = 0;
|
||||||
int result;
|
int result;
|
||||||
int inFileNum;
|
int inFileNum;
|
||||||
int outFileNum;
|
int outFileNum;
|
||||||
int delInputFile = 0;
|
int delInputFile = 0;
|
||||||
|
int force = 0;
|
||||||
struct stat statBuf;
|
struct stat statBuf;
|
||||||
char *delFileName;
|
char *delFileName;
|
||||||
char ifname[MAX_PATH_LEN + 1]; /* input file name */
|
char ifname[MAX_PATH_LEN + 1]; /* input file name */
|
||||||
char ofname[MAX_PATH_LEN + 1]; /* output file name */
|
char ofname[MAX_PATH_LEN + 1]; /* output file name */
|
||||||
|
|
||||||
if (strcmp(applet_name, "zcat") == 0) {
|
if (strcmp(applet_name, "zcat") == 0) {
|
||||||
to_stdout = 1;
|
tostdout = 1;
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fromstdin = 1;
|
fromstdin = 1;
|
||||||
}
|
}
|
||||||
@ -590,23 +591,32 @@ int gunzip_main(int argc, char **argv)
|
|||||||
/* Parse any options */
|
/* Parse any options */
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
while (--argc > 0 && **(++argv) == '-') {
|
||||||
if (*((*argv) + 1) == '\0') {
|
if (*((*argv) + 1) == '\0') {
|
||||||
fromstdin = 1;
|
tostdout = 1;
|
||||||
to_stdout = 1;
|
|
||||||
}
|
}
|
||||||
while (*(++(*argv))) {
|
while (*(++(*argv))) {
|
||||||
switch (**argv) {
|
switch (**argv) {
|
||||||
case 'c':
|
case 'c':
|
||||||
to_stdout = 1;
|
tostdout = 1;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
test_mode = 1;
|
test_mode = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
force = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(gunzip_usage);
|
usage(gunzip_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (argc <= 0)
|
||||||
|
fromstdin = 1;
|
||||||
|
|
||||||
|
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
||||||
|
fatalError( "data not read from terminal. Use -f to force it.\n");
|
||||||
|
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||||
|
fatalError( "data not written to terminal. Use -f to force it.\n");
|
||||||
|
|
||||||
|
|
||||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
@ -644,7 +654,7 @@ int gunzip_main(int argc, char **argv)
|
|||||||
ifile_size = -1L; /* convention for unknown size */
|
ifile_size = -1L; /* convention for unknown size */
|
||||||
} else {
|
} else {
|
||||||
/* Open up the input file */
|
/* Open up the input file */
|
||||||
if (*argv == '\0')
|
if (argc <= 0)
|
||||||
usage(gunzip_usage);
|
usage(gunzip_usage);
|
||||||
if (strlen(*argv) > MAX_PATH_LEN) {
|
if (strlen(*argv) > MAX_PATH_LEN) {
|
||||||
errorMsg(name_too_long);
|
errorMsg(name_too_long);
|
||||||
@ -667,7 +677,7 @@ int gunzip_main(int argc, char **argv)
|
|||||||
ifile_size = statBuf.st_size;
|
ifile_size = statBuf.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (to_stdout == 1) {
|
if (tostdout == 1) {
|
||||||
/* And get to work */
|
/* And get to work */
|
||||||
strcpy(ofname, "stdout");
|
strcpy(ofname, "stdout");
|
||||||
outFileNum = fileno(stdout);
|
outFileNum = fileno(stdout);
|
||||||
@ -741,7 +751,7 @@ int gunzip_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* ========================================================================
|
/* ========================================================================
|
||||||
* Check the magic number of the input file and update ofname if an
|
* Check the magic number of the input file and update ofname if an
|
||||||
* original name was given and to_stdout is not set.
|
* original name was given and tostdout is not set.
|
||||||
* Return the compression method, -1 for error, -2 for warning.
|
* Return the compression method, -1 for error, -2 for warning.
|
||||||
* Set inptr to the offset of the next byte to be processed.
|
* Set inptr to the offset of the next byte to be processed.
|
||||||
* Updates time_stamp if there is one and --no-time is not used.
|
* Updates time_stamp if there is one and --no-time is not used.
|
||||||
|
18
gzip.c
18
gzip.c
@ -1801,6 +1801,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
char *delFileName;
|
char *delFileName;
|
||||||
int tostdout = 0;
|
int tostdout = 0;
|
||||||
int fromstdin = 0;
|
int fromstdin = 0;
|
||||||
|
int force = 0;
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
usage(gzip_usage);
|
usage(gzip_usage);
|
||||||
@ -1808,7 +1809,6 @@ int gzip_main(int argc, char **argv)
|
|||||||
/* Parse any options */
|
/* Parse any options */
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
while (--argc > 0 && **(++argv) == '-') {
|
||||||
if (*((*argv) + 1) == '\0') {
|
if (*((*argv) + 1) == '\0') {
|
||||||
fromstdin = 1;
|
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
}
|
}
|
||||||
while (*(++(*argv))) {
|
while (*(++(*argv))) {
|
||||||
@ -1816,11 +1816,25 @@ int gzip_main(int argc, char **argv)
|
|||||||
case 'c':
|
case 'c':
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
force = 1;
|
||||||
|
break;
|
||||||
|
/* Ignore 1-9 (compression level) options */
|
||||||
|
case '1': case '2': case '3': case '4': case '5':
|
||||||
|
case '6': case '7': case '8': case '9':
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(gzip_usage);
|
usage(gzip_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (argc <= 0)
|
||||||
|
fromstdin = 1;
|
||||||
|
|
||||||
|
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
||||||
|
fatalError( "data not read from terminal. Use -f to force it.\n");
|
||||||
|
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||||
|
fatalError( "data not written to terminal. Use -f to force it.\n");
|
||||||
|
|
||||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
@ -1860,7 +1874,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
ifile_size = -1L; /* convention for unknown size */
|
ifile_size = -1L; /* convention for unknown size */
|
||||||
} else {
|
} else {
|
||||||
/* Open up the input file */
|
/* Open up the input file */
|
||||||
if (*argv == '\0')
|
if (argc <= 0)
|
||||||
usage(gzip_usage);
|
usage(gzip_usage);
|
||||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
strncpy(ifname, *argv, MAX_PATH_LEN);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user