OSDN Git Service

modprobe: cleanup, incorporate Ashwini's fix for alias loading
[android-x86/external-toybox.git] / toys.h
1 /* Toybox infrastructure.
2  *
3  * Copyright 2006 Rob Landley <rob@landley.net>
4  */
5
6 // Stuff that needs to go before the standard headers
7
8 #include "generated/config.h"
9 #include "lib/portability.h"
10
11 // General posix-2008 headers
12 #include <ctype.h>
13 #include <dirent.h>
14 #include <errno.h>
15 #include <fcntl.h>
16 #include <fnmatch.h>
17 #include <grp.h>
18 #include <inttypes.h>
19 #include <limits.h>
20 #include <libgen.h>
21 #include <math.h>
22 #include <pwd.h>
23 #include <regex.h>
24 #include <sched.h>
25 #include <setjmp.h>
26 #include <stdarg.h>
27 #include <stddef.h>
28 #include <stdint.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <strings.h>
33 #include <sys/mman.h>
34 #include <sys/resource.h>
35 #include <sys/stat.h>
36 #include <sys/statvfs.h>
37 #include <sys/time.h>
38 #include <sys/times.h>
39 #include <sys/types.h>
40 #include <sys/utsname.h>
41 #include <sys/wait.h>
42 #include <syslog.h>
43 #include <time.h>
44 #include <unistd.h>
45 #include <utime.h>
46 #include <utmpx.h>
47
48 // Posix networking
49
50 #include <arpa/inet.h>
51 #include <netdb.h>
52 #include <net/if.h>
53 #include <netinet/in.h>
54 #include <netinet/tcp.h>
55 #include <poll.h>
56 #include <sys/socket.h>
57 #include <sys/un.h>
58
59 // Internationalization support (also in POSIX and LSB)
60
61 #include <locale.h>
62 #include <wchar.h>
63 #include <wctype.h>
64
65 // LSB 4.1 headers
66 #include <pty.h>
67 #include <sys/ioctl.h>
68 #include <sys/statfs.h>
69 #include <sys/sysinfo.h>
70
71 #include "lib/lib.h"
72 #include "toys/e2fs.h"
73
74 // Get list of function prototypes for all enabled command_main() functions.
75
76 #define NEWTOY(name, opts, flags) void name##_main(void);
77 #define OLDTOY(name, oldname, opts, flags)
78 #include "generated/newtoys.h"
79 #include "generated/oldtoys.h"
80 #include "generated/flags.h"
81 #include "generated/globals.h"
82
83 // These live in main.c
84
85 struct toy_list *toy_find(char *name);
86 void toy_init(struct toy_list *which, char *argv[]);
87 void toy_exec(char *argv[]);
88
89 // Flags describing command behavior.
90
91 #define TOYFLAG_USR      (1<<0)
92 #define TOYFLAG_BIN      (1<<1)
93 #define TOYFLAG_SBIN     (1<<2)
94 #define TOYMASK_LOCATION ((1<<4)-1)
95
96 // This is a shell built-in function, running in the same process context.
97 #define TOYFLAG_NOFORK   (1<<4)
98
99 // Start command with a umask of 0 (saves old umask in this.old_umask)
100 #define TOYFLAG_UMASK    (1<<5)
101
102 // This command runs as root.
103 #define TOYFLAG_STAYROOT (1<<6)
104 #define TOYFLAG_NEEDROOT (1<<7)
105 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
106
107 // Array of available commands
108
109 extern struct toy_list {
110   char *name;
111   void (*toy_main)(void);
112   char *options;
113   int flags;
114 } toy_list[];
115
116 // Global context shared by all commands.
117
118 extern struct toy_context {
119   struct toy_list *which;  // Which entry in toy_list is this one?
120   char **argv;             // Original command line arguments
121   char **optargs;          // Arguments left over from get_optflags()
122   jmp_buf *rebound;        // longjmp here instead of exit when do_rebound set
123   unsigned optflags;       // Command line option flags from get_optflags()
124   int exitval;             // Value error_exit feeds to exit()
125   int optc;                // Count of optargs
126   int exithelp;            // Should error_exit print a usage message first?
127   int old_umask;           // Old umask preserved by TOYFLAG_UMASK
128   int toycount;            // Total number of commands in this build
129 } toys;
130
131 // Two big temporary buffers: one for use by commands, one for library functions
132
133 extern char toybuf[4096], libbuf[4096];
134
135 extern char **environ;
136
137 #define GLOBALS(...)
138
139 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))