OSDN Git Service

New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandna...
[android-x86/external-toybox.git] / toys.h
1 /* vi: set ts=4 :*/
2 /* Toybox infrastructure.
3  *
4  * Copyright 2006 Rob Landley <rob@landley.net>
5  */
6
7 #include "generated/config.h"
8
9 #include "lib/portability.h"
10
11 #include <ctype.h>
12 #include <dirent.h>
13 #include <errno.h>
14 #include <fcntl.h>
15 #include <grp.h>
16 #include <inttypes.h>
17 #include <limits.h>
18 #include <libgen.h>
19 #include <math.h>
20 #include <pty.h>
21 #include <pwd.h>
22 #include <sched.h>
23 #include <setjmp.h>
24 #include <sched.h>
25 #include <shadow.h>
26 #include <stdarg.h>
27 #include <stdint.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <strings.h>
32 #include <sys/ioctl.h>
33 #include <sys/mman.h>
34 #include <sys/mount.h>
35 #include <sys/resource.h>
36 #include <sys/stat.h>
37 #include <sys/statvfs.h>
38 #include <sys/sysinfo.h>
39 #include <sys/swap.h>
40 #include <sys/times.h>
41 #include <sys/types.h>
42 #include <sys/utsname.h>
43 #include <sys/wait.h>
44 #include <syslog.h>
45 #include <time.h>
46 #include <unistd.h>
47 #include <utime.h>
48 #include <utmpx.h>
49
50 #include "lib/lib.h"
51 #include "toys/e2fs.h"
52
53 // Get list of function prototypes for all enabled command_main() functions.
54
55 #define NEWTOY(name, opts, flags) void name##_main(void);
56 #define OLDTOY(name, oldname, opts, flags)
57 #include "generated/newtoys.h"
58 #include "generated/globals.h"
59
60 // These live in main.c
61
62 struct toy_list *toy_find(char *name);
63 void toy_init(struct toy_list *which, char *argv[]);
64 void toy_exec(char *argv[]);
65
66 // Flags describing command behavior.
67
68 #define TOYFLAG_USR      (1<<0)
69 #define TOYFLAG_BIN      (1<<1)
70 #define TOYFLAG_SBIN     (1<<2)
71 #define TOYMASK_LOCATION ((1<<4)-1)
72
73 // This is a shell built-in function, running in the same process context.
74 #define TOYFLAG_NOFORK   (1<<4)
75
76 // Start command with a umask of 0 (saves old umask in this.old_umask)
77 #define TOYFLAG_UMASK    (1<<5)
78
79 // This command runs as root.
80 #define TOYFLAG_STAYROOT (1<<6)
81 #define TOYFLAG_NEEDROOT (1<<7)
82 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
83
84 // Array of available applets
85
86 extern struct toy_list {
87         char *name;
88         void (*toy_main)(void);
89         char *options;
90         int flags;
91 } toy_list[];
92
93 // Global context shared by all commands.
94
95 extern struct toy_context {
96         struct toy_list *which;  // Which entry in toy_list is this one?
97         int exitval;             // Value error_exit feeds to exit()
98         char **argv;             // Original command line arguments
99         unsigned optflags;       // Command line option flags from get_optflags()
100         char **optargs;          // Arguments left over from get_optflags()
101         int optc;                // Count of optargs
102         int exithelp;            // Should error_exit print a usage message first?
103         int old_umask;           // Old umask preserved by TOYFLAG_UMASK
104 } toys;
105
106 // One big temporary buffer, for use by commands (not library functions).
107
108 extern char toybuf[4096];
109
110 #define GLOBALS(...)
111
112 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))