aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-11-11 05:46:32 +0000
committerEric Andersen <andersen@codepoet.org>1999-11-11 05:46:32 +0000
commit0dfac6b9cec891b8d523f85d7989d772a1447828 (patch)
tree9bba884d702e0e2497ff990bc3ebce08e4d7a1a3
parentc296b54827d102bd020845da904773d861552788 (diff)
downloadbusybox-w32-0dfac6b9cec891b8d523f85d7989d772a1447828.tar.gz
busybox-w32-0dfac6b9cec891b8d523f85d7989d772a1447828.tar.bz2
busybox-w32-0dfac6b9cec891b8d523f85d7989d772a1447828.zip
Stuff
-rw-r--r--archival/gzip.c91
-rw-r--r--gzip.c91
2 files changed, 126 insertions, 56 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index c36270647..500d6d7e0 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -7,9 +7,9 @@
7#include "internal.h" 7#include "internal.h"
8#ifdef BB_GZIP 8#ifdef BB_GZIP
9 9
10#ifndef BB_ZCAT 10//#ifndef BB_ZCAT
11#error you need zcat to have gzip support! 11//#error you need zcat to have gzip support!
12#endif 12//#endif
13 13
14static const char gzip_usage[] = 14static const char gzip_usage[] =
15 "gzip [OPTION]... [FILE]...\n\n" 15 "gzip [OPTION]... [FILE]...\n\n"
@@ -276,7 +276,7 @@ extern int save_orig_name; /* set if original name must be saved */
276#define WARN(msg) {if (!quiet) fprintf msg ; \ 276#define WARN(msg) {if (!quiet) fprintf msg ; \
277 if (exit_code == OK) exit_code = WARNING;} 277 if (exit_code == OK) exit_code = WARNING;}
278 278
279local void do_exit(int exitcode); 279local void do_exit(int exitcode) __attribute__ ((noreturn));
280 280
281 /* in zip.c: */ 281 /* in zip.c: */
282extern int zip OF((int in, int out)); 282extern int zip OF((int in, int out));
@@ -1762,9 +1762,6 @@ unsigned outcnt; /* bytes in output buffer */
1762 1762
1763/* local functions */ 1763/* local functions */
1764 1764
1765local void treat_stdin OF((void));
1766static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
1767
1768#define strequ(s1, s2) (strcmp((s1),(s2)) == 0) 1765#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
1769 1766
1770/* ======================================================================== */ 1767/* ======================================================================== */
@@ -1774,6 +1771,9 @@ static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
1774int gzip_main(int argc, char ** argv) 1771int gzip_main(int argc, char ** argv)
1775{ 1772{
1776 1773
1774 int inFileNum;
1775 int outFileNum;
1776
1777 /* Parse any options */ 1777 /* Parse any options */
1778 while (--argc > 0 && **(++argv) == '-') { 1778 while (--argc > 0 && **(++argv) == '-') {
1779 while (*(++(*argv))) { 1779 while (*(++(*argv))) {
@@ -1817,32 +1817,67 @@ int gzip_main(int argc, char ** argv)
1817 ALLOC(ush, tab_prefix1, 1L<<(BITS-1)); 1817 ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
1818#endif 1818#endif
1819 1819
1820 /* And get to work */ 1820 if (tostdout==1) {
1821 treat_stdin(); 1821 /* And get to work */
1822 do_exit(exit_code); 1822 SET_BINARY_MODE(fileno(stdout));
1823 return exit_code; /* just to avoid lint warning */ 1823 strcpy(ifname, "stdin");
1824} 1824 strcpy(ofname, "stdout");
1825 inFileNum=fileno(stdin);
1826 outFileNum=fileno(stdout);
1825 1827
1826/* ======================================================================== 1828 /* Get the time stamp on the input file. */
1827 * Compress or decompress stdin 1829 time_stamp = 0; /* time unknown by default */
1828 */
1829local void treat_stdin()
1830{
1831 SET_BINARY_MODE(fileno(stdout));
1832 strcpy(ifname, "stdin");
1833 strcpy(ofname, "stdout");
1834 1830
1835 /* Get the time stamp on the input file. */ 1831 ifile_size = -1L; /* convention for unknown size */
1836 time_stamp = 0; /* time unknown by default */
1837 1832
1838 ifile_size = -1L; /* convention for unknown size */ 1833 clear_bufs(); /* clear input and output buffers */
1834 part_nb = 0;
1839 1835
1840 clear_bufs(); /* clear input and output buffers */ 1836 /* Actually do the compression/decompression. */
1841 part_nb = 0; 1837 zip(inFileNum, outFileNum);
1842 1838
1843 /* Actually do the compression/decompression. Loop over zipped members. 1839 } else {
1844 */ 1840 int result;
1845 if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; 1841 struct stat statBuf;
1842
1843 /* And get to work */
1844 if (*argv=='\0')
1845 usage(gzip_usage);
1846 strncpy(ifname, *argv, MAX_PATH_LEN);
1847 strncpy(ofname, *argv, MAX_PATH_LEN-4);
1848 strcat(ofname, ".gz");
1849
1850 inFileNum=open( ifname, O_RDONLY);
1851 if (inFileNum < 0) {
1852 perror(ifname);
1853 do_exit(WARNING);
1854 }
1855 result = stat(ifname, &statBuf);
1856 if (result < 0) {
1857 perror(ifname);
1858 do_exit(WARNING);
1859 }
1860
1861 outFileNum=open( ofname, O_RDONLY);
1862 if (outFileNum < 0) {
1863 perror(ofname);
1864 do_exit(WARNING);
1865 }
1866 SET_BINARY_MODE(outFileNum);
1867
1868 /* Get the time stamp on the input file. */
1869 time_stamp = statBuf.st_ctime; /* time unknown by default */
1870
1871 ifile_size = statBuf.st_size; /* convention for unknown size */
1872
1873 clear_bufs(); /* clear input and output buffers */
1874 part_nb = 0;
1875
1876 /* Actually do the compression/decompression. */
1877 zip(inFileNum, outFileNum);
1878 }
1879
1880 do_exit(exit_code);
1846} 1881}
1847 1882
1848/* ======================================================================== 1883/* ========================================================================
diff --git a/gzip.c b/gzip.c
index c36270647..500d6d7e0 100644
--- a/gzip.c
+++ b/gzip.c
@@ -7,9 +7,9 @@
7#include "internal.h" 7#include "internal.h"
8#ifdef BB_GZIP 8#ifdef BB_GZIP
9 9
10#ifndef BB_ZCAT 10//#ifndef BB_ZCAT
11#error you need zcat to have gzip support! 11//#error you need zcat to have gzip support!
12#endif 12//#endif
13 13
14static const char gzip_usage[] = 14static const char gzip_usage[] =
15 "gzip [OPTION]... [FILE]...\n\n" 15 "gzip [OPTION]... [FILE]...\n\n"
@@ -276,7 +276,7 @@ extern int save_orig_name; /* set if original name must be saved */
276#define WARN(msg) {if (!quiet) fprintf msg ; \ 276#define WARN(msg) {if (!quiet) fprintf msg ; \
277 if (exit_code == OK) exit_code = WARNING;} 277 if (exit_code == OK) exit_code = WARNING;}
278 278
279local void do_exit(int exitcode); 279local void do_exit(int exitcode) __attribute__ ((noreturn));
280 280
281 /* in zip.c: */ 281 /* in zip.c: */
282extern int zip OF((int in, int out)); 282extern int zip OF((int in, int out));
@@ -1762,9 +1762,6 @@ unsigned outcnt; /* bytes in output buffer */
1762 1762
1763/* local functions */ 1763/* local functions */
1764 1764
1765local void treat_stdin OF((void));
1766static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
1767
1768#define strequ(s1, s2) (strcmp((s1),(s2)) == 0) 1765#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
1769 1766
1770/* ======================================================================== */ 1767/* ======================================================================== */
@@ -1774,6 +1771,9 @@ static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
1774int gzip_main(int argc, char ** argv) 1771int gzip_main(int argc, char ** argv)
1775{ 1772{
1776 1773
1774 int inFileNum;
1775 int outFileNum;
1776
1777 /* Parse any options */ 1777 /* Parse any options */
1778 while (--argc > 0 && **(++argv) == '-') { 1778 while (--argc > 0 && **(++argv) == '-') {
1779 while (*(++(*argv))) { 1779 while (*(++(*argv))) {
@@ -1817,32 +1817,67 @@ int gzip_main(int argc, char ** argv)
1817 ALLOC(ush, tab_prefix1, 1L<<(BITS-1)); 1817 ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
1818#endif 1818#endif
1819 1819
1820 /* And get to work */ 1820 if (tostdout==1) {
1821 treat_stdin(); 1821 /* And get to work */
1822 do_exit(exit_code); 1822 SET_BINARY_MODE(fileno(stdout));
1823 return exit_code; /* just to avoid lint warning */ 1823 strcpy(ifname, "stdin");
1824} 1824 strcpy(ofname, "stdout");
1825 inFileNum=fileno(stdin);
1826 outFileNum=fileno(stdout);
1825 1827
1826/* ======================================================================== 1828 /* Get the time stamp on the input file. */
1827 * Compress or decompress stdin 1829 time_stamp = 0; /* time unknown by default */
1828 */
1829local void treat_stdin()
1830{
1831 SET_BINARY_MODE(fileno(stdout));
1832 strcpy(ifname, "stdin");
1833 strcpy(ofname, "stdout");
1834 1830
1835 /* Get the time stamp on the input file. */ 1831 ifile_size = -1L; /* convention for unknown size */
1836 time_stamp = 0; /* time unknown by default */
1837 1832
1838 ifile_size = -1L; /* convention for unknown size */ 1833 clear_bufs(); /* clear input and output buffers */
1834 part_nb = 0;
1839 1835
1840 clear_bufs(); /* clear input and output buffers */ 1836 /* Actually do the compression/decompression. */
1841 part_nb = 0; 1837 zip(inFileNum, outFileNum);
1842 1838
1843 /* Actually do the compression/decompression. Loop over zipped members. 1839 } else {
1844 */ 1840 int result;
1845 if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; 1841 struct stat statBuf;
1842
1843 /* And get to work */
1844 if (*argv=='\0')
1845 usage(gzip_usage);
1846 strncpy(ifname, *argv, MAX_PATH_LEN);
1847 strncpy(ofname, *argv, MAX_PATH_LEN-4);
1848 strcat(ofname, ".gz");
1849
1850 inFileNum=open( ifname, O_RDONLY);
1851 if (inFileNum < 0) {
1852 perror(ifname);
1853 do_exit(WARNING);
1854 }
1855 result = stat(ifname, &statBuf);
1856 if (result < 0) {
1857 perror(ifname);
1858 do_exit(WARNING);
1859 }
1860
1861 outFileNum=open( ofname, O_RDONLY);
1862 if (outFileNum < 0) {
1863 perror(ofname);
1864 do_exit(WARNING);
1865 }
1866 SET_BINARY_MODE(outFileNum);
1867
1868 /* Get the time stamp on the input file. */
1869 time_stamp = statBuf.st_ctime; /* time unknown by default */
1870
1871 ifile_size = statBuf.st_size; /* convention for unknown size */
1872
1873 clear_bufs(); /* clear input and output buffers */
1874 part_nb = 0;
1875
1876 /* Actually do the compression/decompression. */
1877 zip(inFileNum, outFileNum);
1878 }
1879
1880 do_exit(exit_code);
1846} 1881}
1847 1882
1848/* ======================================================================== 1883/* ========================================================================