Mercurial > hg > toybox
annotate toys.h @ 818:264b9da809df
Simplify license text, as mentioned on the mailing list.
Reasoning: it was never my intent to require anybody to copy license
text into another project if they cut and pasted something out of
toybox. The "permission for any purpose" is as close to public domain
as you can get in our current screwed up legal system without making
people uncomfortable the _other_ way. (Besides, my initial reading of
that was "all copies of the source code" but that's not what it says,
and somebody pointed out that Android has "show license text" options
because paranoid lawyers think that sort of thing applies to the BINARY
version, which is nuts.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 14 Mar 2013 09:02:37 -0500 |
parents | 68d6c1ce7bba |
children | d90f14e011b8 |
rev | line source |
---|---|
1
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
1 /* Toybox infrastructure. |
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
2 * |
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
3 * Copyright 2006 Rob Landley <rob@landley.net> |
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
4 */ |
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
5 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
232
diff
changeset
|
6 #include "generated/config.h" |
94
884c03c29f21
Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents:
82
diff
changeset
|
7 |
63
69efffcacd70
Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents:
53
diff
changeset
|
8 #include "lib/portability.h" |
69efffcacd70
Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents:
53
diff
changeset
|
9 |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
10 #include <ctype.h> |
94
884c03c29f21
Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents:
82
diff
changeset
|
11 #include <dirent.h> |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
12 #include <errno.h> |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
13 #include <fcntl.h> |
114
ce6956dfc0cf
Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents:
94
diff
changeset
|
14 #include <grp.h> |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
15 #include <inttypes.h> |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
16 #include <limits.h> |
533 | 17 #include <libgen.h> |
18 #include <math.h> | |
321
dfbfbaeb69c9
Add netcat server mode, -l, -L, and -t.
Rob Landley <rob@landley.net>
parents:
257
diff
changeset
|
19 #include <pty.h> |
114
ce6956dfc0cf
Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents:
94
diff
changeset
|
20 #include <pwd.h> |
533 | 21 #include <sched.h> |
37
14d27eab3acf
Add my old micro-bunzip library. Needs some cleanup...
Rob Landley <rob@landley.net>
parents:
35
diff
changeset
|
22 #include <setjmp.h> |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
600
diff
changeset
|
23 #include <sched.h> |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
564
diff
changeset
|
24 #include <shadow.h> |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
25 #include <stdarg.h> |
696
99ca30ad3d2b
Add rebound support to intercept error_exit() and longjmp instead.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
26 #include <stddef.h> |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
27 #include <stdint.h> |
1
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
28 #include <stdio.h> |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
29 #include <stdlib.h> |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
30 #include <string.h> |
574
d8effa95a5f0
Georgi pointed out that some overly-pedantic C libraries require you to include both "string.h" and "strings.h". (Most don't.)
Rob Landley <rob@landley.net>
parents:
572
diff
changeset
|
31 #include <strings.h> |
53
41d55b5d49fd
Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
37
diff
changeset
|
32 #include <sys/ioctl.h> |
114
ce6956dfc0cf
Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents:
94
diff
changeset
|
33 #include <sys/mman.h> |
75
89ca591a9236
More random progress on mke2fs. Nothing to see yet.
Rob Landley <rob@landley.net>
parents:
63
diff
changeset
|
34 #include <sys/mount.h> |
541
ff71169e8440
Yet another header for technical susv4 compliance.
Rob Landley <rob@landley.net>
parents:
533
diff
changeset
|
35 #include <sys/resource.h> |
4
732b055e17f7
Add xmsprintf(), xgetcwd(), xgetcwd(), find_in_path().
landley@driftwood
parents:
3
diff
changeset
|
36 #include <sys/stat.h> |
747
68d6c1ce7bba
Add stat submission to new "pending" directory, along with infrastructure to support pending.
Rob Landley <rob@landley.net>
parents:
728
diff
changeset
|
37 #include <sys/statfs.h> |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
38 #include <sys/statvfs.h> |
471
35f6a1bd1417
Sigh: moving a header to toys.h isn't very useful if I forget to check in toys.h.
Rob Landley <rob@landley.net>
parents:
427
diff
changeset
|
39 #include <sys/sysinfo.h> |
482
b4a9fd8773d6
Adding swapon and swapoff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
471
diff
changeset
|
40 #include <sys/swap.h> |
728
dfeb3daad8f3
Add header that musl libc needs.
Rob Landley <rob@landley.net>
parents:
712
diff
changeset
|
41 #include <sys/time.h> |
600
58d2fd7484bd
More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
Rob Landley <rob@landley.net>
parents:
574
diff
changeset
|
42 #include <sys/times.h> |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
43 #include <sys/types.h> |
533 | 44 #include <sys/utsname.h> |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
4
diff
changeset
|
45 #include <sys/wait.h> |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
564
diff
changeset
|
46 #include <syslog.h> |
600
58d2fd7484bd
More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
Rob Landley <rob@landley.net>
parents:
574
diff
changeset
|
47 #include <time.h> |
218
bc87305c391f
Make touch work reliably when file doesn't exist and clean up headers a bit.
Rob Landley <rob@landley.net>
parents:
145
diff
changeset
|
48 #include <unistd.h> |
bc87305c391f
Make touch work reliably when file doesn't exist and clean up headers a bit.
Rob Landley <rob@landley.net>
parents:
145
diff
changeset
|
49 #include <utime.h> |
533 | 50 #include <utmpx.h> |
710
cfdaead45479
Make internalization support optional
Felix Janda <felix.janda@posteo.de>
parents:
696
diff
changeset
|
51 |
712
a950dd960593
Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents:
710
diff
changeset
|
52 // Internationalization support |
a950dd960593
Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents:
710
diff
changeset
|
53 |
710
cfdaead45479
Make internalization support optional
Felix Janda <felix.janda@posteo.de>
parents:
696
diff
changeset
|
54 #include <locale.h> |
686
9414be56b1db
wc -m only cares about counting characters. Attached is a try on implementing it and some test cases for it. The test cases are only for UTF-8 locales.
Felix Janda <felix.janda@posteo.de>
parents:
674
diff
changeset
|
55 #include <wchar.h> |
9414be56b1db
wc -m only cares about counting characters. Attached is a try on implementing it and some test cases for it. The test cases are only for UTF-8 locales.
Felix Janda <felix.janda@posteo.de>
parents:
674
diff
changeset
|
56 #include <wctype.h> |
218
bc87305c391f
Make touch work reliably when file doesn't exist and clean up headers a bit.
Rob Landley <rob@landley.net>
parents:
145
diff
changeset
|
57 |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
58 #include "lib/lib.h" |
82 | 59 #include "toys/e2fs.h" |
1
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
60 |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
61 // Get list of function prototypes for all enabled command_main() functions. |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
62 |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
63 #define NEWTOY(name, opts, flags) void name##_main(void); |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
64 #define OLDTOY(name, oldname, opts, flags) |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
65 #include "generated/newtoys.h" |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
66 #include "generated/globals.h" |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
67 |
21
6475d6c46066
Add pwd. Consolidate toy list information under toylist.h.
Rob Landley <rob@landley.net>
parents:
20
diff
changeset
|
68 // These live in main.c |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
69 |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
70 struct toy_list *toy_find(char *name); |
3
266a462ed18c
Next drop of toysh, plus more infratructure.
landley@driftwood
parents:
2
diff
changeset
|
71 void toy_init(struct toy_list *which, char *argv[]); |
266a462ed18c
Next drop of toysh, plus more infratructure.
landley@driftwood
parents:
2
diff
changeset
|
72 void toy_exec(char *argv[]); |
1
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
73 |
564
9530899eee51
Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents:
541
diff
changeset
|
74 // Flags describing command behavior. |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
75 |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
76 #define TOYFLAG_USR (1<<0) |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
77 #define TOYFLAG_BIN (1<<1) |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
78 #define TOYFLAG_SBIN (1<<2) |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
79 #define TOYMASK_LOCATION ((1<<4)-1) |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
80 |
345 | 81 // This is a shell built-in function, running in the same process context. |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
82 #define TOYFLAG_NOFORK (1<<4) |
345 | 83 |
564
9530899eee51
Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents:
541
diff
changeset
|
84 // Start command with a umask of 0 (saves old umask in this.old_umask) |
257 | 85 #define TOYFLAG_UMASK (1<<5) |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
86 |
564
9530899eee51
Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents:
541
diff
changeset
|
87 // This command runs as root. |
370 | 88 #define TOYFLAG_STAYROOT (1<<6) |
89 #define TOYFLAG_NEEDROOT (1<<7) | |
90 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT) | |
91 | |
345 | 92 // Array of available applets |
93 | |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
94 extern struct toy_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:
686
diff
changeset
|
95 char *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:
686
diff
changeset
|
96 void (*toy_main)(void); |
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:
686
diff
changeset
|
97 char *options; |
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:
686
diff
changeset
|
98 int flags; |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
99 } toy_list[]; |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
100 |
564
9530899eee51
Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents:
541
diff
changeset
|
101 // Global context shared by all commands. |
1
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
102 |
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
103 extern struct toy_context { |
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:
686
diff
changeset
|
104 struct toy_list *which; // Which entry in toy_list is this one? |
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:
686
diff
changeset
|
105 int exitval; // Value error_exit feeds to exit() |
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:
686
diff
changeset
|
106 char **argv; // Original command line arguments |
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:
686
diff
changeset
|
107 unsigned optflags; // Command line option flags from get_optflags() |
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:
686
diff
changeset
|
108 char **optargs; // Arguments left over from get_optflags() |
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:
686
diff
changeset
|
109 int optc; // Count of optargs |
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:
686
diff
changeset
|
110 int exithelp; // Should error_exit print a usage message first? |
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:
686
diff
changeset
|
111 int old_umask; // Old umask preserved by TOYFLAG_UMASK |
696
99ca30ad3d2b
Add rebound support to intercept error_exit() and longjmp instead.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
112 jmp_buf *rebound; // longjmp here instead of exit when do_rebound set |
1
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
113 } toys; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
21
diff
changeset
|
114 |
564
9530899eee51
Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents:
541
diff
changeset
|
115 // One big temporary buffer, for use by commands (not library functions). |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
21
diff
changeset
|
116 |
53
41d55b5d49fd
Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
37
diff
changeset
|
117 extern char toybuf[4096]; |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
118 |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
647
diff
changeset
|
119 #define GLOBALS(...) |
647
3258d9233753
Replace TOY_LIST_LEN with more generic ARRAY_LEN()
Rob Landley <rob@landley.net>
parents:
627
diff
changeset
|
120 |
3258d9233753
Replace TOY_LIST_LEN with more generic ARRAY_LEN()
Rob Landley <rob@landley.net>
parents:
627
diff
changeset
|
121 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array)) |