]> git.pld-linux.org Git - packages/cpio.git/blame - cpio-freebsd.patch
patch from FreeBSD with fix FIFO handling (patch merged from rawhide).
[packages/cpio.git] / cpio-freebsd.patch
CommitLineData
696818ea 1--- cpio-2.4.2/copyin.c.fbsd Mon Oct 1 13:50:04 2001
2+++ cpio-2.4.2/copyin.c Mon Oct 1 13:50:05 2001
3@@ -13,6 +13,13 @@
4 #include <stdio.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7+#ifdef HAVE_SYS_PARAM_H
8+#include <sys/param.h>
9+#endif
10+#if ((defined(BSD) && (BSD >= 199306)) || defined(__GLIBC__))
11+#define HAVE_STRFTIME
12+#include <ctype.h>
13+#endif
14 #include "filetypes.h"
15 #include "system.h"
16 #include "cpiohdr.h"
17@@ -28,6 +38,9 @@
18 #ifndef FNM_PATHNAME
19 #include <fnmatch.h>
20 #endif
21+#if defined(HAVE_STRFTIME)
22+#include <langinfo.h>
23+#endif
24
25 /* Debian hack to fix a bug in the --sparse option. This bug has been
26 reported to "bug-gnu-utils@prep.ai.mit.edu". (96/7/10) -BEM */
27@@ -969,13 +982,24 @@
28 break;
29 }
30
31- res = mknod (file_hdr.c_name, file_hdr.c_mode,
32- makedev (file_hdr.c_rdev_maj, file_hdr.c_rdev_min));
33+#ifdef CP_IFIFO
34+ if ((file_hdr.c_mode & CP_IFMT) == CP_IFIFO)
35+ res = mkfifo (file_hdr.c_name, file_hdr.c_mode);
36+ else
37+#endif
38+ res = mknod (file_hdr.c_name, file_hdr.c_mode,
39+ makedev (file_hdr.c_rdev_maj, file_hdr.c_rdev_min));
40 if (res < 0 && create_dir_flag)
41 {
42 create_all_directories (file_hdr.c_name);
43- res = mknod (file_hdr.c_name, file_hdr.c_mode,
44- makedev (file_hdr.c_rdev_maj, file_hdr.c_rdev_min));
45+#ifdef CP_IFIFO
46+ if ((file_hdr.c_mode & CP_IFMT) == CP_IFIFO)
47+ res = mkfifo (file_hdr.c_name, file_hdr.c_mode);
48+ else
49+#endif
50+ res = mknod (file_hdr.c_name, file_hdr.c_mode,
51+ makedev (file_hdr.c_rdev_maj,
52+ file_hdr.c_rdev_min));
53 }
54 if (res < 0)
55 {
56@@ -1087,12 +1111,31 @@
57 char mbuf[11];
58 char tbuf[40];
59 time_t when;
60+ char *ptbuf;
61+#ifdef HAVE_STRFTIME
62+ static int d_first = -1;
63+#endif
64
65 mode_string (file_hdr->c_mode, mbuf);
66 mbuf[10] = '\0';
67
68 /* Get time values ready to print. */
69 when = file_hdr->c_mtime;
70+#ifdef HAVE_STRFTIME
71+#ifdef __FreeBSD__
72+ if (d_first < 0)
73+ d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
74+#else
75+ d_first = 0;
76+#endif
77+ if (current_time - when > 6L * 30L * 24L * 60L * 60L
78+ || current_time - when < 0L)
79+ ptbuf = d_first ? "%e %b %Y" : "%b %e %Y";
80+ else
81+ ptbuf = d_first ? "%e %b %R" : "%b %e %R";
82+ strftime(tbuf, sizeof(tbuf), ptbuf, localtime(&when));
83+ ptbuf = tbuf;
84+#else
85 strcpy (tbuf, ctime (&when));
86 if (current_time - when > 6L * 30L * 24L * 60L * 60L
87 || current_time - when < 0L)
88@@ -1102,8 +1145,10 @@
89 strcpy (tbuf + 11, tbuf + 19);
90 }
91 tbuf[16] = '\0';
92+ ptbuf = tbuf + 4;
93+#endif
94
95- printf ("%s %3u ", mbuf, file_hdr->c_nlink);
96+ printf ("%s %3lu ", mbuf, file_hdr->c_nlink);
97
98 #ifndef __MSDOS__
99 if (numeric_uid)
100@@ -1117,13 +1162,12 @@
101
102 if ((file_hdr->c_mode & CP_IFMT) == CP_IFCHR
103 || (file_hdr->c_mode & CP_IFMT) == CP_IFBLK)
104- printf ("%3u, %3u ", file_hdr->c_rdev_maj,
105- file_hdr->c_rdev_min);
106+ printf ("%3lu, %3lu ", file_hdr->c_rdev_maj, file_hdr->c_rdev_min);
107 else
108 #endif
109 printf ("%8lu ", file_hdr->c_filesize);
110
111- printf ("%s ", tbuf + 4);
112+ printf ("%s ", ptbuf);
113
114 print_name_with_quoting (file_hdr->c_name);
115 if (link_name)
116@@ -1179,6 +1223,9 @@
117 break;
118
119 default:
120+#if ((defined(BSD) && BSD >= 199306) || defined(__GLIBC__))
121+ if (isprint(c))
122+#else
123 if (c > 040 &&
124 #ifdef __MSDOS__
125 c < 0377 && c != 0177
126@@ -1186,6 +1233,7 @@
127 c < 0177
128 #endif
129 )
130+#endif
131 putchar (c);
132 else
133 printf ("\\%03o", (unsigned int) c);
134--- cpio-2.4.2/copyout.c.fbsd Mon Oct 1 13:50:04 2001
135+++ cpio-2.4.2/copyout.c Mon Oct 1 13:51:21 2001
136@@ -36,6 +36,7 @@
137 static void writeout_final_defers();
138 static void writeout_defered_file ();
139 static void check_for_changed_file ();
140+static int check_rdev ();
141
142 /* Write out header FILE_HDR, including the file name, to file
143 descriptor OUT_DES. */
144@@ -294,8 +295,32 @@
145 file_hdr.c_uid = file_stat.st_uid;
146 file_hdr.c_gid = file_stat.st_gid;
147 file_hdr.c_nlink = file_stat.st_nlink;
148- file_hdr.c_rdev_maj = major (file_stat.st_rdev);
149- file_hdr.c_rdev_min = minor (file_stat.st_rdev);
150+
151+ /* The rdev is meaningless except for block and character
152+ special files (POSIX standard) and perhaps fifos and
153+ sockets. Clear it for other types of files so that
154+ check_rdev() doesn't reject files just because stat()
155+ put garbage in st_rdev and so that the output doesn't
156+ depend on the garbage. */
157+ switch (file_hdr.c_mode & CP_IFMT)
158+ {
159+ case CP_IFBLK:
160+ case CP_IFCHR:
161+#ifdef CP_IFIFO
162+ case CP_IFIFO:
163+#endif
164+#ifdef CP_IFSOCK
165+ case CP_IFSOCK:
166+#endif
167+ file_hdr.c_rdev_maj = major (file_stat.st_rdev);
168+ file_hdr.c_rdev_min = minor (file_stat.st_rdev);
169+ break;
170+ default:
171+ file_hdr.c_rdev_maj = 0;
172+ file_hdr.c_rdev_min = 0;
173+ break;
174+ }
175+
176 file_hdr.c_mtime = file_stat.st_mtime;
177 file_hdr.c_filesize = file_stat.st_size;
178 file_hdr.c_chksum = 0;
179@@ -339,6 +364,23 @@
180 continue;
181 }
182
183+ switch (check_rdev (&file_hdr))
184+ {
185+ case 1:
186+ error (0, 0, "%s not dumped: major number would be truncated",
187+ file_hdr.c_name);
188+ continue;
189+ case 2:
190+ error (0, 0, "%s not dumped: minor number would be truncated",
191+ file_hdr.c_name);
192+ continue;
193+ case 4:
194+ error (0, 0, "%s not dumped: device number would be truncated",
195+ file_hdr.c_name);
196+ continue;
197+ }
198+
199+
200 /* Copy the named file to the output. */
201 switch (file_hdr.c_mode & CP_IFMT)
202 {
203@@ -822,6 +864,102 @@
204 return;
205 }
206
207+
208+static int
209+check_rdev (file_hdr)
210+ struct new_cpio_header *file_hdr;
211+{
212+ if (archive_format == arf_newascii || archive_format == arf_crcascii)
213+ {
214+ if ((file_hdr->c_rdev_maj & 0xFFFFFFFF) != file_hdr->c_rdev_maj)
215+ return 1;
216+ if ((file_hdr->c_rdev_min & 0xFFFFFFFF) != file_hdr->c_rdev_min)
217+ return 2;
218+ }
219+ else if (archive_format == arf_oldascii || archive_format == arf_hpoldascii)
220+ {
221+#ifndef __MSDOS__
222+ dev_t rdev;
223+
224+ rdev = makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min);
225+ if (archive_format == arf_oldascii)
226+ {
227+ if ((rdev & 0xFFFF) != rdev)
228+ return 4;
229+ }
230+ else
231+ {
232+ switch (file_hdr->c_mode & CP_IFMT)
233+ {
234+ case CP_IFCHR:
235+ case CP_IFBLK:
236+#ifdef CP_IFSOCK
237+ case CP_IFSOCK:
238+#endif
239+#ifdef CP_IFIFO
240+ case CP_IFIFO:
241+#endif
242+ /* We could handle one more bit if longs are >= 33 bits. */
243+ if ((rdev & 037777777777) != rdev)
244+ return 4;
245+ break;
246+ default:
247+ if ((rdev & 0xFFFF) != rdev)
248+ return 4;
249+ break;
250+ }
251+ }
252+#endif
253+ }
254+ else if (archive_format == arf_tar || archive_format == arf_ustar)
255+ {
256+ /* The major and minor formats are limited to 7 octal digits in ustar
257+ format, and to_oct () adds a gratuitous trailing blank to further
258+ limit the format to 6 octal digits. */
259+ if ((file_hdr->c_rdev_maj & 0777777) != file_hdr->c_rdev_maj)
260+ return 1;
261+ if ((file_hdr->c_rdev_min & 0777777) != file_hdr->c_rdev_min)
262+ return 2;
263+ }
264+ else
265+ {
266+#ifndef __MSDOS__
267+ dev_t rdev;
268+
269+ rdev = makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min);
270+ if (archive_format != arf_hpbinary)
271+ {
272+ if ((rdev & 0xFFFF) != rdev)
273+ return 4;
274+ }
275+ else
276+ {
277+ switch (file_hdr->c_mode & CP_IFMT)
278+ {
279+ case CP_IFCHR:
280+ case CP_IFBLK:
281+#ifdef CP_IFSOCK
282+ case CP_IFSOCK:
283+#endif
284+#ifdef CP_IFIFO
285+ case CP_IFIFO:
286+#endif
287+ if ((rdev & 0xFFFFFFFF) != rdev)
288+ return 4;
289+ file_hdr->c_filesize = rdev;
290+ rdev = makedev (0, 1);
291+ break;
292+ default:
293+ if ((rdev & 0xFFFF) != rdev)
294+ return 4;
295+ break;
296+ }
297+ }
298+#endif
299+ }
300+ return 0;
301+}
302+
303 static void
304 check_for_changed_file (name, header)
305 char *name;
306--- cpio-2.4.2/copypass.c.fbsd Mon Oct 1 13:50:05 2001
307+++ cpio-2.4.2/copypass.c Mon Oct 1 13:50:05 2001
308@@ -311,13 +311,23 @@
309
310 if (link_res < 0)
311 {
312- res = mknod (output_name.ds_string, in_file_stat.st_mode,
313- in_file_stat.st_rdev);
314+#ifdef S_ISFIFO
315+ if (S_ISFIFO (in_file_stat.st_mode))
316+ res = mkfifo (output_name.ds_string, in_file_stat.st_mode);
317+ else
318+#endif
319+ res = mknod (output_name.ds_string, in_file_stat.st_mode,
320+ in_file_stat.st_rdev);
321 if (res < 0 && create_dir_flag)
322 {
323 create_all_directories (output_name.ds_string);
324- res = mknod (output_name.ds_string, in_file_stat.st_mode,
325- in_file_stat.st_rdev);
326+#ifdef S_ISFIFO
327+ if (S_ISFIFO (in_file_stat.st_mode))
328+ res = mkfifo (output_name.ds_string, in_file_stat.st_mode);
329+ else
330+#endif
331+ res = mknod (output_name.ds_string, in_file_stat.st_mode,
332+ in_file_stat.st_rdev);
333 }
334 if (res < 0)
335 {
336--- cpio-2.4.2/main.c.fbsd Mon Oct 1 13:50:05 2001
337+++ cpio-2.4.2/main.c Mon Oct 1 13:50:05 2001
338@@ -19,7 +19,13 @@
339 #include <stdio.h>
340 #include <getopt.h>
341 #include <sys/types.h>
342 #include <sys/stat.h>
343+#ifdef HAVE_SYS_PARAM_H
344+#include <sys/param.h>
345+#endif
346+#if (defined(BSD) && (BSD >= 199306)) || defined(__GLIBC__)
347+#include <locale.h>
348+#endif
349 #include "filetypes.h"
350 #include "system.h"
351 #include "cpiohdr.h"
352@@ -508,13 +516,16 @@
353 bzero (zeros_512, 512);
354 }
355
356-void
357+int
358 main (argc, argv)
359 int argc;
360 char *argv[];
361 {
362 program_name = argv[0];
363- umask (0);
364+
365+#if (defined(BSD) && (BSD >= 199306)) || defined(__GLIBC__)
366+ (void) setlocale (LC_ALL, "");
367+#endif
368
369 #ifdef __TURBOC__
370 _fmode = O_BINARY; /* Put stdin and stdout in binary mode. */
371@@ -525,6 +536,7 @@
372 #endif
373
374 process_args (argc, argv);
375+ umask (0);
376
377 initialize_buffers ();
378
379--- cpio-2.4.2/util.c.fbsd Mon Oct 1 13:50:05 2001
380+++ cpio-2.4.2/util.c Mon Oct 1 13:50:05 2001
381@@ -883,9 +883,9 @@
382 fprintf (tty_out, "%s%d%s", new_media_message_with_number, reel_number,
383 new_media_message_after_number);
384 else if (archive_name)
385- fprintf (tty_out, "Found end of tape. Load next tape and press RETURN. ");
386+ fprintf (tty_out, "Found end of volume. Load next volume and press RETURN. ");
387 else
388- fprintf (tty_out, "Found end of tape. To continue, type device/file name when ready.\n");
389+ fprintf (tty_out, "Found end of volume. To continue, type device/file name when ready.\n");
390
391 fflush (tty_out);
392
This page took 0.122804 seconds and 4 git commands to generate.