OSDN Git Service

Add netcat server mode, -l, -L, and -t.
[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  * Licensed under GPL version 2, see file LICENSE in this tarball for details.
7  */
8
9 #include "generated/config.h"
10
11 #include "lib/portability.h"
12
13 #include <ctype.h>
14 #include <dirent.h>
15 #include <errno.h>
16 #include <fcntl.h>
17 #include <grp.h>
18 #include <inttypes.h>
19 #include <limits.h>
20 #include <pty.h>
21 #include <pwd.h>
22 #include <setjmp.h>
23 #include <stdarg.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/ioctl.h>
29 #include <sys/mman.h>
30 #include <sys/mount.h>
31 #include <sys/stat.h>
32 #include <sys/statvfs.h>
33 #include <sys/types.h>
34 #include <sys/wait.h>
35 #include <unistd.h>
36 #include <utime.h>
37
38 #define _XOPEN_SOURCE 600
39 #include <time.h>
40
41 #include "lib/lib.h"
42 #include "toys/e2fs.h"
43
44 // Get list of function prototypes for all enabled command_main() functions.
45
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"
50
51 // These live in main.c
52
53 struct toy_list *toy_find(char *name);
54 void toy_init(struct toy_list *which, char *argv[]);
55 void toy_exec(char *argv[]);
56
57 // List of available applets
58
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)
63
64 #define TOYFLAG_NOFORK   (1<<4)
65 #define TOYFLAG_UMASK    (1<<5)
66
67 extern struct toy_list {
68         char *name;
69         void (*toy_main)(void);
70         char *options;
71         int flags;
72 } toy_list[];
73
74 // Global context for any applet.
75
76 extern struct toy_context {
77         struct toy_list *which;  // Which entry in toy_list is this one?
78         int exitval;             // Value error_exit feeds to exit()
79         char **argv;             // Original command line arguments
80         unsigned optflags;       // Command line option flags from get_optflags()
81         char **optargs;          // Arguments left over from get_optflags()
82         int optc;                // Count of optargs
83         int exithelp;            // Should error_exit print a usage message first?  (Option parsing.)
84         int old_umask;
85 } toys;
86
87 // One big temporary buffer, for use by applets (not library functions).
88
89 extern char toybuf[4096];
90
91 #define DEFINE_GLOBALS(...)