diff options
author | Khem Raj <raj.khem@gmail.com> | 2016-01-06 12:37:45 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-24 09:40:29 +0000 |
commit | b207868cddcad850078fd061c4150c6ff92acbba (patch) | |
tree | 8c7b5c44312d7d9087c2139ea9ae3e7977a29a0d /meta | |
parent | 1076499cdf6bd4e77b2fd8333c6a92b41545663e (diff) | |
download | poky-b207868cddcad850078fd061c4150c6ff92acbba.tar.gz |
pax: Fix build with musl
There are several BSD specific assumptions
and some GNU specific ones.
(From OE-Core rev: 49e8fc6c4511e026dee176422cf3a7b7558c7cfc)
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
3 files changed, 1330 insertions, 0 deletions
diff --git a/meta/recipes-extended/pax/pax/0001-Fix-build-with-musl.patch b/meta/recipes-extended/pax/pax/0001-Fix-build-with-musl.patch new file mode 100644 index 0000000000..61bf2de5ea --- /dev/null +++ b/meta/recipes-extended/pax/pax/0001-Fix-build-with-musl.patch | |||
@@ -0,0 +1,1287 @@ | |||
1 | From 47c4db8d37248d968fac7ee4a71ca64398890723 Mon Sep 17 00:00:00 2001 | ||
2 | From: Khem Raj <raj.khem@gmail.com> | ||
3 | Date: Wed, 6 Jan 2016 11:57:21 -0800 | ||
4 | Subject: [PATCH] Fix build with musl | ||
5 | |||
6 | Remove BSDisms | ||
7 | Remove fts, and link to libfts thats provided externally | ||
8 | |||
9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
10 | --- | ||
11 | Upstream-Status: Inappropriate[musl specific] | ||
12 | |||
13 | lib/Makefile.am | 4 +- | ||
14 | lib/fts.c | 1025 ------------------------------------------------------- | ||
15 | lib/fts.h | 131 ------- | ||
16 | lib/vis.h | 13 +- | ||
17 | src/Makefile.am | 2 +- | ||
18 | src/extern.h | 2 - | ||
19 | src/file_subs.c | 2 +- | ||
20 | src/tables.c | 2 +- | ||
21 | 8 files changed, 14 insertions(+), 1167 deletions(-) | ||
22 | delete mode 100644 lib/fts.c | ||
23 | delete mode 100644 lib/fts.h | ||
24 | |||
25 | diff --git a/lib/Makefile.am b/lib/Makefile.am | ||
26 | index 56d0859..7f5045a 100644 | ||
27 | --- a/lib/Makefile.am | ||
28 | +++ b/lib/Makefile.am | ||
29 | @@ -8,8 +8,8 @@ AUTOMAKE_OPTIONS = 1.7 gnits | ||
30 | CLEANFILES = *~ | ||
31 | |||
32 | noinst_LIBRARIES = libbsdfunc.a | ||
33 | -noinst_HEADERS = vis.h bsdfunc.h fts.h | ||
34 | +noinst_HEADERS = vis.h bsdfunc.h | ||
35 | |||
36 | AM_CFLAGS = @EXTRA_CFLAGS@ | ||
37 | |||
38 | -libbsdfunc_a_SOURCES = vis.c strlcpy.c strmode.c fts.c | ||
39 | +libbsdfunc_a_SOURCES = vis.c strlcpy.c strmode.c | ||
40 | diff --git a/lib/fts.c b/lib/fts.c | ||
41 | deleted file mode 100644 | ||
42 | index 45e90ca..0000000 | ||
43 | --- a/lib/fts.c | ||
44 | +++ /dev/null | ||
45 | @@ -1,1025 +0,0 @@ | ||
46 | -/*- | ||
47 | - * Copyright (c) 1990, 1993, 1994 | ||
48 | - * The Regents of the University of California. All rights reserved. | ||
49 | - * | ||
50 | - * Redistribution and use in source and binary forms, with or without | ||
51 | - * modification, are permitted provided that the following conditions | ||
52 | - * are met: | ||
53 | - * 1. Redistributions of source code must retain the above copyright | ||
54 | - * notice, this list of conditions and the following disclaimer. | ||
55 | - * 2. Redistributions in binary form must reproduce the above copyright | ||
56 | - * notice, this list of conditions and the following disclaimer in the | ||
57 | - * documentation and/or other materials provided with the distribution. | ||
58 | - * 4. Neither the name of the University nor the names of its contributors | ||
59 | - * may be used to endorse or promote products derived from this software | ||
60 | - * without specific prior written permission. | ||
61 | - * | ||
62 | - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
63 | - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
64 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
65 | - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
66 | - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
67 | - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
68 | - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
69 | - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
70 | - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
71 | - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
72 | - * SUCH DAMAGE. | ||
73 | - */ | ||
74 | - | ||
75 | -#ifdef HAVE_CONFIG_H | ||
76 | -#include <config.h> | ||
77 | -#endif | ||
78 | - | ||
79 | -#include <sys/stat.h> | ||
80 | -#include <fcntl.h> | ||
81 | -#include <dirent.h> | ||
82 | -#include <errno.h> | ||
83 | -#include <fts.h> | ||
84 | -#include <stdlib.h> | ||
85 | -#include <string.h> | ||
86 | -#include <unistd.h> | ||
87 | - | ||
88 | -/* Largest alignment size needed, minus one. | ||
89 | - Usually long double is the worst case. */ | ||
90 | -#ifndef ALIGNBYTES | ||
91 | -#define ALIGNBYTES (__alignof__ (long double) - 1) | ||
92 | -#endif | ||
93 | -/* Align P to that size. */ | ||
94 | -#ifndef ALIGN | ||
95 | -#define ALIGN(p) (((unsigned long int) (p) + ALIGNBYTES) & ~ALIGNBYTES) | ||
96 | -#endif | ||
97 | - | ||
98 | - | ||
99 | -static FTSENT *fts_alloc (FTS *, const char *, int); | ||
100 | -static FTSENT *fts_build (FTS *, int); | ||
101 | -static void fts_lfree (FTSENT *); | ||
102 | -static void fts_load (FTS *, FTSENT *); | ||
103 | -static size_t fts_maxarglen (char * const *); | ||
104 | -static void fts_padjust (FTS *, FTSENT *); | ||
105 | -static int fts_palloc (FTS *, size_t); | ||
106 | -static FTSENT *fts_sort (FTS *, FTSENT *, int); | ||
107 | -static u_short fts_stat (FTS *, FTSENT *, int); | ||
108 | -static int fts_safe_changedir (FTS *, FTSENT *, int, const char *); | ||
109 | - | ||
110 | -#ifndef MAX | ||
111 | -#define MAX(a, b) (a > b ? a : b) | ||
112 | -#endif | ||
113 | - | ||
114 | -#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) | ||
115 | - | ||
116 | -#define CLR(opt) (sp->fts_options &= ~(opt)) | ||
117 | -#define ISSET(opt) (sp->fts_options & (opt)) | ||
118 | -#define SET(opt) (sp->fts_options |= (opt)) | ||
119 | - | ||
120 | -#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) | ||
121 | - | ||
122 | -#define BREAD 3 /* fts_read */ | ||
123 | - | ||
124 | -FTS * | ||
125 | -fts_open(argv, koptions, compar) | ||
126 | - char * const *argv; | ||
127 | - register int koptions; | ||
128 | - int (*compar) (const FTSENT **, const FTSENT **); | ||
129 | -{ | ||
130 | - register FTS *sp; | ||
131 | - register FTSENT *p, *root; | ||
132 | - register int nitems; | ||
133 | - FTSENT *parent, *tmp; | ||
134 | - int len; | ||
135 | - | ||
136 | -tmp = NULL; /* stop compiler whinging */ | ||
137 | - /* Options check. */ | ||
138 | - if (koptions & ~FTS_OPTIONMASK) { | ||
139 | - errno = EINVAL; | ||
140 | - return (NULL); | ||
141 | - } | ||
142 | - | ||
143 | - /* Allocate/initialize the stream */ | ||
144 | - if ((sp = malloc((u_int)sizeof(FTS))) == NULL) | ||
145 | - return (NULL); | ||
146 | - memset(sp, 0, sizeof(FTS)); | ||
147 | - sp->fts_compar = (int (*) (const void *, const void *)) compar; | ||
148 | - sp->fts_options = koptions; | ||
149 | - | ||
150 | - /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ | ||
151 | - if (ISSET(FTS_LOGICAL)) | ||
152 | - SET(FTS_NOCHDIR); | ||
153 | - | ||
154 | - /* | ||
155 | - * Start out with 1K of path space, and enough, in any case, | ||
156 | - * to hold the user's paths. | ||
157 | - */ | ||
158 | -#ifndef MAXPATHLEN | ||
159 | -#define MAXPATHLEN 1024 | ||
160 | -#endif | ||
161 | - if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) | ||
162 | - goto mem1; | ||
163 | - | ||
164 | - /* Allocate/initialize root's parent. */ | ||
165 | - if ((parent = fts_alloc(sp, "", 0)) == NULL) | ||
166 | - goto mem2; | ||
167 | - parent->fts_level = FTS_ROOTPARENTLEVEL; | ||
168 | - | ||
169 | - /* Allocate/initialize root(s). */ | ||
170 | - for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) { | ||
171 | - /* Don't allow zero-length paths. */ | ||
172 | - if ((len = strlen(*argv)) == 0) { | ||
173 | - errno = ENOENT; | ||
174 | - goto mem3; | ||
175 | - } | ||
176 | - | ||
177 | - p = fts_alloc(sp, *argv, len); | ||
178 | - p->fts_level = FTS_ROOTLEVEL; | ||
179 | - p->fts_parent = parent; | ||
180 | - p->fts_accpath = p->fts_name; | ||
181 | - p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); | ||
182 | - | ||
183 | - /* Command-line "." and ".." are real directories. */ | ||
184 | - if (p->fts_info == FTS_DOT) | ||
185 | - p->fts_info = FTS_D; | ||
186 | - | ||
187 | - /* | ||
188 | - * If comparison routine supplied, traverse in sorted | ||
189 | - * order; otherwise traverse in the order specified. | ||
190 | - */ | ||
191 | - if (compar) { | ||
192 | - p->fts_link = root; | ||
193 | - root = p; | ||
194 | - } else { | ||
195 | - p->fts_link = NULL; | ||
196 | - if (root == NULL) | ||
197 | - tmp = root = p; | ||
198 | - else { | ||
199 | - tmp->fts_link = p; | ||
200 | - tmp = p; | ||
201 | - } | ||
202 | - } | ||
203 | - } | ||
204 | - if (compar && nitems > 1) | ||
205 | - root = fts_sort(sp, root, nitems); | ||
206 | - | ||
207 | - /* | ||
208 | - * Allocate a dummy pointer and make fts_read think that we've just | ||
209 | - * finished the node before the root(s); set p->fts_info to FTS_INIT | ||
210 | - * so that everything about the "current" node is ignored. | ||
211 | - */ | ||
212 | - if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) | ||
213 | - goto mem3; | ||
214 | - sp->fts_cur->fts_link = root; | ||
215 | - sp->fts_cur->fts_info = FTS_INIT; | ||
216 | - | ||
217 | - /* | ||
218 | - * If using chdir(2), grab a file descriptor pointing to dot to ensure | ||
219 | - * that we can get back here; this could be avoided for some paths, | ||
220 | - * but almost certainly not worth the effort. Slashes, symbolic links, | ||
221 | - * and ".." are all fairly nasty problems. Note, if we can't get the | ||
222 | - * descriptor we run anyway, just more slowly. | ||
223 | - */ | ||
224 | - if (!ISSET(FTS_NOCHDIR) | ||
225 | - && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0) | ||
226 | - SET(FTS_NOCHDIR); | ||
227 | - | ||
228 | - return (sp); | ||
229 | - | ||
230 | -mem3: fts_lfree(root); | ||
231 | - free(parent); | ||
232 | -mem2: free(sp->fts_path); | ||
233 | -mem1: free(sp); | ||
234 | - return (NULL); | ||
235 | -} | ||
236 | - | ||
237 | -static void | ||
238 | -fts_load(sp, p) | ||
239 | - FTS *sp; | ||
240 | - register FTSENT *p; | ||
241 | -{ | ||
242 | - register int len; | ||
243 | - register char *cp; | ||
244 | - | ||
245 | - /* | ||
246 | - * Load the stream structure for the next traversal. Since we don't | ||
247 | - * actually enter the directory until after the preorder visit, set | ||
248 | - * the fts_accpath field specially so the chdir gets done to the right | ||
249 | - * place and the user can access the first node. From fts_open it's | ||
250 | - * known that the path will fit. | ||
251 | - */ | ||
252 | - len = p->fts_pathlen = p->fts_namelen; | ||
253 | - memmove(sp->fts_path, p->fts_name, len + 1); | ||
254 | - if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { | ||
255 | - len = strlen(++cp); | ||
256 | - memmove(p->fts_name, cp, len + 1); | ||
257 | - p->fts_namelen = len; | ||
258 | - } | ||
259 | - p->fts_accpath = p->fts_path = sp->fts_path; | ||
260 | - sp->fts_dev = p->fts_dev; | ||
261 | -} | ||
262 | - | ||
263 | -int | ||
264 | -fts_close(sp) | ||
265 | - FTS *sp; | ||
266 | -{ | ||
267 | - register FTSENT *freep, *p; | ||
268 | - int saved_errno; | ||
269 | - | ||
270 | - /* | ||
271 | - * This still works if we haven't read anything -- the dummy structure | ||
272 | - * points to the root list, so we step through to the end of the root | ||
273 | - * list which has a valid parent pointer. | ||
274 | - */ | ||
275 | - if (sp->fts_cur) { | ||
276 | - for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { | ||
277 | - freep = p; | ||
278 | - p = p->fts_link != NULL ? p->fts_link : p->fts_parent; | ||
279 | - free(freep); | ||
280 | - } | ||
281 | - free(p); | ||
282 | - } | ||
283 | - | ||
284 | - /* Free up child linked list, sort array, path buffer. */ | ||
285 | - if (sp->fts_child) | ||
286 | - fts_lfree(sp->fts_child); | ||
287 | - if (sp->fts_array) | ||
288 | - free(sp->fts_array); | ||
289 | - free(sp->fts_path); | ||
290 | - | ||
291 | - /* Return to original directory, save errno if necessary. */ | ||
292 | - if (!ISSET(FTS_NOCHDIR)) { | ||
293 | - saved_errno = fchdir(sp->fts_rfd) ? errno : 0; | ||
294 | - (void)close(sp->fts_rfd); | ||
295 | - | ||
296 | - /* Set errno and return. */ | ||
297 | - if (saved_errno != 0) { | ||
298 | - /* Free up the stream pointer. */ | ||
299 | - free(sp); | ||
300 | - errno = saved_errno; | ||
301 | - return (-1); | ||
302 | - } | ||
303 | - } | ||
304 | - | ||
305 | - /* Free up the stream pointer. */ | ||
306 | - free(sp); | ||
307 | - return (0); | ||
308 | -} | ||
309 | - | ||
310 | -/* | ||
311 | - * Special case of "/" at the end of the path so that slashes aren't | ||
312 | - * appended which would cause paths to be written as "....//foo". | ||
313 | - */ | ||
314 | -#define NAPPEND(p) \ | ||
315 | - (p->fts_path[p->fts_pathlen - 1] == '/' \ | ||
316 | - ? p->fts_pathlen - 1 : p->fts_pathlen) | ||
317 | - | ||
318 | -FTSENT * | ||
319 | -fts_read(sp) | ||
320 | - register FTS *sp; | ||
321 | -{ | ||
322 | - register FTSENT *p, *tmp; | ||
323 | - register int instr; | ||
324 | - register char *t; | ||
325 | - int saved_errno; | ||
326 | - | ||
327 | - /* If finished or unrecoverable error, return NULL. */ | ||
328 | - if (sp->fts_cur == NULL || ISSET(FTS_STOP)) | ||
329 | - return (NULL); | ||
330 | - | ||
331 | - /* Set current node pointer. */ | ||
332 | - p = sp->fts_cur; | ||
333 | - | ||
334 | - /* Save and zero out user instructions. */ | ||
335 | - instr = p->fts_instr; | ||
336 | - p->fts_instr = FTS_NOINSTR; | ||
337 | - | ||
338 | - /* Any type of file may be re-visited; re-stat and re-turn. */ | ||
339 | - if (instr == FTS_AGAIN) { | ||
340 | - p->fts_info = fts_stat(sp, p, 0); | ||
341 | - return (p); | ||
342 | - } | ||
343 | - | ||
344 | - /* | ||
345 | - * Following a symlink -- SLNONE test allows application to see | ||
346 | - * SLNONE and recover. If indirecting through a symlink, have | ||
347 | - * keep a pointer to current location. If unable to get that | ||
348 | - * pointer, follow fails. | ||
349 | - */ | ||
350 | - if (instr == FTS_FOLLOW && | ||
351 | - (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { | ||
352 | - p->fts_info = fts_stat(sp, p, 1); | ||
353 | - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { | ||
354 | - if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { | ||
355 | - p->fts_errno = errno; | ||
356 | - p->fts_info = FTS_ERR; | ||
357 | - } else | ||
358 | - p->fts_flags |= FTS_SYMFOLLOW; | ||
359 | - } | ||
360 | - return (p); | ||
361 | - } | ||
362 | - | ||
363 | - /* Directory in pre-order. */ | ||
364 | - if (p->fts_info == FTS_D) { | ||
365 | - /* If skipped or crossed mount point, do post-order visit. */ | ||
366 | - if (instr == FTS_SKIP || | ||
367 | - (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { | ||
368 | - if (p->fts_flags & FTS_SYMFOLLOW) | ||
369 | - (void)close(p->fts_symfd); | ||
370 | - if (sp->fts_child) { | ||
371 | - fts_lfree(sp->fts_child); | ||
372 | - sp->fts_child = NULL; | ||
373 | - } | ||
374 | - p->fts_info = FTS_DP; | ||
375 | - return (p); | ||
376 | - } | ||
377 | - | ||
378 | - /* Rebuild if only read the names and now traversing. */ | ||
379 | - if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) { | ||
380 | - CLR(FTS_NAMEONLY); | ||
381 | - fts_lfree(sp->fts_child); | ||
382 | - sp->fts_child = NULL; | ||
383 | - } | ||
384 | - | ||
385 | - /* | ||
386 | - * Cd to the subdirectory. | ||
387 | - * | ||
388 | - * If have already read and now fail to chdir, whack the list | ||
389 | - * to make the names come out right, and set the parent errno | ||
390 | - * so the application will eventually get an error condition. | ||
391 | - * Set the FTS_DONTCHDIR flag so that when we logically change | ||
392 | - * directories back to the parent we don't do a chdir. | ||
393 | - * | ||
394 | - * If haven't read do so. If the read fails, fts_build sets | ||
395 | - * FTS_STOP or the fts_info field of the node. | ||
396 | - */ | ||
397 | - if (sp->fts_child != NULL) { | ||
398 | - if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { | ||
399 | - p->fts_errno = errno; | ||
400 | - p->fts_flags |= FTS_DONTCHDIR; | ||
401 | - for (p = sp->fts_child; p != NULL; | ||
402 | - p = p->fts_link) | ||
403 | - p->fts_accpath = | ||
404 | - p->fts_parent->fts_accpath; | ||
405 | - } | ||
406 | - } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { | ||
407 | - if (ISSET(FTS_STOP)) | ||
408 | - return (NULL); | ||
409 | - return (p); | ||
410 | - } | ||
411 | - p = sp->fts_child; | ||
412 | - sp->fts_child = NULL; | ||
413 | - goto name; | ||
414 | - } | ||
415 | - | ||
416 | - /* Move to the next node on this level. */ | ||
417 | -next: tmp = p; | ||
418 | - if ((p = p->fts_link) != NULL) { | ||
419 | - free(tmp); | ||
420 | - | ||
421 | - /* | ||
422 | - * If reached the top, return to the original directory (or | ||
423 | - * the root of the tree), and load the paths for the next root. | ||
424 | - */ | ||
425 | - if (p->fts_level == FTS_ROOTLEVEL) { | ||
426 | - if (FCHDIR(sp, sp->fts_rfd)) { | ||
427 | - SET(FTS_STOP); | ||
428 | - return (NULL); | ||
429 | - } | ||
430 | - fts_load(sp, p); | ||
431 | - return (sp->fts_cur = p); | ||
432 | - } | ||
433 | - | ||
434 | - /* | ||
435 | - * User may have called fts_set on the node. If skipped, | ||
436 | - * ignore. If followed, get a file descriptor so we can | ||
437 | - * get back if necessary. | ||
438 | - */ | ||
439 | - if (p->fts_instr == FTS_SKIP) | ||
440 | - goto next; | ||
441 | - if (p->fts_instr == FTS_FOLLOW) { | ||
442 | - p->fts_info = fts_stat(sp, p, 1); | ||
443 | - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { | ||
444 | - if ((p->fts_symfd = | ||
445 | - open(".", O_RDONLY, 0)) < 0) { | ||
446 | - p->fts_errno = errno; | ||
447 | - p->fts_info = FTS_ERR; | ||
448 | - } else | ||
449 | - p->fts_flags |= FTS_SYMFOLLOW; | ||
450 | - } | ||
451 | - p->fts_instr = FTS_NOINSTR; | ||
452 | - } | ||
453 | - | ||
454 | -name: t = sp->fts_path + NAPPEND(p->fts_parent); | ||
455 | - *t++ = '/'; | ||
456 | - memmove(t, p->fts_name, p->fts_namelen + 1); | ||
457 | - return (sp->fts_cur = p); | ||
458 | - } | ||
459 | - | ||
460 | - /* Move up to the parent node. */ | ||
461 | - p = tmp->fts_parent; | ||
462 | - free(tmp); | ||
463 | - | ||
464 | - if (p->fts_level == FTS_ROOTPARENTLEVEL) { | ||
465 | - /* | ||
466 | - * Done; free everything up and set errno to 0 so the user | ||
467 | - * can distinguish between error and EOF. | ||
468 | - */ | ||
469 | - free(p); | ||
470 | - errno = 0; | ||
471 | - return (sp->fts_cur = NULL); | ||
472 | - } | ||
473 | - | ||
474 | - /* NUL terminate the pathname. */ | ||
475 | - sp->fts_path[p->fts_pathlen] = '\0'; | ||
476 | - | ||
477 | - /* | ||
478 | - * Return to the parent directory. If at a root node or came through | ||
479 | - * a symlink, go back through the file descriptor. Otherwise, cd up | ||
480 | - * one directory. | ||
481 | - */ | ||
482 | - if (p->fts_level == FTS_ROOTLEVEL) { | ||
483 | - if (FCHDIR(sp, sp->fts_rfd)) { | ||
484 | - SET(FTS_STOP); | ||
485 | - return (NULL); | ||
486 | - } | ||
487 | - } else if (p->fts_flags & FTS_SYMFOLLOW) { | ||
488 | - if (FCHDIR(sp, p->fts_symfd)) { | ||
489 | - saved_errno = errno; | ||
490 | - (void)close(p->fts_symfd); | ||
491 | - errno = saved_errno; | ||
492 | - SET(FTS_STOP); | ||
493 | - return (NULL); | ||
494 | - } | ||
495 | - (void)close(p->fts_symfd); | ||
496 | - } else if (!(p->fts_flags & FTS_DONTCHDIR) && | ||
497 | - fts_safe_changedir(sp, p->fts_parent, -1, "..")) { | ||
498 | - SET(FTS_STOP); | ||
499 | - return (NULL); | ||
500 | - } | ||
501 | - p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; | ||
502 | - return (sp->fts_cur = p); | ||
503 | -} | ||
504 | - | ||
505 | -/* | ||
506 | - * Fts_set takes the stream as an argument although it's not used in this | ||
507 | - * implementation; it would be necessary if anyone wanted to add global | ||
508 | - * semantics to fts using fts_set. An error return is allowed for similar | ||
509 | - * reasons. | ||
510 | - */ | ||
511 | -/* ARGSUSED */ | ||
512 | -int | ||
513 | -fts_set(sp, p, instr) | ||
514 | - FTS __attribute__((__unused__)) *sp; | ||
515 | - FTSENT *p; | ||
516 | - int instr; | ||
517 | -{ | ||
518 | -sp = NULL; /* stop compiler whinging */ | ||
519 | - if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW && | ||
520 | - instr != FTS_NOINSTR && instr != FTS_SKIP) { | ||
521 | - errno = EINVAL; | ||
522 | - return (1); | ||
523 | - } | ||
524 | - p->fts_instr = instr; | ||
525 | - return (0); | ||
526 | -} | ||
527 | - | ||
528 | -/* | ||
529 | - * This is the tricky part -- do not casually change *anything* in here. The | ||
530 | - * idea is to build the linked list of entries that are used by fts_children | ||
531 | - * and fts_read. There are lots of special cases. | ||
532 | - * | ||
533 | - * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is | ||
534 | - * set and it's a physical walk (so that symbolic links can't be directories), | ||
535 | - * we can do things quickly. First, if it's a 4.4BSD file system, the type | ||
536 | - * of the file is in the directory entry. Otherwise, we assume that the number | ||
537 | - * of subdirectories in a node is equal to the number of links to the parent. | ||
538 | - * The former skips all stat calls. The latter skips stat calls in any leaf | ||
539 | - * directories and for any files after the subdirectories in the directory have | ||
540 | - * been found, cutting the stat calls by about 2/3. | ||
541 | - */ | ||
542 | -static FTSENT * | ||
543 | -fts_build(sp, type) | ||
544 | - register FTS *sp; | ||
545 | - int type; | ||
546 | -{ | ||
547 | - register struct dirent *dp; | ||
548 | - register FTSENT *p, *head; | ||
549 | - register int nitems; | ||
550 | - FTSENT *cur, *tail; | ||
551 | - DIR *dirp; | ||
552 | - void *oldaddr; | ||
553 | - int cderrno, descend, len, level, nlinks, saved_errno, | ||
554 | - nostat, doadjust; | ||
555 | - size_t maxlen; | ||
556 | - char *cp; | ||
557 | - | ||
558 | - /* Set current node pointer. */ | ||
559 | - cur = sp->fts_cur; | ||
560 | - | ||
561 | - /* | ||
562 | - * Open the directory for reading. If this fails, we're done. | ||
563 | - * If being called from fts_read, set the fts_info field. | ||
564 | - */ | ||
565 | - if ((dirp = opendir(cur->fts_accpath)) == NULL) { | ||
566 | - if (type == BREAD) { | ||
567 | - cur->fts_info = FTS_DNR; | ||
568 | - cur->fts_errno = errno; | ||
569 | - } | ||
570 | - return (NULL); | ||
571 | - } | ||
572 | - | ||
573 | - /* | ||
574 | - * Nlinks is the number of possible entries of type directory in the | ||
575 | - * directory if we're cheating on stat calls, 0 if we're not doing | ||
576 | - * any stat calls at all, -1 if we're doing stats on everything. | ||
577 | - */ | ||
578 | - nlinks = -1; | ||
579 | - nostat = 0; | ||
580 | - | ||
581 | - /* | ||
582 | - * If we're going to need to stat anything or we want to descend | ||
583 | - * and stay in the directory, chdir. If this fails we keep going, | ||
584 | - * but set a flag so we don't chdir after the post-order visit. | ||
585 | - * We won't be able to stat anything, but we can still return the | ||
586 | - * names themselves. Note, that since fts_read won't be able to | ||
587 | - * chdir into the directory, it will have to return different path | ||
588 | - * names than before, i.e. "a/b" instead of "b". Since the node | ||
589 | - * has already been visited in pre-order, have to wait until the | ||
590 | - * post-order visit to return the error. There is a special case | ||
591 | - * here, if there was nothing to stat then it's not an error to | ||
592 | - * not be able to stat. This is all fairly nasty. If a program | ||
593 | - * needed sorted entries or stat information, they had better be | ||
594 | - * checking FTS_NS on the returned nodes. | ||
595 | - */ | ||
596 | - cderrno = 0; | ||
597 | - if (nlinks || type == BREAD) { | ||
598 | - if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { | ||
599 | - if (nlinks && type == BREAD) | ||
600 | - cur->fts_errno = errno; | ||
601 | - cur->fts_flags |= FTS_DONTCHDIR; | ||
602 | - descend = 0; | ||
603 | - cderrno = errno; | ||
604 | - (void)closedir(dirp); | ||
605 | - dirp = NULL; | ||
606 | - } else | ||
607 | - descend = 1; | ||
608 | - } else | ||
609 | - descend = 0; | ||
610 | - | ||
611 | - /* | ||
612 | - * Figure out the max file name length that can be stored in the | ||
613 | - * current path -- the inner loop allocates more path as necessary. | ||
614 | - * We really wouldn't have to do the maxlen calculations here, we | ||
615 | - * could do them in fts_read before returning the path, but it's a | ||
616 | - * lot easier here since the length is part of the dirent structure. | ||
617 | - * | ||
618 | - * If not changing directories set a pointer so that can just append | ||
619 | - * each new name into the path. | ||
620 | - */ | ||
621 | - len = NAPPEND(cur); | ||
622 | - if (ISSET(FTS_NOCHDIR)) { | ||
623 | - cp = sp->fts_path + len; | ||
624 | - *cp++ = '/'; | ||
625 | - } else { | ||
626 | - /* GCC, you're too verbose. */ | ||
627 | - cp = NULL; | ||
628 | - } | ||
629 | - len++; | ||
630 | - maxlen = sp->fts_pathlen - len; | ||
631 | - | ||
632 | - level = cur->fts_level + 1; | ||
633 | - | ||
634 | - /* Read the directory, attaching each entry to the `link' pointer. */ | ||
635 | - doadjust = 0; | ||
636 | - for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { | ||
637 | - if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) | ||
638 | - continue; | ||
639 | - | ||
640 | - if ((p = fts_alloc(sp, dp->d_name, (int)_D_EXACT_NAMLEN (dp))) == NULL) | ||
641 | - goto mem1; | ||
642 | - if (_D_EXACT_NAMLEN (dp) >= maxlen) {/* include space for NUL */ | ||
643 | - oldaddr = sp->fts_path; | ||
644 | - if (fts_palloc(sp, _D_EXACT_NAMLEN (dp) + len + 1)) { | ||
645 | - /* | ||
646 | - * No more memory for path or structures. Save | ||
647 | - * errno, free up the current structure and the | ||
648 | - * structures already allocated. | ||
649 | - */ | ||
650 | -mem1: saved_errno = errno; | ||
651 | - if (p) | ||
652 | - free(p); | ||
653 | - fts_lfree(head); | ||
654 | - (void)closedir(dirp); | ||
655 | - cur->fts_info = FTS_ERR; | ||
656 | - SET(FTS_STOP); | ||
657 | - errno = saved_errno; | ||
658 | - return (NULL); | ||
659 | - } | ||
660 | - /* Did realloc() change the pointer? */ | ||
661 | - if (oldaddr != sp->fts_path) { | ||
662 | - doadjust = 1; | ||
663 | - if (ISSET(FTS_NOCHDIR)) | ||
664 | - cp = sp->fts_path + len; | ||
665 | - } | ||
666 | - maxlen = sp->fts_pathlen - len; | ||
667 | - } | ||
668 | - | ||
669 | - if (len + _D_EXACT_NAMLEN (dp) >= 0x10000) { | ||
670 | - /* | ||
671 | - * In an FTSENT, fts_pathlen is a u_short so it is | ||
672 | - * possible to wraparound here. If we do, free up | ||
673 | - * the current structure and the structures already | ||
674 | - * allocated, then error out with ENAMETOOLONG. | ||
675 | - */ | ||
676 | - free(p); | ||
677 | - fts_lfree(head); | ||
678 | - (void)closedir(dirp); | ||
679 | - cur->fts_info = FTS_ERR; | ||
680 | - SET(FTS_STOP); | ||
681 | - errno = ENAMETOOLONG; | ||
682 | - return (NULL); | ||
683 | - } | ||
684 | - p->fts_level = level; | ||
685 | - p->fts_parent = sp->fts_cur; | ||
686 | - p->fts_pathlen = len + _D_EXACT_NAMLEN (dp); | ||
687 | - | ||
688 | -#if defined FTS_WHITEOUT && 0 | ||
689 | - if (dp->d_type == DT_WHT) | ||
690 | - p->fts_flags |= FTS_ISW; | ||
691 | -#endif | ||
692 | - | ||
693 | - if (cderrno) { | ||
694 | - if (nlinks) { | ||
695 | - p->fts_info = FTS_NS; | ||
696 | - p->fts_errno = cderrno; | ||
697 | - } else | ||
698 | - p->fts_info = FTS_NSOK; | ||
699 | - p->fts_accpath = cur->fts_accpath; | ||
700 | - } else if (nlinks == 0 | ||
701 | -#if defined DT_DIR && defined _DIRENT_HAVE_D_TYPE | ||
702 | - || (nostat && | ||
703 | - dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) | ||
704 | -#endif | ||
705 | - ) { | ||
706 | - p->fts_accpath = | ||
707 | - ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; | ||
708 | - p->fts_info = FTS_NSOK; | ||
709 | - } else { | ||
710 | - /* Build a file name for fts_stat to stat. */ | ||
711 | - if (ISSET(FTS_NOCHDIR)) { | ||
712 | - p->fts_accpath = p->fts_path; | ||
713 | - memmove(cp, p->fts_name, p->fts_namelen + 1); | ||
714 | - } else | ||
715 | - p->fts_accpath = p->fts_name; | ||
716 | - /* Stat it. */ | ||
717 | - p->fts_info = fts_stat(sp, p, 0); | ||
718 | - | ||
719 | - /* Decrement link count if applicable. */ | ||
720 | - if (nlinks > 0 && (p->fts_info == FTS_D || | ||
721 | - p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) | ||
722 | - --nlinks; | ||
723 | - } | ||
724 | - | ||
725 | - /* We walk in directory order so "ls -f" doesn't get upset. */ | ||
726 | - p->fts_link = NULL; | ||
727 | - if (head == NULL) | ||
728 | - head = tail = p; | ||
729 | - else { | ||
730 | - tail->fts_link = p; | ||
731 | - tail = p; | ||
732 | - } | ||
733 | - ++nitems; | ||
734 | - } | ||
735 | - if (dirp) | ||
736 | - (void)closedir(dirp); | ||
737 | - | ||
738 | - /* | ||
739 | - * If realloc() changed the address of the path, adjust the | ||
740 | - * addresses for the rest of the tree and the dir list. | ||
741 | - */ | ||
742 | - if (doadjust) | ||
743 | - fts_padjust(sp, head); | ||
744 | - | ||
745 | - /* | ||
746 | - * If not changing directories, reset the path back to original | ||
747 | - * state. | ||
748 | - */ | ||
749 | - if (ISSET(FTS_NOCHDIR)) { | ||
750 | - if (len == sp->fts_pathlen || nitems == 0) | ||
751 | - --cp; | ||
752 | - *cp = '\0'; | ||
753 | - } | ||
754 | - | ||
755 | - /* | ||
756 | - * If descended after called from fts_children or after called from | ||
757 | - * fts_read and nothing found, get back. At the root level we use | ||
758 | - * the saved fd; if one of fts_open()'s arguments is a relative path | ||
759 | - * to an empty directory, we wind up here with no other way back. If | ||
760 | - * can't get back, we're done. | ||
761 | - */ | ||
762 | - if (descend && nitems == 0 && | ||
763 | - (cur->fts_level == FTS_ROOTLEVEL ? | ||
764 | - FCHDIR(sp, sp->fts_rfd) : | ||
765 | - fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { | ||
766 | - cur->fts_info = FTS_ERR; | ||
767 | - SET(FTS_STOP); | ||
768 | - return (NULL); | ||
769 | - } | ||
770 | - | ||
771 | - /* If didn't find anything, return NULL. */ | ||
772 | - if (!nitems) { | ||
773 | - if (type == BREAD) | ||
774 | - cur->fts_info = FTS_DP; | ||
775 | - return (NULL); | ||
776 | - } | ||
777 | - | ||
778 | - /* Sort the entries. */ | ||
779 | - if (sp->fts_compar && nitems > 1) | ||
780 | - head = fts_sort(sp, head, nitems); | ||
781 | - return (head); | ||
782 | -} | ||
783 | - | ||
784 | -static u_short | ||
785 | -fts_stat(sp, p, follow) | ||
786 | - FTS *sp; | ||
787 | - register FTSENT *p; | ||
788 | - int follow; | ||
789 | -{ | ||
790 | - register FTSENT *t; | ||
791 | - register dev_t dev; | ||
792 | - register ino_t ino; | ||
793 | - struct stat *sbp; | ||
794 | - int saved_errno; | ||
795 | - | ||
796 | - /* If user needs stat info, stat buffer already allocated. */ | ||
797 | - sbp = p->fts_statp; | ||
798 | - | ||
799 | -#if defined FTS_WHITEOUT && 0 | ||
800 | - /* check for whiteout */ | ||
801 | - if (p->fts_flags & FTS_ISW) { | ||
802 | - if (sbp != &sb) { | ||
803 | - memset(sbp, '\0', sizeof (*sbp)); | ||
804 | - sbp->st_mode = S_IFWHT; | ||
805 | - } | ||
806 | - return (FTS_W); | ||
807 | - } | ||
808 | -#endif | ||
809 | - | ||
810 | - /* | ||
811 | - * If doing a logical walk, or application requested FTS_FOLLOW, do | ||
812 | - * a stat(2). If that fails, check for a non-existent symlink. If | ||
813 | - * fail, set the errno from the stat call. | ||
814 | - */ | ||
815 | - if (ISSET(FTS_LOGICAL) || follow) { | ||
816 | - if (stat(p->fts_accpath, sbp)) { | ||
817 | - saved_errno = errno; | ||
818 | - if (!lstat(p->fts_accpath, sbp)) { | ||
819 | - errno = 0; | ||
820 | - return (FTS_SLNONE); | ||
821 | - } | ||
822 | - p->fts_errno = saved_errno; | ||
823 | - goto err; | ||
824 | - } | ||
825 | - } else if (lstat(p->fts_accpath, sbp)) { | ||
826 | - p->fts_errno = errno; | ||
827 | -err: memset(sbp, 0, sizeof(struct stat)); | ||
828 | - return (FTS_NS); | ||
829 | - } | ||
830 | - | ||
831 | - if (S_ISDIR(sbp->st_mode)) { | ||
832 | - /* | ||
833 | - * Set the device/inode. Used to find cycles and check for | ||
834 | - * crossing mount points. Also remember the link count, used | ||
835 | - * in fts_build to limit the number of stat calls. It is | ||
836 | - * understood that these fields are only referenced if fts_info | ||
837 | - * is set to FTS_D. | ||
838 | - */ | ||
839 | - dev = p->fts_dev = sbp->st_dev; | ||
840 | - ino = p->fts_ino = sbp->st_ino; | ||
841 | - p->fts_nlink = sbp->st_nlink; | ||
842 | - | ||
843 | - if (ISDOT(p->fts_name)) | ||
844 | - return (FTS_DOT); | ||
845 | - | ||
846 | - /* | ||
847 | - * Cycle detection is done by brute force when the directory | ||
848 | - * is first encountered. If the tree gets deep enough or the | ||
849 | - * number of symbolic links to directories is high enough, | ||
850 | - * something faster might be worthwhile. | ||
851 | - */ | ||
852 | - for (t = p->fts_parent; | ||
853 | - t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) | ||
854 | - if (ino == t->fts_ino && dev == t->fts_dev) { | ||
855 | - p->fts_cycle = t; | ||
856 | - return (FTS_DC); | ||
857 | - } | ||
858 | - return (FTS_D); | ||
859 | - } | ||
860 | - if (S_ISLNK(sbp->st_mode)) | ||
861 | - return (FTS_SL); | ||
862 | - if (S_ISREG(sbp->st_mode)) | ||
863 | - return (FTS_F); | ||
864 | - return (FTS_DEFAULT); | ||
865 | -} | ||
866 | - | ||
867 | -static FTSENT * | ||
868 | -fts_sort(sp, head, nitems) | ||
869 | - FTS *sp; | ||
870 | - FTSENT *head; | ||
871 | - register int nitems; | ||
872 | -{ | ||
873 | - register FTSENT **ap, *p; | ||
874 | - | ||
875 | - /* | ||
876 | - * Construct an array of pointers to the structures and call qsort(3). | ||
877 | - * Reassemble the array in the order returned by qsort. If unable to | ||
878 | - * sort for memory reasons, return the directory entries in their | ||
879 | - * current order. Allocate enough space for the current needs plus | ||
880 | - * 40 so don't realloc one entry at a time. | ||
881 | - */ | ||
882 | - if (nitems > sp->fts_nitems) { | ||
883 | - struct _ftsent **a; | ||
884 | - | ||
885 | - sp->fts_nitems = nitems + 40; | ||
886 | - if ((a = realloc(sp->fts_array, | ||
887 | - (size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) { | ||
888 | - free(sp->fts_array); | ||
889 | - sp->fts_array = NULL; | ||
890 | - sp->fts_nitems = 0; | ||
891 | - return (head); | ||
892 | - } | ||
893 | - sp->fts_array = a; | ||
894 | - } | ||
895 | - for (ap = sp->fts_array, p = head; p; p = p->fts_link) | ||
896 | - *ap++ = p; | ||
897 | - qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar); | ||
898 | - for (head = *(ap = sp->fts_array); --nitems; ++ap) | ||
899 | - ap[0]->fts_link = ap[1]; | ||
900 | - ap[0]->fts_link = NULL; | ||
901 | - return (head); | ||
902 | -} | ||
903 | - | ||
904 | -static FTSENT * | ||
905 | -fts_alloc(sp, name, namelen) | ||
906 | - FTS *sp; | ||
907 | - const char *name; | ||
908 | - register int namelen; | ||
909 | -{ | ||
910 | - register FTSENT *p; | ||
911 | - size_t len; | ||
912 | - | ||
913 | - /* | ||
914 | - * The file name is a variable length array and no stat structure is | ||
915 | - * necessary if the user has set the nostat bit. Allocate the FTSENT | ||
916 | - * structure, the file name and the stat structure in one chunk, but | ||
917 | - * be careful that the stat structure is reasonably aligned. Since the | ||
918 | - * fts_name field is declared to be of size 1, the fts_name pointer is | ||
919 | - * namelen + 2 before the first possible address of the stat structure. | ||
920 | - */ | ||
921 | - len = sizeof(FTSENT) + namelen; | ||
922 | - len += sizeof(struct stat) + ALIGNBYTES; | ||
923 | - if ((p = malloc(len)) == NULL) | ||
924 | - return (NULL); | ||
925 | - | ||
926 | - /* Copy the name and guarantee NUL termination. */ | ||
927 | - memmove(p->fts_name, name, namelen); | ||
928 | - p->fts_name[namelen] = '\0'; | ||
929 | - | ||
930 | - p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2); | ||
931 | - p->fts_namelen = namelen; | ||
932 | - p->fts_path = sp->fts_path; | ||
933 | - p->fts_errno = 0; | ||
934 | - p->fts_flags = 0; | ||
935 | - p->fts_instr = FTS_NOINSTR; | ||
936 | - p->fts_number = 0; | ||
937 | - p->fts_pointer = NULL; | ||
938 | - return (p); | ||
939 | -} | ||
940 | - | ||
941 | -static void | ||
942 | -fts_lfree(head) | ||
943 | - register FTSENT *head; | ||
944 | -{ | ||
945 | - register FTSENT *p; | ||
946 | - | ||
947 | - /* Free a linked list of structures. */ | ||
948 | - while ((p = head)) { | ||
949 | - head = head->fts_link; | ||
950 | - free(p); | ||
951 | - } | ||
952 | -} | ||
953 | - | ||
954 | -/* | ||
955 | - * Allow essentially unlimited paths; find, rm, ls should all work on any tree. | ||
956 | - * Most systems will allow creation of paths much longer than MAXPATHLEN, even | ||
957 | - * though the kernel won't resolve them. Add the size (not just what's needed) | ||
958 | - * plus 256 bytes so don't realloc the path 2 bytes at a time. | ||
959 | - */ | ||
960 | -static int | ||
961 | -fts_palloc(sp, more) | ||
962 | - FTS *sp; | ||
963 | - size_t more; | ||
964 | -{ | ||
965 | - char *p; | ||
966 | - | ||
967 | - sp->fts_pathlen += more + 256; | ||
968 | - /* | ||
969 | - * Check for possible wraparound. In an FTS, fts_pathlen is | ||
970 | - * a signed int but in an FTSENT it is an unsigned short. | ||
971 | - * We limit fts_pathlen to USHRT_MAX to be safe in both cases. | ||
972 | - */ | ||
973 | - if (sp->fts_pathlen < 0 || sp->fts_pathlen >= 0x10000) { | ||
974 | - if (sp->fts_path) { | ||
975 | - free(sp->fts_path); | ||
976 | - sp->fts_path = NULL; | ||
977 | - } | ||
978 | - sp->fts_path = NULL; | ||
979 | - errno = ENAMETOOLONG; | ||
980 | - return (1); | ||
981 | - } | ||
982 | - p = realloc(sp->fts_path, sp->fts_pathlen); | ||
983 | - if (p == NULL) { | ||
984 | - free(sp->fts_path); | ||
985 | - sp->fts_path = NULL; | ||
986 | - return 1; | ||
987 | - } | ||
988 | - sp->fts_path = p; | ||
989 | - return 0; | ||
990 | -} | ||
991 | - | ||
992 | -/* | ||
993 | - * When the path is realloc'd, have to fix all of the pointers in structures | ||
994 | - * already returned. | ||
995 | - */ | ||
996 | -static void | ||
997 | -fts_padjust(sp, head) | ||
998 | - FTS *sp; | ||
999 | - FTSENT *head; | ||
1000 | -{ | ||
1001 | - FTSENT *p; | ||
1002 | - char *addr = sp->fts_path; | ||
1003 | - | ||
1004 | -#define ADJUST(p) do { \ | ||
1005 | - if ((p)->fts_accpath != (p)->fts_name) { \ | ||
1006 | - (p)->fts_accpath = \ | ||
1007 | - (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ | ||
1008 | - } \ | ||
1009 | - (p)->fts_path = addr; \ | ||
1010 | -} while (0) | ||
1011 | - /* Adjust the current set of children. */ | ||
1012 | - for (p = sp->fts_child; p; p = p->fts_link) | ||
1013 | - ADJUST(p); | ||
1014 | - | ||
1015 | - /* Adjust the rest of the tree, including the current level. */ | ||
1016 | - for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { | ||
1017 | - ADJUST(p); | ||
1018 | - p = p->fts_link ? p->fts_link : p->fts_parent; | ||
1019 | - } | ||
1020 | -} | ||
1021 | - | ||
1022 | -static size_t | ||
1023 | -fts_maxarglen(argv) | ||
1024 | - char * const *argv; | ||
1025 | -{ | ||
1026 | - size_t len, max; | ||
1027 | - | ||
1028 | - for (max = 0; *argv; ++argv) | ||
1029 | - if ((len = strlen(*argv)) > max) | ||
1030 | - max = len; | ||
1031 | - return (max + 1); | ||
1032 | -} | ||
1033 | - | ||
1034 | -/* | ||
1035 | - * Change to dir specified by fd or p->fts_accpath without getting | ||
1036 | - * tricked by someone changing the world out from underneath us. | ||
1037 | - * Assumes p->fts_dev and p->fts_ino are filled in. | ||
1038 | - */ | ||
1039 | -static int | ||
1040 | -fts_safe_changedir(sp, p, fd, path) | ||
1041 | - FTS *sp; | ||
1042 | - FTSENT *p; | ||
1043 | - int fd; | ||
1044 | - const char *path; | ||
1045 | -{ | ||
1046 | - int ret, oerrno, newfd; | ||
1047 | - struct stat sb; | ||
1048 | - | ||
1049 | - newfd = fd; | ||
1050 | - if (ISSET(FTS_NOCHDIR)) | ||
1051 | - return (0); | ||
1052 | - if (fd < 0 && (newfd = open(path, O_RDONLY, 0)) < 0) | ||
1053 | - return (-1); | ||
1054 | - if (fstat(newfd, &sb)) { | ||
1055 | - ret = -1; | ||
1056 | - goto bail; | ||
1057 | - } | ||
1058 | - if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) { | ||
1059 | - errno = ENOENT; /* disinformation */ | ||
1060 | - ret = -1; | ||
1061 | - goto bail; | ||
1062 | - } | ||
1063 | - ret = fchdir(newfd); | ||
1064 | -bail: | ||
1065 | - oerrno = errno; | ||
1066 | - if (fd < 0) | ||
1067 | - (void)close(newfd); | ||
1068 | - errno = oerrno; | ||
1069 | - return (ret); | ||
1070 | -} | ||
1071 | diff --git a/lib/fts.h b/lib/fts.h | ||
1072 | deleted file mode 100644 | ||
1073 | index 58846b9..0000000 | ||
1074 | --- a/lib/fts.h | ||
1075 | +++ /dev/null | ||
1076 | @@ -1,131 +0,0 @@ | ||
1077 | -/* | ||
1078 | - * Copyright (c) 1989, 1993 | ||
1079 | - * The Regents of the University of California. All rights reserved. | ||
1080 | - * | ||
1081 | - * Redistribution and use in source and binary forms, with or without | ||
1082 | - * modification, are permitted provided that the following conditions | ||
1083 | - * are met: | ||
1084 | - * 1. Redistributions of source code must retain the above copyright | ||
1085 | - * notice, this list of conditions and the following disclaimer. | ||
1086 | - * 2. Redistributions in binary form must reproduce the above copyright | ||
1087 | - * notice, this list of conditions and the following disclaimer in the | ||
1088 | - * documentation and/or other materials provided with the distribution. | ||
1089 | - * 4. Neither the name of the University nor the names of its contributors | ||
1090 | - * may be used to endorse or promote products derived from this software | ||
1091 | - * without specific prior written permission. | ||
1092 | - * | ||
1093 | - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
1094 | - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
1095 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
1096 | - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
1097 | - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
1098 | - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
1099 | - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
1100 | - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
1101 | - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
1102 | - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
1103 | - * SUCH DAMAGE. | ||
1104 | - * | ||
1105 | - * @(#)fts.h 8.3 (Berkeley) 8/14/94 | ||
1106 | - */ | ||
1107 | - | ||
1108 | -#ifndef _FTS_H | ||
1109 | -#define _FTS_H 1 | ||
1110 | - | ||
1111 | -#include <features.h> | ||
1112 | -#include <sys/types.h> | ||
1113 | - | ||
1114 | -typedef struct { | ||
1115 | - struct _ftsent *fts_cur; /* current node */ | ||
1116 | - struct _ftsent *fts_child; /* linked list of children */ | ||
1117 | - struct _ftsent **fts_array; /* sort array */ | ||
1118 | - dev_t fts_dev; /* starting device # */ | ||
1119 | - char *fts_path; /* path for this descent */ | ||
1120 | - int fts_rfd; /* fd for root */ | ||
1121 | - int fts_pathlen; /* sizeof(path) */ | ||
1122 | - int fts_nitems; /* elements in the sort array */ | ||
1123 | - int (*fts_compar) (const void *, const void *); /* compare fn */ | ||
1124 | - | ||
1125 | -#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */ | ||
1126 | -#define FTS_LOGICAL 0x0002 /* logical walk */ | ||
1127 | -#define FTS_NOCHDIR 0x0004 /* don't change directories */ | ||
1128 | -#define FTS_NOSTAT 0x0008 /* don't get stat info */ | ||
1129 | -#define FTS_PHYSICAL 0x0010 /* physical walk */ | ||
1130 | -#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */ | ||
1131 | -#define FTS_XDEV 0x0040 /* don't cross devices */ | ||
1132 | -#define FTS_WHITEOUT 0x0080 /* return whiteout information */ | ||
1133 | -#define FTS_OPTIONMASK 0x00ff /* valid user option mask */ | ||
1134 | - | ||
1135 | -#define FTS_NAMEONLY 0x0100 /* (private) child names only */ | ||
1136 | -#define FTS_STOP 0x0200 /* (private) unrecoverable error */ | ||
1137 | - int fts_options; /* fts_open options, global flags */ | ||
1138 | -} FTS; | ||
1139 | - | ||
1140 | -typedef struct _ftsent { | ||
1141 | - struct _ftsent *fts_cycle; /* cycle node */ | ||
1142 | - struct _ftsent *fts_parent; /* parent directory */ | ||
1143 | - struct _ftsent *fts_link; /* next file in directory */ | ||
1144 | - long fts_number; /* local numeric value */ | ||
1145 | - void *fts_pointer; /* local address value */ | ||
1146 | - char *fts_accpath; /* access path */ | ||
1147 | - char *fts_path; /* root path */ | ||
1148 | - int fts_errno; /* errno for this node */ | ||
1149 | - int fts_symfd; /* fd for symlink */ | ||
1150 | - u_short fts_pathlen; /* strlen(fts_path) */ | ||
1151 | - u_short fts_namelen; /* strlen(fts_name) */ | ||
1152 | - | ||
1153 | - ino_t fts_ino; /* inode */ | ||
1154 | - dev_t fts_dev; /* device */ | ||
1155 | - nlink_t fts_nlink; /* link count */ | ||
1156 | - | ||
1157 | -#define FTS_ROOTPARENTLEVEL -1 | ||
1158 | -#define FTS_ROOTLEVEL 0 | ||
1159 | - short fts_level; /* depth (-1 to N) */ | ||
1160 | - | ||
1161 | -#define FTS_D 1 /* preorder directory */ | ||
1162 | -#define FTS_DC 2 /* directory that causes cycles */ | ||
1163 | -#define FTS_DEFAULT 3 /* none of the above */ | ||
1164 | -#define FTS_DNR 4 /* unreadable directory */ | ||
1165 | -#define FTS_DOT 5 /* dot or dot-dot */ | ||
1166 | -#define FTS_DP 6 /* postorder directory */ | ||
1167 | -#define FTS_ERR 7 /* error; errno is set */ | ||
1168 | -#define FTS_F 8 /* regular file */ | ||
1169 | -#define FTS_INIT 9 /* initialized only */ | ||
1170 | -#define FTS_NS 10 /* stat(2) failed */ | ||
1171 | -#define FTS_NSOK 11 /* no stat(2) requested */ | ||
1172 | -#define FTS_SL 12 /* symbolic link */ | ||
1173 | -#define FTS_SLNONE 13 /* symbolic link without target */ | ||
1174 | -#define FTS_W 14 /* whiteout object */ | ||
1175 | - u_short fts_info; /* user flags for FTSENT structure */ | ||
1176 | - | ||
1177 | -#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ | ||
1178 | -#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ | ||
1179 | - u_short fts_flags; /* private flags for FTSENT structure */ | ||
1180 | - | ||
1181 | -#define FTS_AGAIN 1 /* read node again */ | ||
1182 | -#define FTS_FOLLOW 2 /* follow symbolic link */ | ||
1183 | -#define FTS_NOINSTR 3 /* no instructions */ | ||
1184 | -#define FTS_SKIP 4 /* discard node */ | ||
1185 | - u_short fts_instr; /* fts_set() instructions */ | ||
1186 | - | ||
1187 | - struct stat *fts_statp; /* stat(2) information */ | ||
1188 | - char fts_name[1]; /* file name */ | ||
1189 | -} FTSENT; | ||
1190 | - | ||
1191 | -__BEGIN_DECLS | ||
1192 | - | ||
1193 | -#define fts_children pax_fts_children | ||
1194 | -#define fts_close pax_fts_close | ||
1195 | -#define fts_open pax_fts_open | ||
1196 | -#define fts_read pax_fts_read | ||
1197 | -#define fts_set pax_fts_set | ||
1198 | - | ||
1199 | -FTSENT *fts_children (FTS *, int); | ||
1200 | -int fts_close (FTS *); | ||
1201 | -FTS *fts_open (char * const *, int, | ||
1202 | - int (*)(const FTSENT **, const FTSENT **)); | ||
1203 | -FTSENT *fts_read (FTS *); | ||
1204 | -int fts_set (FTS *, FTSENT *, int) __THROW; | ||
1205 | -__END_DECLS | ||
1206 | - | ||
1207 | -#endif /* fts.h */ | ||
1208 | diff --git a/lib/vis.h b/lib/vis.h | ||
1209 | index d34d342..71fa5f4 100644 | ||
1210 | --- a/lib/vis.h | ||
1211 | +++ b/lib/vis.h | ||
1212 | @@ -73,14 +73,19 @@ | ||
1213 | */ | ||
1214 | #define UNVIS_END 1 /* no more characters */ | ||
1215 | |||
1216 | -#include <sys/cdefs.h> | ||
1217 | +#ifndef __P | ||
1218 | +#define __P(x) x | ||
1219 | +#endif | ||
1220 | |||
1221 | -__BEGIN_DECLS | ||
1222 | +#ifdef __cplusplus | ||
1223 | +extern "C" { | ||
1224 | +#endif | ||
1225 | char *vis __P((char *, int, int, int)); | ||
1226 | int strvis __P((char *, const char *, int)); | ||
1227 | int strvisx __P((char *, const char *, size_t, int)); | ||
1228 | int strunvis __P((char *, const char *)); | ||
1229 | int unvis __P((char *, char, int *, int)); | ||
1230 | -__END_DECLS | ||
1231 | - | ||
1232 | +#ifdef __cplusplus | ||
1233 | +} | ||
1234 | +#endif | ||
1235 | #endif /* !_VIS_H_ */ | ||
1236 | diff --git a/src/Makefile.am b/src/Makefile.am | ||
1237 | index 5ef52a3..227cdef 100644 | ||
1238 | --- a/src/Makefile.am | ||
1239 | +++ b/src/Makefile.am | ||
1240 | @@ -22,4 +22,4 @@ pax_SOURCES = ar_io.c ar_subs.c buf_subs.c cache.c cpio.c\ | ||
1241 | file_subs.c ftree.c gen_subs.c getoldopt.c options.c\ | ||
1242 | pat_rep.c pax.c sel_subs.c tables.c tar.c tty_subs.c | ||
1243 | |||
1244 | -pax_LDADD = $(top_builddir)/lib/libbsdfunc.a | ||
1245 | +pax_LDADD = $(top_builddir)/lib/libbsdfunc.a -lfts | ||
1246 | diff --git a/src/extern.h b/src/extern.h | ||
1247 | index 361fa81..3ed365d 100644 | ||
1248 | --- a/src/extern.h | ||
1249 | +++ b/src/extern.h | ||
1250 | @@ -37,8 +37,6 @@ | ||
1251 | * External references from each source file | ||
1252 | */ | ||
1253 | |||
1254 | -#include <sys/cdefs.h> | ||
1255 | - | ||
1256 | /* | ||
1257 | * ar_io.c | ||
1258 | */ | ||
1259 | diff --git a/src/file_subs.c b/src/file_subs.c | ||
1260 | index 5590ff1..15bc339 100644 | ||
1261 | --- a/src/file_subs.c | ||
1262 | +++ b/src/file_subs.c | ||
1263 | @@ -52,7 +52,7 @@ | ||
1264 | #include "extern.h" | ||
1265 | |||
1266 | static int | ||
1267 | -mk_link __P((register char *,register struct stat *,register char *, int)); | ||
1268 | +mk_link (register char *,register struct stat *,register char *, int); | ||
1269 | |||
1270 | /* | ||
1271 | * routines that deal with file operations such as: creating, removing; | ||
1272 | diff --git a/src/tables.c b/src/tables.c | ||
1273 | index 2275bf7..8fddca4 100644 | ||
1274 | --- a/src/tables.c | ||
1275 | +++ b/src/tables.c | ||
1276 | @@ -39,7 +39,7 @@ | ||
1277 | #include <sys/time.h> | ||
1278 | #include <sys/stat.h> | ||
1279 | #include <sys/param.h> | ||
1280 | -#include <sys/fcntl.h> | ||
1281 | +#include <fcntl.h> | ||
1282 | #include <stdio.h> | ||
1283 | #include <string.h> | ||
1284 | #include <unistd.h> | ||
1285 | -- | ||
1286 | 2.6.4 | ||
1287 | |||
diff --git a/meta/recipes-extended/pax/pax/0001-use-strtoll-instead-of-strtoq.patch b/meta/recipes-extended/pax/pax/0001-use-strtoll-instead-of-strtoq.patch new file mode 100644 index 0000000000..58ac9ce4a0 --- /dev/null +++ b/meta/recipes-extended/pax/pax/0001-use-strtoll-instead-of-strtoq.patch | |||
@@ -0,0 +1,33 @@ | |||
1 | From b1f50320332c9c90fa33ab136ef0ec2d12cda461 Mon Sep 17 00:00:00 2001 | ||
2 | From: Khem Raj <raj.khem@gmail.com> | ||
3 | Date: Wed, 6 Jan 2016 12:30:52 -0800 | ||
4 | Subject: [PATCH] use strtoll instead of strtoq | ||
5 | |||
6 | Use LLONG_MAX instead of LONG_LONG_MAX | ||
7 | LONG_LONG_MAX is GNU specific | ||
8 | |||
9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
10 | --- | ||
11 | Upstream-Status: Pending | ||
12 | |||
13 | src/options.c | 4 ++-- | ||
14 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
15 | |||
16 | diff --git a/src/options.c b/src/options.c | ||
17 | index da8b4cf..c663b4e 100644 | ||
18 | --- a/src/options.c | ||
19 | +++ b/src/options.c | ||
20 | @@ -1547,8 +1547,8 @@ str_offt (char *val) | ||
21 | |||
22 | #if (SIZEOF_LONG == 4 && SIZEOF_OFF_T == 8) \ | ||
23 | || (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) | ||
24 | - num = strtoq (val, &expr, 0); | ||
25 | - if ((num == LONG_LONG_MAX) || (num <= 0) || (expr == val)) | ||
26 | + num = strtoll (val, &expr, 0); | ||
27 | + if ((num == LLONG_MAX) || (num <= 0) || (expr == val)) | ||
28 | #else | ||
29 | num = strtol (val, &expr, 0); | ||
30 | if ((num == LONG_MAX) || (num <= 0) || (expr == val)) | ||
31 | -- | ||
32 | 2.6.4 | ||
33 | |||
diff --git a/meta/recipes-extended/pax/pax_3.4.bb b/meta/recipes-extended/pax/pax_3.4.bb index ad04871a8e..cee52e3e57 100644 --- a/meta/recipes-extended/pax/pax_3.4.bb +++ b/meta/recipes-extended/pax/pax_3.4.bb | |||
@@ -12,11 +12,21 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=4b0b674dfdc56daa3832d4069b820ea0 \ | |||
12 | SECTION = "base" | 12 | SECTION = "base" |
13 | PR = "r2" | 13 | PR = "r2" |
14 | 14 | ||
15 | DEPENDS_append_libc-musl = " fts " | ||
16 | |||
15 | SRC_URI = "http://pkgs.fedoraproject.org/repo/pkgs/${BPN}/${BP}.tar.bz2/fbd9023b590b45ac3ade95870702a0d6/${BP}.tar.bz2 \ | 17 | SRC_URI = "http://pkgs.fedoraproject.org/repo/pkgs/${BPN}/${BP}.tar.bz2/fbd9023b590b45ac3ade95870702a0d6/${BP}.tar.bz2 \ |
16 | file://fix_for_compile_with_gcc-4.6.0.patch \ | 18 | file://fix_for_compile_with_gcc-4.6.0.patch \ |
17 | file://pax-3.4_fix_for_x32.patch" | 19 | file://pax-3.4_fix_for_x32.patch" |
18 | 20 | ||
21 | SRC_URI_append_libc-musl = " file://0001-Fix-build-with-musl.patch \ | ||
22 | file://0001-use-strtoll-instead-of-strtoq.patch \ | ||
23 | " | ||
24 | |||
19 | SRC_URI[md5sum] = "fbd9023b590b45ac3ade95870702a0d6" | 25 | SRC_URI[md5sum] = "fbd9023b590b45ac3ade95870702a0d6" |
20 | SRC_URI[sha256sum] = "ac3c06048e02828077cf7757d3d142241429238893b91d529af29a2e8cc5623b" | 26 | SRC_URI[sha256sum] = "ac3c06048e02828077cf7757d3d142241429238893b91d529af29a2e8cc5623b" |
21 | 27 | ||
28 | # see https://lists.yoctoproject.org/pipermail/poky/2013-December/009435.html | ||
29 | # We should ideally drop ac_cv_sizeof_off_t from site files but until then | ||
30 | EXTRA_OECONF += "${@bb.utils.contains('DISTRO_FEATURES', 'largefile', 'ac_cv_sizeof_off_t=8', '', d)}" | ||
31 | |||
22 | inherit autotools | 32 | inherit autotools |