2 /* Toybox infrastructure.
4 * Copyright 2006 Rob Landley <rob@landley.net>
6 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
9 #include "generated/config.h"
11 #include "lib/portability.h"
28 #include <sys/ioctl.h>
30 #include <sys/mount.h>
32 #include <sys/statvfs.h>
33 #include <sys/types.h>
38 #define _XOPEN_SOURCE 600
42 #include "toys/e2fs.h"
44 // Get list of function prototypes for all enabled command_main() functions.
46 #define NEWTOY(name, opts, flags) void name##_main(void);
47 #define OLDTOY(name, oldname, opts, flags)
48 #include "generated/newtoys.h"
49 #include "generated/globals.h"
51 // These live in main.c
53 struct toy_list *toy_find(char *name);
54 void toy_init(struct toy_list *which, char *argv[]);
55 void toy_exec(char *argv[]);
57 // Flags describing applet behavior.
59 #define TOYFLAG_USR (1<<0)
60 #define TOYFLAG_BIN (1<<1)
61 #define TOYFLAG_SBIN (1<<2)
62 #define TOYMASK_LOCATION ((1<<4)-1)
64 // This is a shell built-in function, running in the same process context.
65 #define TOYFLAG_NOFORK (1<<4)
67 // Start applet with a umask of 0 (saves old umask in this.old_umask)
68 #define TOYFLAG_UMASK (1<<5)
70 // Array of available applets
72 extern struct toy_list {
74 void (*toy_main)(void);
79 // Global context shared by all applets.
81 extern struct toy_context {
82 struct toy_list *which; // Which entry in toy_list is this one?
83 int exitval; // Value error_exit feeds to exit()
84 char **argv; // Original command line arguments
85 unsigned optflags; // Command line option flags from get_optflags()
86 char **optargs; // Arguments left over from get_optflags()
87 int optc; // Count of optargs
88 int exithelp; // Should error_exit print a usage message first?
89 int old_umask; // Old umask preserved by TOYFLAG_UMASK
92 // One big temporary buffer, for use by applets (not library functions).
94 extern char toybuf[4096];
96 #define DEFINE_GLOBALS(...)