1 /* Toybox infrastructure.
3 * Copyright 2006 Rob Landley <rob@landley.net>
6 #include "generated/config.h"
8 #include "lib/portability.h"
32 #include <sys/ioctl.h>
34 #include <sys/mount.h>
35 #include <sys/resource.h>
37 #include <sys/statfs.h>
38 #include <sys/statvfs.h>
39 #include <sys/sysinfo.h>
42 #include <sys/times.h>
43 #include <sys/types.h>
44 #include <sys/utsname.h>
52 // Internationalization support
59 #include "toys/e2fs.h"
61 // Get list of function prototypes for all enabled command_main() functions.
63 #define NEWTOY(name, opts, flags) void name##_main(void);
64 #define OLDTOY(name, oldname, opts, flags)
65 #include "generated/newtoys.h"
66 #include "generated/globals.h"
68 // These live in main.c
70 struct toy_list *toy_find(char *name);
71 void toy_init(struct toy_list *which, char *argv[]);
72 void toy_exec(char *argv[]);
74 // Flags describing command behavior.
76 #define TOYFLAG_USR (1<<0)
77 #define TOYFLAG_BIN (1<<1)
78 #define TOYFLAG_SBIN (1<<2)
79 #define TOYMASK_LOCATION ((1<<4)-1)
81 // This is a shell built-in function, running in the same process context.
82 #define TOYFLAG_NOFORK (1<<4)
84 // Start command with a umask of 0 (saves old umask in this.old_umask)
85 #define TOYFLAG_UMASK (1<<5)
87 // This command runs as root.
88 #define TOYFLAG_STAYROOT (1<<6)
89 #define TOYFLAG_NEEDROOT (1<<7)
90 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
92 // Array of available applets
94 extern struct toy_list {
96 void (*toy_main)(void);
101 // Global context shared by all commands.
103 extern struct toy_context {
104 struct toy_list *which; // Which entry in toy_list is this one?
105 int exitval; // Value error_exit feeds to exit()
106 char **argv; // Original command line arguments
107 unsigned optflags; // Command line option flags from get_optflags()
108 char **optargs; // Arguments left over from get_optflags()
109 int optc; // Count of optargs
110 int exithelp; // Should error_exit print a usage message first?
111 int old_umask; // Old umask preserved by TOYFLAG_UMASK
112 jmp_buf *rebound; // longjmp here instead of exit when do_rebound set
115 // One big temporary buffer, for use by commands (not library functions).
117 extern char toybuf[4096];
121 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))