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/statvfs.h>
38 #include <sys/sysinfo.h>
40 #include <sys/times.h>
41 #include <sys/types.h>
42 #include <sys/utsname.h>
53 #include "toys/e2fs.h"
55 // Get list of function prototypes for all enabled command_main() functions.
57 #define NEWTOY(name, opts, flags) void name##_main(void);
58 #define OLDTOY(name, oldname, opts, flags)
59 #include "generated/newtoys.h"
60 #include "generated/globals.h"
62 // These live in main.c
64 struct toy_list *toy_find(char *name);
65 void toy_init(struct toy_list *which, char *argv[]);
66 void toy_exec(char *argv[]);
68 // Flags describing command behavior.
70 #define TOYFLAG_USR (1<<0)
71 #define TOYFLAG_BIN (1<<1)
72 #define TOYFLAG_SBIN (1<<2)
73 #define TOYMASK_LOCATION ((1<<4)-1)
75 // This is a shell built-in function, running in the same process context.
76 #define TOYFLAG_NOFORK (1<<4)
78 // Start command with a umask of 0 (saves old umask in this.old_umask)
79 #define TOYFLAG_UMASK (1<<5)
81 // This command runs as root.
82 #define TOYFLAG_STAYROOT (1<<6)
83 #define TOYFLAG_NEEDROOT (1<<7)
84 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
86 // Array of available applets
88 extern struct toy_list {
90 void (*toy_main)(void);
95 // Global context shared by all commands.
97 extern struct toy_context {
98 struct toy_list *which; // Which entry in toy_list is this one?
99 int exitval; // Value error_exit feeds to exit()
100 char **argv; // Original command line arguments
101 unsigned optflags; // Command line option flags from get_optflags()
102 char **optargs; // Arguments left over from get_optflags()
103 int optc; // Count of optargs
104 int exithelp; // Should error_exit print a usage message first?
105 int old_umask; // Old umask preserved by TOYFLAG_UMASK
108 // One big temporary buffer, for use by commands (not library functions).
110 extern char toybuf[4096];
114 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))