Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.2 KiB

  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. #ifndef lint
  44. static char *ident = "$Id: pass.c,v 1.3 89/02/12 10:29:51 mark Exp $";
  45. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  46. #endif /* ! lint */
  47. /* Headers */
  48. #include "pax.h"
  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. #ifdef __STDC__
  62. void pass(char *dirname) /* Xn */
  63. #else
  64. void pass(dirname) /* Xn */
  65. char *dirname;
  66. #endif
  67. {
  68. char name[PATH_MAX + 1];
  69. int fd;
  70. Stat sb;
  71. #ifdef DF_TRACE_DEBUG
  72. printf("DF_TRACE_DEBUG: void pass() in pass.c\n");
  73. #endif
  74. while (name_next(name, &sb) >= 0 && (fd = openin(name, &sb)) >= 0) {
  75. if (rplhead != (Replstr *)NULL) {
  76. rpl_name(name);
  77. }
  78. if (get_disposition("pass", name) || get_newname(name, sizeof(name))) {
  79. /* skip file... */
  80. if (fd) {
  81. close(fd);
  82. }
  83. continue;
  84. }
  85. if (passitem(name, &sb, fd, dirname)) {
  86. close(fd);
  87. }
  88. if (f_verbose) {
  89. fprintf(stderr, "%s/%s\n", dirname, name);
  90. }
  91. }
  92. }
  93. /* passitem - copy one file
  94. *
  95. * DESCRIPTION
  96. *
  97. * Passitem copies a specific file to the named directory
  98. *
  99. * PARAMETERS
  100. *
  101. * char *from - the name of the file to open
  102. * Stat *asb - the stat block associated with the file to copy
  103. * int ifd - the input file descriptor for the file to copy
  104. * char *dir - the directory to copy it to
  105. *
  106. * RETURNS
  107. *
  108. * Returns given input file descriptor or -1 if an error occurs.
  109. *
  110. * ERRORS
  111. */
  112. #ifdef __STDC__
  113. int passitem(char *from, Stat *asb, int ifd, char *dir)
  114. #else
  115. int passitem(from, asb, ifd, dir)
  116. char *from;
  117. Stat *asb;
  118. int ifd;
  119. char *dir;
  120. #endif
  121. {
  122. int ofd;
  123. #ifdef _POSIX_SOURCE /* Xn */
  124. struct utimbuf tstamp; /* Xn */
  125. #else /* Xn */
  126. time_t tstamp[2];
  127. #endif /* Xn */
  128. char to[PATH_MAX + 1];
  129. #ifdef DF_TRACE_DEBUG
  130. printf("DF_TRACE_DEBUG: int passitem() in pass.c\n");
  131. #endif
  132. if (nameopt(strcat(strcat(strcpy(to, dir), "/"), from)) < 0) {
  133. return (-1);
  134. }
  135. #if 0 /* NIST-PCTS */
  136. if (asb->sb_nlink > 1) {
  137. #else /* NIST-PCTS */
  138. if (asb->sb_nlink > 1 && (asb->sb_mode & S_IFMT) != S_IFDIR) { /* NIST-PCTS */
  139. #endif /* NIST-PCTS */
  140. linkto(to, asb);
  141. }
  142. if (f_link && islink(from, asb) == (Link *)NULL) {
  143. linkto(from, asb);
  144. }
  145. if ((ofd = openout(to, asb, islink(to, asb), 1)) < 0) {
  146. return (-1);
  147. }
  148. if (ofd > 0) {
  149. passdata(from, ifd, to, ofd);
  150. }
  151. #ifdef _POSIX_SOURCE /* Xn */
  152. tstamp.actime = asb->sb_atime; /* Xn */
  153. tstamp.modtime = f_mtime ? asb->sb_mtime : time((time_t *) 0); /* Xn */
  154. (void) utime(to, &tstamp); /* Xn */
  155. #else /* Xn */
  156. tstamp[0] = asb->sb_atime;
  157. tstamp[1] = f_mtime ? asb->sb_mtime : time((time_t *) 0);
  158. (void) utime(to, tstamp); /* Xn */
  159. #endif /* Xn */
  160. return (ifd);
  161. }