home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / PAX20.ZIP / PASS.C < prev    next >
C/C++ Source or Header  |  1990-11-12  |  4KB  |  168 lines

  1. /* $Source: /u/mark/src/pax/RCS/pass.c,v $
  2.  *
  3.  * $Revision: 2.0.0.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, Open Systems Architects, Inc. (mark@minnetech.mn.org)
  15.  *
  16.  * COPYRIGHT
  17.  *
  18.  *    Copyright (c) 1989 Mark H. Colburn.  All rights reserved.
  19.  *
  20.  *    Redistribution and use in source and binary forms are permitted
  21.  *    provided that the above copyright notice and this paragraph are
  22.  *    duplicated in all such forms and that any documentation,
  23.  *    advertising materials, and other materials related to such
  24.  *    distribution and use acknowledge that the software was developed
  25.  *    by Mark H. Colburn.
  26.  *
  27.  *    THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  28.  *    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  29.  *    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  * $Log:    pass.c,v $
  32.  * Revision 2.0.0.3  89/10/13  02:35:27  mark
  33.  * Beta Test Freeze
  34.  *
  35.  */
  36.  
  37. #ifndef lint
  38. static char        *ident = "$Id: pass.c,v 2.0.0.3 89/10/13 02:35:27 mark Exp Locker: mark $";
  39. static char        *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  40. #endif /* ! lint */
  41.  
  42.  
  43. /* Headers */
  44.  
  45. #include "pax.h"
  46.  
  47.  
  48. /* pass - copy within the filesystem
  49.  *
  50.  * DESCRIPTION
  51.  *
  52.  *    Pass copies the named files from the current directory hierarchy to
  53.  *    the directory pointed to by dirname.
  54.  *
  55.  * PARAMETERS
  56.  *
  57.  *    char    *dirname    - name of directory to copy named files to.
  58.  *
  59.  */
  60.  
  61. #ifdef __STDC__
  62.  
  63. int
  64. pass(char *dirname)
  65.  
  66. #else
  67.  
  68. int
  69. pass(dirname)
  70.     char               *dirname;
  71.  
  72. #endif
  73. {
  74.     char                name[PATH_MAX + 1];
  75.     int                 fd;
  76.     Stat                sb;
  77.  
  78.     DBUG_ENTER("pass");
  79.     while (name_next(name, &sb) >= 0 && (fd = openin(name, &sb)) >= 0) {
  80.  
  81.     if (rplhead != (Replstr *) NULL) {
  82.         rpl_name(name);
  83.     }
  84.     if (get_disposition("pass", name) || get_newname(name, sizeof(name))) {
  85.         /* skip file... */
  86.         if (fd) {
  87.         /* FIXME: do error checking here */
  88.         close(fd);
  89.         }
  90.         continue;
  91.     }
  92.     if (passitem(name, &sb, fd, dirname)) {
  93.         /* FIXME: do error checking here */
  94.         close(fd);
  95.     }
  96.     if (f_verbose) {
  97.         fprintf(stderr, "%s/%s\n", dirname, name);
  98.     }
  99.     }
  100. }
  101.  
  102.  
  103. /* passitem - copy one file
  104.  *
  105.  * DESCRIPTION
  106.  *
  107.  *    Passitem copies a specific file to the named directory
  108.  *
  109.  * PARAMETERS
  110.  *
  111.  *    char   *from    - the name of the file to open
  112.  *    Stat   *asb    - the stat block associated with the file to copy
  113.  *    int    ifd    - the input file descriptor for the file to copy
  114.  *    char   *dir    - the directory to copy it to
  115.  *
  116.  * RETURNS
  117.  *
  118.  *     Returns given input file descriptor or -1 if an error occurs.
  119.  *
  120.  * ERRORS
  121.  */
  122.  
  123. #ifdef __STDC__
  124.  
  125. int
  126. passitem(char *from, Stat * asb, int ifd, char *dir)
  127.  
  128. #else
  129.  
  130. int
  131. passitem(from, asb, ifd, dir)
  132.     char               *from;
  133.     Stat               *asb;
  134.     int                 ifd;
  135.     char               *dir;
  136.  
  137. #endif
  138. {
  139.     int                 ofd;
  140.     time_t              tstamp[2];
  141.     char                to[PATH_MAX + 1];
  142.  
  143.     DBUG_ENTER("passitem");
  144.     strcpy(to, dir);
  145.     strcat(to, "/");
  146.     strcat(to, from);
  147.  
  148.     if (nameopt(to) < 0) {
  149.     DBUG_RETURN(-1);
  150.     }
  151.     if (asb->sb_nlink > 1) {
  152.     linkto(to, asb);
  153.     }
  154.     if (f_link && islink(from, asb) == (Link *) NULL) {
  155.     linkto(from, asb);
  156.     }
  157.     if ((ofd = openout(to, asb, islink(to, asb), 1)) < 0) {
  158.     DBUG_RETURN(-1);
  159.     }
  160.     if (ofd > 0) {
  161.     passdata(from, ifd, to, ofd);
  162.     }
  163.     tstamp[0] = asb->sb_atime;
  164.     tstamp[1] = f_mtime ? asb->sb_mtime : time((time_t *) 0);
  165.     utime(to, tstamp);
  166.     DBUG_RETURN(ifd);
  167. }
  168.