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

  1. /* $Source: /u/mark/src/pax/RCS/pass.c,v $
  2.  *
  3.  * $Revision: 1.3 $
  4.  *
  5.  * pass.c - handle the pass option of cpio
  6.  *
  7.  * DESCRIPTION
  8.  *
  9.  *    These functions implement the pass options in PAX.  The pass option
  10.  *    copies files from one directory hierarchy to another.
  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:    pass.c,v $
  33.  * Revision 1.3  89/02/12  10:29:51  mark
  34.  * Fixed misspelling of Replstr
  35.  * 
  36.  * Revision 1.2  89/02/12  10:05:09  mark
  37.  * 1.2 release fixes
  38.  * 
  39.  * Revision 1.1  88/12/23  18:02:20  mark
  40.  * Initial revision
  41.  * 
  42.  */
  43.  
  44. #ifndef lint
  45. static char *ident = "$Id: pass.c,v 1.3 89/02/12 10:29:51 mark Exp $";
  46. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  47. #endif /* ! lint */
  48.  
  49.  
  50. /* Headers */
  51.  
  52. #include "pax.h"
  53.  
  54.  
  55. /* pass - copy within the filesystem
  56.  *
  57.  * DESCRIPTION
  58.  *
  59.  *    Pass copies the named files from the current directory hierarchy to
  60.  *    the directory pointed to by dirname.
  61.  *
  62.  * PARAMETERS
  63.  *
  64.  *    char    *dirname    - name of directory to copy named files to.
  65.  *
  66.  */
  67.  
  68. #ifdef __STDC__
  69.     
  70. void pass(char *dirname)  /* Xn */
  71.  
  72. #else
  73.     
  74. void pass(dirname)  /* Xn */
  75. char    *dirname;
  76.  
  77. #endif
  78. {
  79.     char            name[PATH_MAX + 1];
  80.     int             fd;
  81.     Stat            sb;
  82.  
  83. #ifdef DF_TRACE_DEBUG
  84. printf("DF_TRACE_DEBUG: void pass() in pass.c\n");
  85. #endif
  86.     while (name_next(name, &sb) >= 0 && (fd = openin(name, &sb)) >= 0) {
  87.  
  88.     if (rplhead != (Replstr *)NULL) {
  89.         rpl_name(name);
  90.     }
  91.     if (get_disposition("pass", name) || get_newname(name, sizeof(name))) {
  92.         /* skip file... */
  93.         if (fd) {
  94.         close(fd);
  95.         }
  96.         continue;
  97.     } 
  98.  
  99.     if (passitem(name, &sb, fd, dirname)) {
  100.         close(fd);
  101.     }
  102.     if (f_verbose) {
  103.         fprintf(stderr, "%s/%s\n", dirname, name);
  104.     }
  105.     }
  106. }
  107.  
  108.  
  109. /* passitem - copy one file
  110.  *
  111.  * DESCRIPTION
  112.  *
  113.  *    Passitem copies a specific file to the named directory
  114.  *
  115.  * PARAMETERS
  116.  *
  117.  *    char   *from    - the name of the file to open
  118.  *    Stat   *asb    - the stat block associated with the file to copy
  119.  *    int    ifd    - the input file descriptor for the file to copy
  120.  *    char   *dir    - the directory to copy it to
  121.  *
  122.  * RETURNS
  123.  *
  124.  *     Returns given input file descriptor or -1 if an error occurs.
  125.  *
  126.  * ERRORS
  127.  */
  128.  
  129. #ifdef __STDC__
  130.  
  131. int passitem(char *from, Stat *asb, int ifd, char *dir)
  132.  
  133. #else
  134.     
  135. int passitem(from, asb, ifd, dir)
  136. char           *from;
  137. Stat           *asb;
  138. int             ifd;
  139. char           *dir;
  140.  
  141. #endif
  142. {
  143.     int             ofd;
  144. #ifdef _POSIX_SOURCE  /* Xn */
  145.     struct utimbuf  tstamp;  /* Xn */
  146. #else  /* Xn */
  147.     time_t          tstamp[2];
  148. #endif  /* Xn */
  149.     char            to[PATH_MAX + 1];
  150.  
  151. #ifdef DF_TRACE_DEBUG
  152. printf("DF_TRACE_DEBUG: int passitem() in pass.c\n");
  153. #endif
  154.     if (nameopt(strcat(strcat(strcpy(to, dir), "/"), from)) < 0) {
  155.     return (-1);
  156.     }
  157. #if 0
  158.     (void) fprintf(stderr, "pass.c/passitem: from: \"%s\"; asb->sb_nlink: %d\n", from, asb->sb_nlink);
  159. #endif /* Xn 1993-06-21 */
  160. #if 0  /* NIST-PCTS */
  161.     if (asb->sb_nlink > 1) {
  162. #else  /* NIST-PCTS */
  163.     if (asb->sb_nlink > 1 && (asb->sb_mode & S_IFMT) != S_IFDIR) {  /* NIST-PCTS */
  164. #endif  /* NIST-PCTS */
  165.     linkto(to, asb);
  166.     }
  167.     if (f_link && islink(from, asb) == (Link *)NULL) {
  168.     linkto(from, asb);
  169.     }
  170.     if ((ofd = openout(to, asb, islink(to, asb), 1)) < 0) {
  171.     return (-1);
  172.     }
  173.     if (ofd > 0) {
  174.     passdata(from, ifd, to, ofd);
  175.     }
  176. #ifdef _POSIX_SOURCE  /* Xn */
  177.     tstamp.actime = asb->sb_atime;  /* Xn */
  178.     tstamp.modtime = f_mtime ? asb->sb_mtime : time((time_t *) 0);  /* Xn */
  179.     (void) utime(to, &tstamp);  /* Xn */
  180. #else  /* Xn */
  181.     tstamp[0] = asb->sb_atime;
  182.     tstamp[1] = f_mtime ? asb->sb_mtime : time((time_t *) 0);
  183.     (void) utime(to, tstamp);  /* Xn */
  184. #endif  /* Xn */
  185.     return (ifd);
  186. }
  187.