OSDN Git Service

Introduce libbuf analogous to toybuf but for use by lib/*.c. Change readfile() semant...
[android-x86/external-toybox.git] / toys.h
1 /* Toybox infrastructure.
2  *
3  * Copyright 2006 Rob Landley <rob@landley.net>
4  */
5
6 #include "generated/config.h"
7
8 #include "lib/portability.h"
9
10 #include <ctype.h>
11 #include <dirent.h>
12 #include <errno.h>
13 #include <fcntl.h>
14 #include <grp.h>
15 #include <inttypes.h>
16 #include <limits.h>
17 #include <libgen.h>
18 #include <math.h>
19 #include <pty.h>
20 #include <pwd.h>
21 #include <sched.h>
22 #include <setjmp.h>
23 #include <sched.h>
24 #include <shadow.h>
25 #include <stdarg.h>
26 #include <stddef.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/statfs.h>
38 #include <sys/statvfs.h>
39 #include <sys/sysinfo.h>
40 #include <sys/swap.h>
41 #include <sys/time.h>
42 #include <sys/times.h>
43 #include <sys/types.h>
44 #include <sys/utsname.h>
45 #include <sys/wait.h>
46 #include <syslog.h>
47 #include <time.h>
48 #include <unistd.h>
49 #include <utime.h>
50 #include <utmpx.h>
51
52 // Internationalization support
53
54 #include <locale.h>
55 #include <wchar.h>
56 #include <wctype.h>
57
58 #include "lib/lib.h"
59 #include "toys/e2fs.h"
60
61 // Get list of function prototypes for all enabled command_main() functions.
62
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/oldtoys.h"
67 #include "generated/globals.h"
68
69 // These live in main.c
70
71 struct toy_list *toy_find(char *name);
72 void toy_init(struct toy_list *which, char *argv[]);
73 void toy_exec(char *argv[]);
74
75 // Flags describing command behavior.
76
77 #define TOYFLAG_USR      (1<<0)
78 #define TOYFLAG_BIN      (1<<1)
79 #define TOYFLAG_SBIN     (1<<2)
80 #define TOYMASK_LOCATION ((1<<4)-1)
81
82 // This is a shell built-in function, running in the same process context.
83 #define TOYFLAG_NOFORK   (1<<4)
84
85 // Start command with a umask of 0 (saves old umask in this.old_umask)
86 #define TOYFLAG_UMASK    (1<<5)
87
88 // This command runs as root.
89 #define TOYFLAG_STAYROOT (1<<6)
90 #define TOYFLAG_NEEDROOT (1<<7)
91 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
92
93 // Array of available commands
94
95 extern struct toy_list {
96   char *name;
97   void (*toy_main)(void);
98   char *options;
99   int flags;
100 } toy_list[];
101
102 // Global context shared by all commands.
103
104 extern struct toy_context {
105   struct toy_list *which;  // Which entry in toy_list is this one?
106   int exitval;             // Value error_exit feeds to exit()
107   char **argv;             // Original command line arguments
108   unsigned optflags;       // Command line option flags from get_optflags()
109   char **optargs;          // Arguments left over from get_optflags()
110   int optc;                // Count of optargs
111   int exithelp;            // Should error_exit print a usage message first?
112   int old_umask;           // Old umask preserved by TOYFLAG_UMASK
113   jmp_buf *rebound;        // longjmp here instead of exit when do_rebound set
114 } toys;
115
116 // Two big temporary buffers: one for use by commands, one for library functions
117
118 extern char toybuf[4096], libbuf[4096];
119
120 extern char **environ;
121
122 #define GLOBALS(...)
123
124 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))