home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Networking / wu-ftpd-2.4.2b13-MIHS / util / gzip2cmp.c next >
Encoding:
C/C++ Source or Header  |  1994-04-01  |  1.0 KB  |  57 lines

  1. #include <stdio.h>
  2.  
  3. main (ac, av)
  4.     int ac;
  5.     char **av;
  6. {
  7.     char *zipfile;
  8.     int fd[2];
  9.  
  10.     switch (ac) {
  11.  
  12.     case 2:
  13.         zipfile = av[1];
  14.         break;
  15.  
  16.     case 1:
  17.         zipfile = NULL;
  18.         break;
  19.  
  20.     default:
  21.         fputs (stderr, "usage: gziptocomp [zipfile]");
  22.         exit (1);
  23.     }
  24.  
  25.     if (pipe (fd) < 0) {
  26.         perror ("pipe");
  27.         exit (1);
  28.     }
  29.  
  30.     switch (fork ()) {
  31.  
  32.     default:            /* the father */
  33.         if (dup2 (fd[0], 0) < 0) {
  34.             perror ("parent: dup2");
  35.             exit (1);
  36.         }
  37.         close (fd[1]);
  38.         execlp ("/bin/compress", "compress", NULL);
  39.         perror ("execlp: compress");
  40.         exit (1);
  41.  
  42.     case 0:             /* the son */
  43.         if (dup2 (fd[1], 1) < 0) {
  44.             perror ("child: dup2");
  45.             exit (1);
  46.         }
  47.         close (fd[0]);
  48.         execlp ("/bin/gzip", "gzip", "-cd", zipfile, NULL);
  49.         perror ("execlp: unzip");
  50.         exit (1);
  51.  
  52.     case -1:            /* Murphy's ghost */
  53.         perror ("fork");
  54.         exit (1);
  55.     }
  56. }
  57.