Mercurial > hg > toybox
annotate lib/lib.h @ 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 | eee7dfe95a8f |
children | 184c98250cc5 |
rev | line source |
---|---|
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
1 /* lib.h - header file for lib directory |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
2 * |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
3 * Copyright 2006 Rob Landley <rob@landley.net> |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
4 */ |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
5 |
20
3981c96f9285
Implement which. Add hello world to menuconfig. Wrap the various applet main
Rob Landley <rob@landley.net>
parents:
16
diff
changeset
|
6 // llist.c |
3981c96f9285
Implement which. Add hello world to menuconfig. Wrap the various applet main
Rob Landley <rob@landley.net>
parents:
16
diff
changeset
|
7 |
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:
551
diff
changeset
|
8 // All these list types can be handled by the same code because first element |
821
46919d9f14f7
Remove unused min/max macros.
Rob Landley <rob@landley.net>
parents:
779
diff
changeset
|
9 // is always next pointer, so next = (mytype *)&struct. (The payloads are |
46919d9f14f7
Remove unused min/max macros.
Rob Landley <rob@landley.net>
parents:
779
diff
changeset
|
10 // named differently to catch using the wrong type early.) |
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:
551
diff
changeset
|
11 |
20
3981c96f9285
Implement which. Add hello world to menuconfig. Wrap the various applet main
Rob Landley <rob@landley.net>
parents:
16
diff
changeset
|
12 struct string_list { |
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:
658
diff
changeset
|
13 struct string_list *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:
658
diff
changeset
|
14 char str[0]; |
20
3981c96f9285
Implement which. Add hello world to menuconfig. Wrap the various applet main
Rob Landley <rob@landley.net>
parents:
16
diff
changeset
|
15 }; |
3981c96f9285
Implement which. Add hello world to menuconfig. Wrap the various applet main
Rob Landley <rob@landley.net>
parents:
16
diff
changeset
|
16 |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
20
diff
changeset
|
17 struct arg_list { |
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:
658
diff
changeset
|
18 struct arg_list *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:
658
diff
changeset
|
19 char *arg; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
20
diff
changeset
|
20 }; |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
20
diff
changeset
|
21 |
201
5d523752715a
Start of "patch" support. Writes to stdout at the moment.
Rob Landley <rob@landley.net>
parents:
185
diff
changeset
|
22 struct double_list { |
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:
658
diff
changeset
|
23 struct double_list *next, *prev; |
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:
658
diff
changeset
|
24 char *data; |
201
5d523752715a
Start of "patch" support. Writes to stdout at the moment.
Rob Landley <rob@landley.net>
parents:
185
diff
changeset
|
25 }; |
5d523752715a
Start of "patch" support. Writes to stdout at the moment.
Rob Landley <rob@landley.net>
parents:
185
diff
changeset
|
26 |
1295
114ec0ab161c
Add free functions for predefined llist types.
Rob Landley <rob@landley.net>
parents:
1276
diff
changeset
|
27 void llist_free_arg(void *node); |
114ec0ab161c
Add free functions for predefined llist types.
Rob Landley <rob@landley.net>
parents:
1276
diff
changeset
|
28 void llist_free_double(void *node); |
114ec0ab161c
Add free functions for predefined llist types.
Rob Landley <rob@landley.net>
parents:
1276
diff
changeset
|
29 void llist_traverse(void *list, void (*using)(void *node)); |
1059
ef72a16f4b3a
Redo tail closer to the original design. Add more tests for large data sets. (Still no -f support yet.)
Rob Landley <rob@landley.net>
parents:
1055
diff
changeset
|
30 void *llist_pop(void *list); // actually void **list |
ef72a16f4b3a
Redo tail closer to the original design. Add more tests for large data sets. (Still no -f support yet.)
Rob Landley <rob@landley.net>
parents:
1055
diff
changeset
|
31 void *dlist_pop(void *list); // actually struct double_list **list |
540
c2f39708a4c4
Redo tail to use optargs and optionally support lseek. Add support to optargs and llist.c, plus add a test suite entry. Still no -f support though.
Rob Landley <rob@landley.net>
parents:
503
diff
changeset
|
32 void dlist_add_nomalloc(struct double_list **list, struct double_list *new); |
315
aaac01796688
Upgrade patch to detect hunks that start after a false start.
Rob Landley <rob@landley.net>
parents:
311
diff
changeset
|
33 struct double_list *dlist_add(struct double_list **list, char *data); |
1321
4d898affda0c
Switch mtab_list to doubly linked so we can traverse in either order. Convert umount and df. Add dlist_terminate() to break lists for traversal in either direction.
Rob Landley <rob@landley.net>
parents:
1320
diff
changeset
|
34 void *dlist_terminate(void *list); |
238
630b2e12db16
Move dlist_add() to lib/llist.c
Rob Landley <rob@landley.net>
parents:
216
diff
changeset
|
35 |
143
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
137
diff
changeset
|
36 // args.c |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
137
diff
changeset
|
37 void get_optflags(void); |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
137
diff
changeset
|
38 |
9cbb323f297f
Break out dirtree.c and let it call a function instead of returning the data.
Rob Landley <rob@landley.net>
parents:
137
diff
changeset
|
39 // dirtree.c |
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:
551
diff
changeset
|
40 |
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:
551
diff
changeset
|
41 // Values returnable from callback function (bitfield, or them together) |
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:
551
diff
changeset
|
42 // Default with no callback is 0 |
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:
551
diff
changeset
|
43 |
580
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
44 // Add this node to the tree |
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
45 #define DIRTREE_SAVE 1 |
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
46 // Recurse into children |
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
47 #define DIRTREE_RECURSE 2 |
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
48 // Call again after handling all children of this directory |
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
49 // (Ignored for non-directories, sets linklen = -1 before second call.) |
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:
551
diff
changeset
|
50 #define DIRTREE_COMEAGAIN 4 |
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:
551
diff
changeset
|
51 // Follow symlinks to directories |
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:
551
diff
changeset
|
52 #define DIRTREE_SYMFOLLOW 8 |
580
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
53 // Don't look at any more files in this directory. |
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
54 #define DIRTREE_ABORT 256 |
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:
551
diff
changeset
|
55 |
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:
551
diff
changeset
|
56 #define DIRTREE_ABORTVAL ((struct dirtree *)1) |
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:
551
diff
changeset
|
57 |
95
a636e4d20f13
Add xstat(), read_dirtree(), and read_dirtree_node().
Rob Landley <rob@landley.net>
parents:
75
diff
changeset
|
58 struct dirtree { |
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:
658
diff
changeset
|
59 struct dirtree *next, *parent, *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:
658
diff
changeset
|
60 long extra; // place for user to store their stuff (can be pointer) |
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:
658
diff
changeset
|
61 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:
658
diff
changeset
|
62 char *symlink; |
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:
1399
diff
changeset
|
63 int data; // dirfd for directory, linklen for symlink |
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:
1399
diff
changeset
|
64 char again; |
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:
658
diff
changeset
|
65 char name[]; |
95
a636e4d20f13
Add xstat(), read_dirtree(), and read_dirtree_node().
Rob Landley <rob@landley.net>
parents:
75
diff
changeset
|
66 }; |
a636e4d20f13
Add xstat(), read_dirtree(), and read_dirtree_node().
Rob Landley <rob@landley.net>
parents:
75
diff
changeset
|
67 |
735
3aaba60133c8
Have dirtree_add_node() set parent so error message can provide full path.
Rob Landley <rob@landley.net>
parents:
730
diff
changeset
|
68 struct dirtree *dirtree_add_node(struct dirtree *p, char *name, int symfollow); |
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:
551
diff
changeset
|
69 char *dirtree_path(struct dirtree *node, int *plen); |
580
4877cff01b25
dirtree logic cleanup: switch DIRTREE_NORECURSE and DIRTREE_NOSAVE to DIRTREE_RECURSE and DIRTREE_SAVE.
Rob Landley <rob@landley.net>
parents:
565
diff
changeset
|
70 int dirtree_notdotdot(struct dirtree *catch); |
601 | 71 int dirtree_parentfd(struct dirtree *node); |
779
90e98cdb1b7c
Make dirtree_handle_callback() start with dirtree_ like the rest of the dirtree functions.
Rob Landley <rob@landley.net>
parents:
762
diff
changeset
|
72 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:
658
diff
changeset
|
73 int (*callback)(struct dirtree *node)); |
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:
1399
diff
changeset
|
74 int dirtree_recurse(struct dirtree *node, int (*callback)(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:
1399
diff
changeset
|
75 int symfollow); |
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:
551
diff
changeset
|
76 struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node)); |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
20
diff
changeset
|
77 |
858
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
821
diff
changeset
|
78 // help.c |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
821
diff
changeset
|
79 |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
821
diff
changeset
|
80 void show_help(void); |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
821
diff
changeset
|
81 |
952
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
82 // xwrap.c |
870 | 83 void xstrncpy(char *dest, char *src, size_t size); |
1599
cd97856ca52c
Implement xstrncat() and fix xstrndup().
Rob Landley <rob@landley.net>
parents:
1525
diff
changeset
|
84 void xstrncat(char *dest, char *src, size_t size); |
925
07693eb46e26
Add xexit() and make error_exit() use it.
Rob Landley <rob@landley.net>
parents:
916
diff
changeset
|
85 void xexit(void) noreturn; |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
86 void *xmalloc(size_t size); |
3
266a462ed18c
Next drop of toysh, plus more infratructure.
landley@driftwood
parents:
2
diff
changeset
|
87 void *xzalloc(size_t size); |
115
19b5567f0a1b
Add readlink, xreadlink(), and change xrealloc() to not fight the stupid
Rob Landley <rob@landley.net>
parents:
102
diff
changeset
|
88 void *xrealloc(void *ptr, size_t size); |
369
5715eed39575
Correct return types of xstrdup() and xstrndup()
Rob Landley <rob@landley.net>
parents:
340
diff
changeset
|
89 char *xstrndup(char *s, size_t n); |
5715eed39575
Correct return types of xstrdup() and xstrndup()
Rob Landley <rob@landley.net>
parents:
340
diff
changeset
|
90 char *xstrdup(char *s); |
1183
0752b2d58909
Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents:
1170
diff
changeset
|
91 char *xmprintf(char *format, ...); |
70
a1b464bbef08
Add "echo". Has -n and -e (but not \0123 yet).
Rob Landley <rob@landley.net>
parents:
64
diff
changeset
|
92 void xprintf(char *format, ...); |
128
0a90a5fbc1bf
Add xputs() to detect EOF on writes.
Rob Landley <rob@landley.net>
parents:
124
diff
changeset
|
93 void xputs(char *s); |
70
a1b464bbef08
Add "echo". Has -n and -e (but not \0123 yet).
Rob Landley <rob@landley.net>
parents:
64
diff
changeset
|
94 void xputc(char c); |
a1b464bbef08
Add "echo". Has -n and -e (but not \0123 yet).
Rob Landley <rob@landley.net>
parents:
64
diff
changeset
|
95 void xflush(void); |
952
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
96 void xexec_optargs(int skip); |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
97 void xexec(char **argv); |
1472
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
98 pid_t xpopen_both(char **argv, int *pipes); |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
99 int xpclose_both(pid_t pid, int *pipes); |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
100 pid_t xpopen(char **argv, int *pipe, int stdout); |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
101 pid_t xpclose(pid_t pid, int pipe); |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
102 int xrun(char **argv); |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
103 int xpspawn(char **argv, int*pipes); |
51 | 104 void xaccess(char *path, int flags); |
214
98820d1eaa79
Upgrade patch to understand creating and deleting files.
Rob Landley <rob@landley.net>
parents:
209
diff
changeset
|
105 void xunlink(char *path); |
49
bb4c38853a7d
xopen() wants 2 arguments unless you're creating a file, in which case you
Rob Landley <rob@landley.net>
parents:
35
diff
changeset
|
106 int xcreate(char *path, int flags, int mode); |
bb4c38853a7d
xopen() wants 2 arguments unless you're creating a file, in which case you
Rob Landley <rob@landley.net>
parents:
35
diff
changeset
|
107 int xopen(char *path, int flags); |
201
5d523752715a
Start of "patch" support. Writes to stdout at the moment.
Rob Landley <rob@landley.net>
parents:
185
diff
changeset
|
108 void xclose(int fd); |
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:
551
diff
changeset
|
109 int xdup(int fd); |
991
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
952
diff
changeset
|
110 FILE *xfdopen(int fd, char *mode); |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
111 FILE *xfopen(char *path, char *mode); |
63
69efffcacd70
Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents:
53
diff
changeset
|
112 size_t xread(int fd, void *buf, size_t len); |
69efffcacd70
Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents:
53
diff
changeset
|
113 void xreadall(int fd, void *buf, size_t len); |
69efffcacd70
Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents:
53
diff
changeset
|
114 void xwrite(int fd, void *buf, size_t len); |
340 | 115 off_t xlseek(int fd, off_t offset, int whence); |
1170
8afe1fde9314
Pass through all the readfile() arguments from xreadfile().
Rob Landley <rob@landley.net>
parents:
1156
diff
changeset
|
116 char *xreadfile(char *name, char *buf, off_t len); |
883
aca8323e2690
Add posix headers to toynet.h, move xioctl() to lib.c, introduce lib/net.c and move xsocket() to it.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
117 int xioctl(int fd, int request, void *data); |
4
732b055e17f7
Add xmsprintf(), xgetcwd(), xgetcwd(), find_in_path().
landley@driftwood
parents:
3
diff
changeset
|
118 char *xgetcwd(void); |
95
a636e4d20f13
Add xstat(), read_dirtree(), and read_dirtree_node().
Rob Landley <rob@landley.net>
parents:
75
diff
changeset
|
119 void xstat(char *path, struct stat *st); |
708
50d759f8b371
Remove readlink -m for being poorly defined ("readlink -m /dev/null/and/more" answers what question, exactly?), rewrite xabspath() to work right and not depend on realpath, fix subtle longstanding bug in llist_traverse().
Rob Landley <rob@landley.net>
parents:
707
diff
changeset
|
120 char *xabspath(char *path, int exact); |
292
b4077be6c746
Update mdev to work around the newest sysfs api breakage in the 2.6.25 kernel.
Rob Landley <rob@landley.net>
parents:
284
diff
changeset
|
121 void xchdir(char *path); |
1156
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1145
diff
changeset
|
122 void xchroot(char *path); |
1129
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1115
diff
changeset
|
123 struct passwd *xgetpwuid(uid_t uid); |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1115
diff
changeset
|
124 struct group *xgetgrgid(gid_t gid); |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
125 struct passwd *xgetpwnam(char *name); |
1420
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1416
diff
changeset
|
126 struct group *xgetgrnam(char *name); |
1156
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1145
diff
changeset
|
127 void xsetuser(struct passwd *pwd); |
951
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
128 char *xreadlink(char *name); |
952
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
129 long xparsetime(char *arg, long units, long *fraction); |
1028 | 130 void xpidfile(char *name); |
1235
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
131 void xregcomp(regex_t *preg, char *rexec, int cflags); |
951
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
132 |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
133 // lib.c |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
134 void verror_msg(char *msg, int err, va_list va); |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
135 void error_msg(char *msg, ...); |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
136 void perror_msg(char *msg, ...); |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
137 void error_exit(char *msg, ...) noreturn; |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
138 void perror_exit(char *msg, ...) noreturn; |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
139 ssize_t readall(int fd, void *buf, size_t len); |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
140 ssize_t writeall(int fd, void *buf, size_t len); |
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
141 off_t lskip(int fd, off_t offset); |
1219
468444e5c7c5
Move mkpathat to lib, remove redundant function used by patch.
Rob Landley <rob@landley.net>
parents:
1197
diff
changeset
|
142 int mkpathat(int atfd, char *dir, mode_t lastmode, int flags); |
951
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
143 struct string_list **splitpath(char *path, struct string_list **list); |
1043
acf7bb2b99e2
Introduce libbuf analogous to toybuf but for use by lib/*.c. Change readfile() semantics to be able to read into an existing buffer, or malloc its own if that's NULL.
Rob Landley <rob@landley.net>
parents:
1042
diff
changeset
|
144 char *readfile(char *name, char *buf, off_t len); |
951
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
145 void msleep(long miliseconds); |
1399
a0c328bc2c14
Little endian and big endian versions of peek (for host.c).
Rob Landley <rob@landley.net>
parents:
1363
diff
changeset
|
146 int64_t peek_le(void *ptr, unsigned size); |
a0c328bc2c14
Little endian and big endian versions of peek (for host.c).
Rob Landley <rob@landley.net>
parents:
1363
diff
changeset
|
147 int64_t peek_be(void *ptr, unsigned size); |
a0c328bc2c14
Little endian and big endian versions of peek (for host.c).
Rob Landley <rob@landley.net>
parents:
1363
diff
changeset
|
148 int64_t peek(void *ptr, unsigned size); |
951
62d59b8aea34
Split lib/xwrap.c from lib/lib.c
Rob Landley <rob@landley.net>
parents:
948
diff
changeset
|
149 void poke(void *ptr, uint64_t val, int size); |
20
3981c96f9285
Implement which. Add hello world to menuconfig. Wrap the various applet main
Rob Landley <rob@landley.net>
parents:
16
diff
changeset
|
150 struct string_list *find_in_path(char *path, char *filename); |
102
aa4fa2543a65
Add atolx() which understands extensions for kilobytes and megabytes and such.
Rob Landley <rob@landley.net>
parents:
97
diff
changeset
|
151 long atolx(char *c); |
1131
f9678ea553c8
Oops, cleaned up ifconfig uses atolx_range() instead of get_int_list(). Check that in.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
152 long atolx_range(char *numstr, long low, long high); |
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:
551
diff
changeset
|
153 int numlen(long l); |
623
f51beec92738
New infrastructure for od (oops).
Rob Landley <rob@landley.net>
parents:
607
diff
changeset
|
154 int stridx(char *haystack, char needle); |
1525
95cb37adb024
Factor out printf-style escape parsing logic from echo.c.
Rob Landley <rob@landley.net>
parents:
1472
diff
changeset
|
155 int unescape(char c); |
1345
b7598d21ca10
Forgot to check in strstart().
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
156 int strstart(char **a, char *b); |
75
89ca591a9236
More random progress on mke2fs. Nothing to see yet.
Rob Landley <rob@landley.net>
parents:
70
diff
changeset
|
157 off_t fdlength(int fd); |
397
b7afbc6b753a
Forgot to check in loopfiles_rw changes needed by truncate.
Rob Landley <rob@landley.net>
parents:
370
diff
changeset
|
158 void loopfiles_rw(char **argv, int flags, int permissions, int failok, |
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:
658
diff
changeset
|
159 void (*function)(int fd, char *name)); |
185
29e2051296fd
Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents:
167
diff
changeset
|
160 void loopfiles(char **argv, void (*function)(int fd, char *name)); |
284
603275a05524
Teach get_rawline() to continue until a configurable char, and xstrndup()
Rob Landley <rob@landley.net>
parents:
263
diff
changeset
|
161 char *get_rawline(int fd, long *plen, char end); |
201
5d523752715a
Start of "patch" support. Writes to stdout at the moment.
Rob Landley <rob@landley.net>
parents:
185
diff
changeset
|
162 char *get_line(int fd); |
5d523752715a
Start of "patch" support. Writes to stdout at the moment.
Rob Landley <rob@landley.net>
parents:
185
diff
changeset
|
163 void xsendfile(int in, int out); |
590
7becb497c3c4
Update chmod to work with new dirtree, and fix bugs in string_to_mode().
Rob Landley <rob@landley.net>
parents:
589
diff
changeset
|
164 int wfchmodat(int rc, char *name, mode_t mode); |
209 | 165 int copy_tempfile(int fdin, char *name, char **tempname); |
166 void delete_tempfile(int fdin, int fdout, char **tempname); | |
167 void replace_tempfile(int fdin, int fdout, char **tempname); | |
337
aaafa1ceaa91
Add -N, -I, -L, and -P options to cksum.
Rob Landley <rob@landley.net>
parents:
334
diff
changeset
|
168 void crc_init(unsigned int *crc_table, int little_endian); |
1607
eee7dfe95a8f
Forgot to check in a header file for base64.
Rob Landley <rob@landley.net>
parents:
1600
diff
changeset
|
169 void base64_init(char *p); |
1108
fb8467436e6a
Tweak terminal_size to never set either to 0, and return true/false whether it could determine at least one coordinate.
Rob Landley <rob@landley.net>
parents:
1089
diff
changeset
|
170 int terminal_size(unsigned *x, unsigned *y); |
503
3b9dea897dc0
Upgrade yesno() and make cp -i use it.
Rob Landley <rob@landley.net>
parents:
498
diff
changeset
|
171 int yesno(char *prompt, int def); |
1276
d48bdc1cb017
Switch human_readable() to just outputing decimal kilo/mega/gigabytes, make du use it, move it from lib/pending.c to lib.c.
Rob Landley <rob@landley.net>
parents:
1235
diff
changeset
|
172 int human_readable(char *buf, unsigned long long num); |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
173 |
883
aca8323e2690
Add posix headers to toynet.h, move xioctl() to lib.c, introduce lib/net.c and move xsocket() to it.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
174 // net.c |
aca8323e2690
Add posix headers to toynet.h, move xioctl() to lib.c, introduce lib/net.c and move xsocket() to it.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
175 int xsocket(int domain, int type, int protocol); |
1607
eee7dfe95a8f
Forgot to check in a header file for base64.
Rob Landley <rob@landley.net>
parents:
1600
diff
changeset
|
176 void xsetsockopt(int fd, int level, int opt, void *val, socklen_t len); |
883
aca8323e2690
Add posix headers to toynet.h, move xioctl() to lib.c, introduce lib/net.c and move xsocket() to it.
Rob Landley <rob@landley.net>
parents:
870
diff
changeset
|
177 |
1363 | 178 // password.c |
179 int get_salt(char *salt, char * algo); | |
180 | |
3
266a462ed18c
Next drop of toysh, plus more infratructure.
landley@driftwood
parents:
2
diff
changeset
|
181 // getmountlist.c |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
182 struct mtab_list { |
1321
4d898affda0c
Switch mtab_list to doubly linked so we can traverse in either order. Convert umount and df. Add dlist_terminate() to break lists for traversal in either direction.
Rob Landley <rob@landley.net>
parents:
1320
diff
changeset
|
183 struct mtab_list *next, *prev; |
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:
658
diff
changeset
|
184 struct stat 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:
658
diff
changeset
|
185 struct statvfs statvfs; |
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:
658
diff
changeset
|
186 char *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:
658
diff
changeset
|
187 char *device; |
1320
b2cc738d3cfc
Add mount options to data getmountlist collects.
Rob Landley <rob@landley.net>
parents:
1299
diff
changeset
|
188 char *opts; |
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:
658
diff
changeset
|
189 char type[0]; |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
190 }; |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
191 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1420
diff
changeset
|
192 void comma_collate(char **old, char *new); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1420
diff
changeset
|
193 char *comma_iterate(char **list, int *len); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1420
diff
changeset
|
194 int comma_scan(char *optlist, char *opt, int clean); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1420
diff
changeset
|
195 int comma_scanall(char *optlist, char *scanlist); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1420
diff
changeset
|
196 int mountlist_istype(struct mtab_list *ml, char *typelist); |
1033
11cf9b97fae7
Allow getmountlist to read fstab too.
Rob Landley <rob@landley.net>
parents:
1028
diff
changeset
|
197 struct mtab_list *xgetmountlist(char *path); |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
198 |
498
c9aaceccd6bd
Factor out common code between killall/kill and move it to lib/lib.c, plus cleanups on kill.c.
Rob Landley <rob@landley.net>
parents:
478
diff
changeset
|
199 // signal |
c9aaceccd6bd
Factor out common code between killall/kill and move it to lib/lib.c, plus cleanups on kill.c.
Rob Landley <rob@landley.net>
parents:
478
diff
changeset
|
200 |
1299
313980d3d78c
Add generic_signal() handler, which sets toys.signal and writes byte to toys.signalfd if set.
Rob Landley <rob@landley.net>
parents:
1295
diff
changeset
|
201 void generic_signal(int signal); |
643
7bdebd2af1d6
Add signal handler to clean up tempfile.
Rob Landley <rob@landley.net>
parents:
637
diff
changeset
|
202 void sigatexit(void *handler); |
498
c9aaceccd6bd
Factor out common code between killall/kill and move it to lib/lib.c, plus cleanups on kill.c.
Rob Landley <rob@landley.net>
parents:
478
diff
changeset
|
203 int sig_to_num(char *pidstr); |
c9aaceccd6bd
Factor out common code between killall/kill and move it to lib/lib.c, plus cleanups on kill.c.
Rob Landley <rob@landley.net>
parents:
478
diff
changeset
|
204 char *num_to_sig(int sig); |
551
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
540
diff
changeset
|
205 |
2548e6e590b2
Add string to mode_t parser
Daniel Walter <d.walter@0x90.at>
parents:
540
diff
changeset
|
206 mode_t string_to_mode(char *mode_str, mode_t base); |
916 | 207 void mode_to_string(mode_t mode, char *buf); |
1145
80c9df5145fe
Move names_to_pid from pending to lib.
Rob Landley <rob@landley.net>
parents:
1131
diff
changeset
|
208 void names_to_pid(char **names, int (*callback)(pid_t pid, char *name)); |
626 | 209 |
1235
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
210 // Functions in need of further review/cleanup |
1115
349424387e22
Break out lib/pending.h from lib/lib.h.
Rob Landley <rob@landley.net>
parents:
1108
diff
changeset
|
211 #include "lib/pending.h" |