Mercurial > hg > toybox
annotate lib/dirtree.c @ 1613:96aa7ec74936 draft
Fix yet another sed bug.
The s/// command would copy the \ of substitutions before deciding what to
do with them (generally overwriting the \ with the new data). When the
substitution was A) at the very end of the new string, B) resolved to nothing,
it could leave a trailing \ that didn't belong there and didn't get overwritten
because the "copy trailing data" part that copies the original string's null
terminator already happened before the \ overwrote it.
The ghostwheel() function restarts regexes after embedded NUL bytes, but
if the string it's passed is _longer_ than the length it's told then it
gets confused (and it means we're off the end of our allocation so segfaults
are likely).
Fix: test for \ first and move the "copy byte" logic into an else case.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 15 Dec 2014 03:34:55 -0600 |
parents | a2796b4cef49 |
children |
rev | line source |
---|---|
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 /* dirtree.c - Functions for dealing with directory trees. |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * Copyright 2007 Rob Landley <rob@landley.net> |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 */ |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 #include "toys.h" |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
8 static int notdotdot(char *name) |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
9 { |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
10 if (name[0]=='.' && (!name[1] || (name[1]=='.' && !name[2]))) return 0; |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
11 |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
12 return 1; |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
13 } |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
14 |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
15 // Default callback, filters out "." and "..". |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
16 |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
17 int dirtree_notdotdot(struct dirtree *catch) |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
18 { |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
19 // Should we skip "." and ".."? |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
20 return notdotdot(catch->name) ? DIRTREE_SAVE|DIRTREE_RECURSE : 0; |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
21 } |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
22 |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
23 // Create a dirtree node from a path, with stat and symlink info. |
569
2e0367cb9585
More work on ls. Now ls -lR sort of works-ish.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
24 // (This doesn't open directory filehandles yet so as not to exhaust the |
779
90e98cdb1b7c
Make dirtree_handle_callback() start with dirtree_ like the rest of the dirtree functions.
Rob Landley <rob@landley.net>
parents:
739
diff
changeset
|
25 // filehandle space on large trees, dirtree_handle_callback() does that.) |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
27 struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
28 int symfollow) |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
30 struct dirtree *dt = NULL; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
31 struct stat st; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
32 char buf[4096]; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
33 int len = 0, linklen = 0; |
156
1e8f4b05cb65
Remove trailing whitespace (thanks to Charlie Shepherd), and a couple comment
Rob Landley <rob@landley.net>
parents:
143
diff
changeset
|
34 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
35 if (name) { |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
36 // open code this because haven't got node to call dirtree_parentfd() on yet |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
37 int fd = parent ? parent->data : AT_FDCWD; |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
38 |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
39 if (fstatat(fd, name, &st, symfollow ? 0 : AT_SYMLINK_NOFOLLOW)) goto error; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
40 if (S_ISLNK(st.st_mode)) { |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
41 if (0>(linklen = readlinkat(fd, name, buf, 4095))) goto error; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
42 buf[linklen++]=0; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
43 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
44 len = strlen(name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
45 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
46 dt = xzalloc((len = sizeof(struct dirtree)+len+1)+linklen); |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
47 dt->parent = parent; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
48 if (name) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
49 memcpy(&(dt->st), &st, sizeof(struct stat)); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
50 strcpy(dt->name, name); |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
52 if (linklen) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
53 dt->symlink = memcpy(len+(char *)dt, buf, linklen); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
54 dt->data = --linklen; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
55 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
56 } |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
58 return dt; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
59 |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
60 error: |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
61 if (notdotdot(name)) { |
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
62 char *path = parent ? dirtree_path(parent, 0) : ""; |
1398
7402cae7889f
Fix memory leak in error path.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
63 |
7402cae7889f
Fix memory leak in error path.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
64 perror_msg("%s%s%s", path, parent ? "/" : "", name); |
7402cae7889f
Fix memory leak in error path.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
65 if (parent) free(path); |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
66 } |
739
451d7e91232e
Complicate the rm -i behavior to do what posix specifies.
Rob Landley <rob@landley.net>
parents:
735
diff
changeset
|
67 if (parent) parent->symlink = (char *)1; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
68 free(dt); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
69 return 0; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
70 } |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
71 |
569
2e0367cb9585
More work on ls. Now ls -lR sort of works-ish.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
72 // Return path to this node, assembled recursively. |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
73 |
1496
a2796b4cef49
Respond to two static analysis issues in dirtree_path() reported by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1406
diff
changeset
|
74 // Initial call can pass in NULL to plen, or point to an int initialized to 0 |
a2796b4cef49
Respond to two static analysis issues in dirtree_path() reported by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1406
diff
changeset
|
75 // to return the length of the path, or a value greater than 0 to allocate |
a2796b4cef49
Respond to two static analysis issues in dirtree_path() reported by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1406
diff
changeset
|
76 // extra space if you want to append your own text to the string. |
a2796b4cef49
Respond to two static analysis issues in dirtree_path() reported by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1406
diff
changeset
|
77 |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
78 char *dirtree_path(struct dirtree *node, int *plen) |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
79 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
80 char *path; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
81 int len; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
82 |
1496
a2796b4cef49
Respond to two static analysis issues in dirtree_path() reported by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1406
diff
changeset
|
83 if (!node) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
84 path = xmalloc(*plen); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
85 *plen = 0; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
86 return path; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
87 } |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
89 len = (plen ? *plen : 0)+strlen(node->name)+1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
90 path = dirtree_path(node->parent, &len); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
91 if (len && path[len-1] != '/') path[len++]='/'; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
92 len = (stpcpy(path+len, node->name) - path); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
93 if (plen) *plen = len; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
94 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
95 return path; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
96 } |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
97 |
601 | 98 int dirtree_parentfd(struct dirtree *node) |
99 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
100 return node->parent ? node->parent->data : AT_FDCWD; |
601 | 101 } |
102 | |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
103 // Handle callback for a node in the tree. Returns saved node(s) or NULL. |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 // |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
105 // By default, allocates a tree of struct dirtree, not following symlinks |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
106 // If callback==NULL, or callback always returns 0, allocate tree of struct |
582
b88bc7dcdb48
Update chgrp so -R works, tweaking DIRTREE_COMEAGAIN design along the way.
Rob Landley <rob@landley.net>
parents:
580
diff
changeset
|
107 // dirtree and return root of tree. Otherwise call callback(node) on each |
b88bc7dcdb48
Update chgrp so -R works, tweaking DIRTREE_COMEAGAIN design along the way.
Rob Landley <rob@landley.net>
parents:
580
diff
changeset
|
108 // hit, free structures after use, and return NULL. |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
109 // |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 |
779
90e98cdb1b7c
Make dirtree_handle_callback() start with dirtree_ like the rest of the dirtree functions.
Rob Landley <rob@landley.net>
parents:
739
diff
changeset
|
111 struct dirtree *dirtree_handle_callback(struct dirtree *new, |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
112 int (*callback)(struct dirtree *node)) |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
114 int flags, dir = S_ISDIR(new->st.st_mode); |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
116 if (!callback) callback = dirtree_notdotdot; |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
118 flags = callback(new); |
582
b88bc7dcdb48
Update chgrp so -R works, tweaking DIRTREE_COMEAGAIN design along the way.
Rob Landley <rob@landley.net>
parents:
580
diff
changeset
|
119 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
120 if (dir) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
121 if (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN)) { |
1403
411cf82cdf77
Default xcreate/xopen to O_CLOEXEC. (Pass O_CLOEXEC in the flags to switch it back off.)
Rob Landley <rob@landley.net>
parents:
1398
diff
changeset
|
122 new->data = openat(dirtree_parentfd(new), new->name, O_CLOEXEC); |
1404
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
123 flags = dirtree_recurse(new, callback, flags); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
124 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
125 } |
582
b88bc7dcdb48
Update chgrp so -R works, tweaking DIRTREE_COMEAGAIN design along the way.
Rob Landley <rob@landley.net>
parents:
580
diff
changeset
|
126 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
127 // If this had children, it was callback's job to free them already. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
128 if (!(flags & DIRTREE_SAVE)) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
129 free(new); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
130 new = NULL; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
131 } |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
133 return (flags & DIRTREE_ABORT)==DIRTREE_ABORT ? DIRTREE_ABORTVAL : new; |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
134 } |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
136 // Recursively read/process children of directory node (with dirfd in data), |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
137 // filtering through callback(). |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 |
1404
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
139 int dirtree_recurse(struct dirtree *node, |
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
140 int (*callback)(struct dirtree *node), int flags) |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
141 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
142 struct dirtree *new, **ddt = &(node->child); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
143 struct dirent *entry; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
144 DIR *dir; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
145 |
944
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
779
diff
changeset
|
146 if (node->data == -1 || !(dir = fdopendir(node->data))) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
147 char *path = dirtree_path(node, 0); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
148 perror_msg("No %s", path); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
149 free(path); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
150 close(node->data); |
569
2e0367cb9585
More work on ls. Now ls -lR sort of works-ish.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
151 |
1404
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
152 return flags; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
153 } |
569
2e0367cb9585
More work on ls. Now ls -lR sort of works-ish.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
154 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
155 // according to the fddir() man page, the filehandle in the DIR * can still |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
156 // be externally used by things that don't lseek() it. |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
157 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
158 // The extra parentheses are to shut the stupid compiler up. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
159 while ((entry = readdir(dir))) { |
1404
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
160 if (!(new = dirtree_add_node(node, entry->d_name, flags&DIRTREE_SYMFOLLOW))) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
161 continue; |
779
90e98cdb1b7c
Make dirtree_handle_callback() start with dirtree_ like the rest of the dirtree functions.
Rob Landley <rob@landley.net>
parents:
739
diff
changeset
|
162 new = dirtree_handle_callback(new, callback); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
163 if (new == DIRTREE_ABORTVAL) break; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
164 if (new) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
165 *ddt = new; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
166 ddt = &((*ddt)->next); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
167 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
168 } |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
169 |
1406
5f20ac712f44
Actually set the again flag when calling the dirtree comeagain callback.
Rob Landley <rob@landley.net>
parents:
1404
diff
changeset
|
170 if (flags & DIRTREE_COMEAGAIN) { |
5f20ac712f44
Actually set the again flag when calling the dirtree comeagain callback.
Rob Landley <rob@landley.net>
parents:
1404
diff
changeset
|
171 node->again++; |
5f20ac712f44
Actually set the again flag when calling the dirtree comeagain callback.
Rob Landley <rob@landley.net>
parents:
1404
diff
changeset
|
172 flags = callback(node); |
5f20ac712f44
Actually set the again flag when calling the dirtree comeagain callback.
Rob Landley <rob@landley.net>
parents:
1404
diff
changeset
|
173 } |
1404
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
174 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
175 // This closes filehandle as well, so note it |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
176 closedir(dir); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
629
diff
changeset
|
177 node->data = -1; |
1404
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
178 |
ffc7f606ce5b
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Rob Landley <rob@landley.net>
parents:
1403
diff
changeset
|
179 return flags; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
180 } |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
181 |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
182 // Create dirtree from path, using callback to filter nodes. |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
183 // If callback == NULL allocate a tree of struct dirtree nodes and return |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
184 // pointer to root node. |
607
8bee9c27c219
Unify chown and chgrp, add support for -hHLP flags.
Rob Landley <rob@landley.net>
parents:
601
diff
changeset
|
185 // symfollow is just for the top of tree, callback return code controls children |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
186 |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
187 struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node)) |
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
188 { |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
189 struct dirtree *root = dirtree_add_node(0, path, 0); |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
190 |
779
90e98cdb1b7c
Make dirtree_handle_callback() start with dirtree_ like the rest of the dirtree functions.
Rob Landley <rob@landley.net>
parents:
739
diff
changeset
|
191 return root ? dirtree_handle_callback(root, callback) : DIRTREE_ABORTVAL; |
565
44abf4d901f3
Rewrite dirtree so we don't need readdir, scandir, and fts.h. Rewrite ls (from scratch) to use new dirtree infrastructure. (This breaks everything else that currently uses dirtree.)
Rob Landley <rob@landley.net>
parents:
320
diff
changeset
|
192 } |