home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / pax / 1 / pass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-07  |  3.4 KB  |  158 lines

  1. /* $Source: /u/mark/src/pax/RCS/pass.c,v $
  2.  *
  3.  * $Revision: 1.1 $
  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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  31.  *
  32.  * $Log:    pass.c,v $
  33.  * Revision 1.1  88/12/23  18:02:20  mark
  34.  * Initial revision
  35.  * 
  36.  */
  37.  
  38. #ifndef lint
  39. static char *ident = "$Id: pass.c,v 1.1 88/12/23 18:02:20 mark Rel $";
  40. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  41. #endif /* ! lint */
  42.  
  43.  
  44. /* Headers */
  45.  
  46. #include "pax.h"
  47.  
  48.  
  49. /* pass - copy within the filesystem
  50.  *
  51.  * DESCRIPTION
  52.  *
  53.  *    Pass copies the named files from the current directory hierarchy to
  54.  *    the directory pointed to by dirname.
  55.  *
  56.  * PARAMETERS
  57.  *
  58.  *    char    *dirname    - name of directory to copy named files to.
  59.  *
  60.  */
  61.  
  62. #ifdef __STDC__
  63.     
  64. int pass(char *dirname)
  65.  
  66. #else
  67.     
  68. int pass(dirname)
  69. char    *dirname;
  70.  
  71. #endif
  72. {
  73.     char            name[PATH_MAX + 1];
  74.     int             fd;
  75.     Stat            sb;
  76.  
  77.     while (name_next(name, &sb) >= 0 && (fd = openi(name, &sb)) >= 0) {
  78.  
  79.     if (rplhead != NULL) {
  80.         rpl_name(name);
  81.     }
  82.     if (get_disposition("pass", name) || get_newname(name, sizeof(name))) {
  83.         /* skip file... */
  84.         if (fd) {
  85.         close(fd);
  86.         }
  87.         continue;
  88.     } 
  89.  
  90.     if (passitem(name, &sb, fd, dirname)) {
  91.         close(fd);
  92.     }
  93.     if (f_verbose) {
  94.         fprintf(stderr, "%s/%s\n", dirname, name);
  95.     }
  96.     }
  97. }
  98.  
  99.  
  100. /* passitem - copy one file
  101.  *
  102.  * DESCRIPTION
  103.  *
  104.  *    Passitem copies a specific file to the named directory
  105.  *
  106.  * PARAMETERS
  107.  *
  108.  *    char   *from    - the name of the file to open
  109.  *    Stat   *asb    - the stat block associated with the file to copy
  110.  *    int    ifd    - the input file descriptor for the file to copy
  111.  *    char   *dir    - the directory to copy it to
  112.  *
  113.  * RETURNS
  114.  *
  115.  *     Returns given input file descriptor or -1 if an error occurs.
  116.  *
  117.  * ERRORS
  118.  */
  119.  
  120. #ifdef __STDC__
  121.  
  122. int passitem(char *from, Stat *asb, int ifd, char *dir)
  123.  
  124. #else
  125.     
  126. int passitem(from, asb, ifd, dir)
  127. char           *from;
  128. Stat           *asb;
  129. int             ifd;
  130. char           *dir;
  131.  
  132. #endif
  133. {
  134.     int             ofd;
  135.     time_t          tstamp[2];
  136.     char            to[PATH_MAX + 1];
  137.  
  138.     if (nameopt(strcat(strcat(strcpy(to, dir), "/"), from)) < 0) {
  139.     return (-1);
  140.     }
  141.     if (asb->sb_nlink > 1) {
  142.     if (f_link && islink(from, asb) == (Link *) NULL) {
  143.         linkto(from, asb);
  144.     }
  145.     linkto(to, asb);
  146.     }
  147.     if ((ofd = openo(to, asb, islink(to, asb), 1)) < 0) {
  148.     return (-1);
  149.     }
  150.     if (ofd > 0) {
  151.     passdata(from, ifd, to, ofd);
  152.     }
  153.     tstamp[0] = asb->sb_atime;
  154.     tstamp[1] = f_modification_time ? asb->sb_mtime : time((time_t *) 0);
  155.     utime(to, tstamp);
  156.     return (ifd);
  157. }
  158.