home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / apps / posix / source / PAX / CPIO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-17  |  5.2 KB  |  236 lines

  1. /* $Source: /u/mark/src/pax/RCS/cpio.c,v $
  2.  *
  3.  * $Revision: 1.2 $
  4.  *
  5.  * cpio.c - Cpio specific functions for archive handling
  6.  *
  7.  * DESCRIPTION
  8.  *
  9.  *    These function provide a cpio conformant interface to the pax
  10.  *    program.
  11.  *
  12.  * AUTHOR
  13.  *
  14.  *     Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
  15.  *
  16.  * Sponsored by The USENIX Association for public distribution. 
  17.  *
  18.  * Copyright (c) 1989 Mark H. Colburn.
  19.  * All rights reserved.
  20.  *
  21.  * Redistribution and use in source and binary forms are permitted
  22.  * provided that the above copyright notice is duplicated in all such 
  23.  * forms and that any documentation, advertising materials, and other 
  24.  * materials related to such distribution and use acknowledge that the 
  25.  * software was developed * by Mark H. Colburn and sponsored by The 
  26.  * USENIX Association. 
  27.  *
  28.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  29.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  30.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  31.  *
  32.  * $Log:    cpio.c,v $
  33.  * Revision 1.2  89/02/12  10:04:13  mark
  34.  * 1.2 release fixes
  35.  * 
  36.  * Revision 1.1  88/12/23  18:02:05  mark
  37.  * Initial revision
  38.  * 
  39.  */
  40.  
  41. #ifndef lint
  42. static char *ident = "$Id: cpio.c,v 1.2 89/02/12 10:04:13 mark Exp $";
  43. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  44. #endif /* ! lint */
  45.  
  46.  
  47. /* Headers */
  48.  
  49. #include "pax.h"
  50.  
  51.  
  52. /* Function Prototypes */
  53.  
  54. #ifdef __STDC__
  55. static void     usage(void);
  56. #else /* !__STDC__ */
  57. static void     usage();
  58. #endif /* __STDC__ */
  59.  
  60.  
  61. /* do_cpio - handle cpio format archives
  62.  *
  63.  * DESCRIPTION
  64.  *
  65.  *    Do_cpio provides a standard CPIO interface to the PAX program.  All
  66.  *    of the standard cpio flags are available, and the behavior of the
  67.  *    program mimics traditonal cpio.
  68.  *
  69.  * PARAMETERS
  70.  *
  71.  *    int    argc    - command line argument count
  72.  *    char    **argv    - pointer to command line arguments
  73.  *
  74.  * RETURNS
  75.  *
  76.  *    Nothing.
  77.  */
  78.  
  79. #ifdef __STDC__
  80.  
  81. void do_cpio(int argc, char **argv)  /* Xn */
  82.  
  83. #else
  84.  
  85. void do_cpio(argc, argv)  /* Xn */
  86. int             argc;
  87. char          **argv;
  88.  
  89. #endif
  90. {
  91.     int             c;
  92.     char           *dirname;
  93.     Stat            st;
  94.  
  95.     /* default input/output file for CPIO is STDIN/STDOUT */
  96.     ar_file = "-";
  97.     names_from_stdin = 1;
  98.  
  99.     /* set up the flags to reflect the default CPIO inteface. */
  100.     blocksize = BLOCKSIZE;
  101.     ar_interface = CPIO;
  102.     ar_format = CPIO;
  103.     msgfile=stderr;
  104.  
  105. #ifdef _POSIX2_SOURCE  /* Xn */
  106. #ifdef DF_TRACE_DEBUG
  107. printf("DF_TRACE_DEBUG: void do_cpio() in cpio.c\n");
  108. #endif
  109.     while ((c = getopt(argc, (const char * const *) argv, "D:Bacdfilmoprtuv")) != EOF) {  /* Xn */
  110. #else  /* Xn */
  111.     while ((c = getopt(argc, argv, "D:Bacdfilmoprtuv")) != EOF) {
  112. #endif  /* Xn */
  113.     switch (c) {
  114.     case 'i':
  115.         f_extract = 1;
  116.         break;
  117.     case 'o':
  118.         f_create = 1;
  119.         break;
  120.     case 'p':
  121.         f_pass = 1;
  122.         dirname = argv[--argc];
  123.  
  124.         /* check to make sure that the argument is a directory */
  125.         if (LSTAT(dirname, &st) < 0) {
  126.         fatal(strerror(errno));  /* Xn */
  127.         }
  128.         if ((st.sb_mode & S_IFMT) != S_IFDIR) {
  129.         fatal("Not a directory");
  130.         }
  131.         break;
  132.     case 'B':
  133.         blocksize = BLOCK;
  134.         break;
  135.     case 'a':
  136.         f_access_time = 1;
  137.         break;
  138.     case 'c':
  139.         break;
  140.     case 'D':
  141.         ar_file = optarg;
  142.         break;
  143.     case 'd':
  144.         f_dir_create = 1;
  145.         break;
  146.     case 'f':
  147.         f_reverse_match = 1;
  148.         break;
  149.     case 'l':
  150.         f_link = 1;
  151.         break;
  152.     case 'm':
  153.         f_mtime = 1;
  154.         break;
  155.     case 'r':
  156.         f_interactive = 1;
  157.         break;
  158.     case 't':
  159.         f_list = 1;
  160.         break;
  161.     case 'u':
  162.         f_unconditional = 1;
  163.         break;
  164.     case 'v':
  165.         f_verbose = 1;
  166.         break;
  167.     default:
  168.         usage();
  169.     }
  170.     }
  171.  
  172.     if (f_create + f_pass + f_extract != 1) {
  173.     usage();
  174.     }
  175.     if (!f_pass) {
  176.     buf_allocate((OFFSET) blocksize);
  177.     }
  178.     if (f_extract) {
  179.     open_archive(AR_READ);    /* Open for reading */
  180.     read_archive();
  181.     } else if (f_create) {
  182.     open_archive(AR_WRITE);
  183.     create_archive();
  184.     } else if (f_pass) {
  185.     pass(dirname);
  186.     }
  187.  
  188.     /* print out the total block count transfered */
  189.     fprintf(stderr, "%ld Blocks\n", ROUNDUP(total, BLOCKSIZE) / BLOCKSIZE);
  190.     
  191. #if 1 && WIN_NT
  192.     if (ppid == (pid_t) 1 && globulation == 0)
  193.     deglobulate();
  194. #endif
  195.     exit(0);
  196.     /* NOTREACHED */
  197. }
  198.  
  199.  
  200. /* usage - print a helpful message and exit
  201.  *
  202.  * DESCRIPTION
  203.  *
  204.  *    Usage prints out the usage message for the CPIO interface and then
  205.  *    exits with a non-zero termination status.  This is used when a user
  206.  *    has provided non-existant or incompatible command line arguments.
  207.  *
  208.  * RETURNS
  209.  *
  210.  *    Returns an exit status of 1 to the parent process.
  211.  *
  212.  */
  213.  
  214. #ifdef __STDC__
  215.  
  216. static void usage(void)
  217.  
  218. #else
  219.  
  220. static void usage()
  221.  
  222. #endif
  223. {
  224. #ifdef DF_TRACE_DEBUG
  225. printf("DF_TRACE_DEBUG: static void usage() in cpio.c\n");
  226. #endif
  227.     fprintf(stderr, "Usage: %s -o[Bacv]\n", myname);
  228.     fprintf(stderr, "       %s -i[Bcdmrtuvf] [pattern...]\n", myname);
  229.     fprintf(stderr, "       %s -p[adlmruv] directory\n", myname);
  230. #if 1 && WIN_NT
  231.     if (ppid == (pid_t) 1 && globulation == 0)
  232.     deglobulate();
  233. #endif
  234.     exit(1);
  235. }
  236.