|
|
1.1 ! root 1: /* $Source: /src386/usr/bin/pax/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 ([email protected]) ! 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.1 92/08/28 08:02:22 bin ! 34: * Initial revision ! 35: * ! 36: * Revision 1.1 89/02/14 16:48:05 jep ! 37: * Initial revision ! 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.1 92/08/28 08:02:22 bin Exp Locker: bin $"; ! 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: #if __STDC__ ! 69: ! 70: int pass(char *dirname) ! 71: ! 72: #else ! 73: ! 74: int pass(dirname) ! 75: char *dirname; ! 76: ! 77: #endif ! 78: { ! 79: char name[PATH_MAX + 1]; ! 80: int fd; ! 81: Stat sb; ! 82: ! 83: while (name_next(name, &sb) >= 0 && (fd = openin(name, &sb)) >= 0) { ! 84: ! 85: if (rplhead != (Replstr *)NULL) { ! 86: rpl_name(name); ! 87: } ! 88: if (get_disposition("pass", name) || get_newname(name, sizeof(name))) { ! 89: /* skip file... */ ! 90: if (fd) { ! 91: close(fd); ! 92: } ! 93: continue; ! 94: } ! 95: ! 96: if (passitem(name, &sb, fd, dirname)) { ! 97: close(fd); ! 98: } ! 99: if (f_verbose) { ! 100: fprintf(stderr, "%s/%s\n", dirname, name); ! 101: } ! 102: } ! 103: } ! 104: ! 105: ! 106: /* passitem - copy one file ! 107: * ! 108: * DESCRIPTION ! 109: * ! 110: * Passitem copies a specific file to the named directory ! 111: * ! 112: * PARAMETERS ! 113: * ! 114: * char *from - the name of the file to open ! 115: * Stat *asb - the stat block associated with the file to copy ! 116: * int ifd - the input file descriptor for the file to copy ! 117: * char *dir - the directory to copy it to ! 118: * ! 119: * RETURNS ! 120: * ! 121: * Returns given input file descriptor or -1 if an error occurs. ! 122: * ! 123: * ERRORS ! 124: */ ! 125: ! 126: #if __STDC__ ! 127: ! 128: int passitem(char *from, Stat *asb, int ifd, char *dir) ! 129: ! 130: #else ! 131: ! 132: int passitem(from, asb, ifd, dir) ! 133: char *from; ! 134: Stat *asb; ! 135: int ifd; ! 136: char *dir; ! 137: ! 138: #endif ! 139: { ! 140: int ofd; ! 141: time_t tstamp[2]; ! 142: char to[PATH_MAX + 1]; ! 143: ! 144: if (nameopt(strcat(strcat(strcpy(to, dir), "/"), from)) < 0) { ! 145: return (-1); ! 146: } ! 147: if (asb->sb_nlink > 1) { ! 148: linkto(to, asb); ! 149: } ! 150: if (f_link && islink(from, asb) == (Link *)NULL) { ! 151: linkto(from, asb); ! 152: } ! 153: if ((ofd = openout(to, asb, islink(to, asb), 1)) < 0) { ! 154: return (-1); ! 155: } ! 156: if (ofd > 0) { ! 157: passdata(from, ifd, to, ofd); ! 158: } ! 159: tstamp[0] = asb->sb_atime; ! 160: tstamp[1] = f_mtime ? asb->sb_mtime : time((time_t *) 0); ! 161: if (!f_modified) /* VLAD */ ! 162: utime(to, tstamp); ! 163: return (ifd); ! 164: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.