annotate toys.h @ 1572:da1bf31ed322 draft

Tweak the "ignoring return value" fortify workaround for readlinkat. We zero the buffer and if the link read fails that's left alone, so it's ok for the symlink not to be there. Unfortunately, typecasting the return value to (void) doesn't shut up gcc, and having an if(); with the semicolon on the same line doesn't shut up llvm. (The semicolon on a new line would, but C does not have significant whitespace and I'm not going to humor llvm if it plans to start.) So far, empty curly brackets consistently get the warning to shut up.
author Rob Landley <rob@landley.net>
date Mon, 24 Nov 2014 17:23:23 -0600
parents 685a0da6ca59
children aafd2f28245a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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: 1232
diff changeset
6 // Stuff that needs to go before the standard headers
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: 1232
diff changeset
7
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
8 #include "generated/config.h"
63
69efffcacd70 Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents: 53
diff changeset
9 #include "lib/portability.h"
69efffcacd70 Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents: 53
diff changeset
10
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: 1232
diff changeset
11 // General posix-2008 headers
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
12 #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
13 #include <dirent.h>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
14 #include <errno.h>
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
15 #include <fcntl.h>
1249
b13728c24a58 modprobe: cleanup, incorporate Ashwini's fix for alias loading
Isaac Dunham <ibid.ag@gmail.com>
parents: 1235
diff changeset
16 #include <fnmatch.h>
114
ce6956dfc0cf Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
17 #include <grp.h>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
18 #include <inttypes.h>
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
19 #include <limits.h>
533
31215cc6c9f2 Consolidate headers.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
20 #include <libgen.h>
31215cc6c9f2 Consolidate headers.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
21 #include <math.h>
114
ce6956dfc0cf Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
22 #include <pwd.h>
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: 1232
diff changeset
23 #include <regex.h>
533
31215cc6c9f2 Consolidate headers.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
24 #include <sched.h>
37
14d27eab3acf Add my old micro-bunzip library. Needs some cleanup...
Rob Landley <rob@landley.net>
parents: 35
diff changeset
25 #include <setjmp.h>
1299
313980d3d78c Add generic_signal() handler, which sets toys.signal and writes byte to toys.signalfd if set.
Rob Landley <rob@landley.net>
parents: 1274
diff changeset
26 #include <signal.h>
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
27 #include <stdarg.h>
696
99ca30ad3d2b Add rebound support to intercept error_exit() and longjmp instead.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
28 #include <stddef.h>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
29 #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
30 #include <stdio.h>
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
31 #include <stdlib.h>
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
32 #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
33 #include <strings.h>
114
ce6956dfc0cf Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
34 #include <sys/mman.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>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
37 #include <sys/statvfs.h>
728
dfeb3daad8f3 Add header that musl libc needs.
Rob Landley <rob@landley.net>
parents: 712
diff changeset
38 #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
39 #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
40 #include <sys/types.h>
533
31215cc6c9f2 Consolidate headers.
Rob Landley <rob@landley.net>
parents: 482
diff changeset
41 #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
42 #include <sys/wait.h>
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 564
diff changeset
43 #include <syslog.h>
1564
685a0da6ca59 probe for getspnam(), forkpty(), utmpx, replace sethostname()
Isaac Dunham <ibid.ag@gmail.com>
parents: 1534
diff changeset
44 #include <termios.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
45 #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
46 #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
47 #include <utime.h>
710
cfdaead45479 Make internalization support optional
Felix Janda <felix.janda@posteo.de>
parents: 696
diff changeset
48
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: 1232
diff changeset
49 // Posix networking
1104
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
50
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
51 #include <arpa/inet.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
52 #include <netdb.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
53 #include <net/if.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
54 #include <netinet/in.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
55 #include <netinet/tcp.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
56 #include <poll.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
57 #include <sys/socket.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
58 #include <sys/un.h>
e11684e3bbc5 Merge toynet.h into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
Rob Landley <rob@landley.net>
parents: 1076
diff changeset
59
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: 1232
diff changeset
60 // Internationalization support (also in POSIX and LSB)
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: 1232
diff changeset
61
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: 1232
diff changeset
62 #include <locale.h>
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: 1232
diff changeset
63 #include <wchar.h>
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: 1232
diff changeset
64 #include <wctype.h>
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: 1232
diff changeset
65
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: 1232
diff changeset
66 // LSB 4.1 headers
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: 1232
diff changeset
67 #include <sys/ioctl.h>
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: 1232
diff changeset
68 #include <sys/statfs.h>
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: 1232
diff changeset
69 #include <sys/sysinfo.h>
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: 1232
diff changeset
70
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
71 #include "lib/lib.h"
82
612c8d6c2829 More work on mke2fs.
Rob Landley <rob@landley.net>
parents: 76
diff changeset
72 #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
73
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
74 // 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
75
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
76 #define NEWTOY(name, opts, flags) void name##_main(void);
1502
84922376d15c Have OLDTOY emit (redundant) function prototype so single.sh can build OLDTOY standalone (if it has its own config symbol).
Rob Landley <rob@landley.net>
parents: 1467
diff changeset
77 #define OLDTOY(name, oldname, opts, flags) void oldname##_main(void);
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
78 #include "generated/newtoys.h"
1006
d7bd69bec519 Forgot to check in toys.h when generated/oldtoys.h went in. (Oops.)
Rob Landley <rob@landley.net>
parents: 873
diff changeset
79 #include "generated/oldtoys.h"
1076
1c15ba60aa64 Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents: 1043
diff changeset
80 #include "generated/flags.h"
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
81 #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
82
21
6475d6c46066 Add pwd. Consolidate toy list information under toylist.h.
Rob Landley <rob@landley.net>
parents: 20
diff changeset
83 // 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
84
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
85 struct toy_list *toy_find(char *name);
3
266a462ed18c Next drop of toysh, plus more infratructure.
landley@driftwood
parents: 2
diff changeset
86 void toy_init(struct toy_list *which, char *argv[]);
266a462ed18c Next drop of toysh, plus more infratructure.
landley@driftwood
parents: 2
diff changeset
87 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
88
564
9530899eee51 Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents: 541
diff changeset
89 // 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
90
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
91 #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
92 #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
93 #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
94 #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
95
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
96 // 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
97 #define TOYFLAG_NOFORK (1<<4)
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
98
564
9530899eee51 Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents: 541
diff changeset
99 // Start command with a umask of 0 (saves old umask in this.old_umask)
257
951110c37fee Add TOYFLAG_UMASK.
Rob Landley <rob@landley.net>
parents: 255
diff changeset
100 #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
101
564
9530899eee51 Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents: 541
diff changeset
102 // This command runs as root.
370
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
103 #define TOYFLAG_STAYROOT (1<<6)
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
104 #define TOYFLAG_NEEDROOT (1<<7)
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
105 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
106
1342
3b85d2ce34aa When locale is enabled, sprintf("%.123s", str) is counting characters, not bytes, so we can't globally enable locale without opening stack/heap smashing vulnerabilities. Make commands individually request setlocale() using TOYFLAGS instead.
Rob Landley <rob@landley.net>
parents: 1299
diff changeset
107 // Call setlocale to listen to environment variables.
3b85d2ce34aa When locale is enabled, sprintf("%.123s", str) is counting characters, not bytes, so we can't globally enable locale without opening stack/heap smashing vulnerabilities. Make commands individually request setlocale() using TOYFLAGS instead.
Rob Landley <rob@landley.net>
parents: 1299
diff changeset
108 // This invalidates sprintf("%.*s", size, string) as a valid length constraint.
3b85d2ce34aa When locale is enabled, sprintf("%.123s", str) is counting characters, not bytes, so we can't globally enable locale without opening stack/heap smashing vulnerabilities. Make commands individually request setlocale() using TOYFLAGS instead.
Rob Landley <rob@landley.net>
parents: 1299
diff changeset
109 #define TOYFLAG_LOCALE (1<<8)
3b85d2ce34aa When locale is enabled, sprintf("%.123s", str) is counting characters, not bytes, so we can't globally enable locale without opening stack/heap smashing vulnerabilities. Make commands individually request setlocale() using TOYFLAGS instead.
Rob Landley <rob@landley.net>
parents: 1299
diff changeset
110
873
d90f14e011b8 Fix some comments from way back when toybox first started (in 2006), when I was still cleaning busybox-isms out of my head...
Rob Landley <rob@landley.net>
parents: 747
diff changeset
111 // Array of available commands
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
112
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
113 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
114 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
115 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
116 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
117 int flags;
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
118 } toy_list[];
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
119
564
9530899eee51 Comment and whitespace changes.
Rob Landley <rob@landley.net>
parents: 541
diff changeset
120 // 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
121
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
122 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
123 struct toy_list *which; // Which entry in toy_list is this one?
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
124 char **argv; // Original command line arguments
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
125 char **optargs; // Arguments left over from get_optflags()
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
126 unsigned optflags; // Command line option flags from get_optflags()
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
127 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
128 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
129 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
130 int old_umask; // Old umask preserved by TOYFLAG_UMASK
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 1104
diff changeset
131 int toycount; // Total number of commands in this build
1299
313980d3d78c Add generic_signal() handler, which sets toys.signal and writes byte to toys.signalfd if set.
Rob Landley <rob@landley.net>
parents: 1274
diff changeset
132 int signal; // generic_signal() records what signal it saw here
313980d3d78c Add generic_signal() handler, which sets toys.signal and writes byte to toys.signalfd if set.
Rob Landley <rob@landley.net>
parents: 1274
diff changeset
133 int signalfd; // and writes signal to this fd, if set
1274
c47218ccbfdf Fix bug reported by Ashwini Sharma: rebound has to be at the end or toy_init() doesn't zero the rest of the struct.
Rob Landley <rob@landley.net>
parents: 1249
diff changeset
134
c47218ccbfdf Fix bug reported by Ashwini Sharma: rebound has to be at the end or toy_init() doesn't zero the rest of the struct.
Rob Landley <rob@landley.net>
parents: 1249
diff changeset
135 // This is at the end so toy_init() doesn't zero it.
c47218ccbfdf Fix bug reported by Ashwini Sharma: rebound has to be at the end or toy_init() doesn't zero the rest of the struct.
Rob Landley <rob@landley.net>
parents: 1249
diff changeset
136 jmp_buf *rebound; // longjmp here instead of exit when do_rebound set
1534
83cac28515a3 xexec() recursion limiter has to go after rebound or toy_init() zeroes it.
Rob Landley <rob@landley.net>
parents: 1502
diff changeset
137 int recursion; // How many nested calls to toy_exec()
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
138 } toys;
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents: 21
diff changeset
139
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: 1008
diff changeset
140 // Two big temporary buffers: one for use by commands, one for 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
141
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: 1008
diff changeset
142 extern char toybuf[4096], libbuf[4096];
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
143
1008
a55854bde872 su: cleanery
Strake <strake888@gmail.com>
parents: 1006
diff changeset
144 extern char **environ;
a55854bde872 su: cleanery
Strake <strake888@gmail.com>
parents: 1006
diff changeset
145
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
146 #define GLOBALS(...)
647
3258d9233753 Replace TOY_LIST_LEN with more generic ARRAY_LEN()
Rob Landley <rob@landley.net>
parents: 627
diff changeset
147
3258d9233753 Replace TOY_LIST_LEN with more generic ARRAY_LEN()
Rob Landley <rob@landley.net>
parents: 627
diff changeset
148 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))