toys.h revision 6f4584958bc299b073ce20801e6184fb1af3baac
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#undef _XOPEN_SOURCE
39#define _XOPEN_SOURCE 600
40#include <time.h>
41
42#include "lib/lib.h"
43#include "toys/e2fs.h"
44
45// Get list of function prototypes for all enabled command_main() functions.
46
47#define NEWTOY(name, opts, flags) void name##_main(void);
48#define OLDTOY(name, oldname, opts, flags)
49#include "generated/newtoys.h"
50#include "generated/globals.h"
51
52// These live in main.c
53
54struct toy_list *toy_find(char *name);
55void toy_init(struct toy_list *which, char *argv[]);
56void toy_exec(char *argv[]);
57
58// Flags describing applet behavior.
59
60#define TOYFLAG_USR      (1<<0)
61#define TOYFLAG_BIN      (1<<1)
62#define TOYFLAG_SBIN     (1<<2)
63#define TOYMASK_LOCATION ((1<<4)-1)
64
65// This is a shell built-in function, running in the same process context.
66#define TOYFLAG_NOFORK   (1<<4)
67
68// Start applet with a umask of 0 (saves old umask in this.old_umask)
69#define TOYFLAG_UMASK    (1<<5)
70
71// Array of available applets
72
73extern struct toy_list {
74        char *name;
75        void (*toy_main)(void);
76        char *options;
77        int flags;
78} toy_list[];
79
80// Global context shared by all applets.
81
82extern struct toy_context {
83	struct toy_list *which;  // Which entry in toy_list is this one?
84	int exitval;             // Value error_exit feeds to exit()
85	char **argv;             // Original command line arguments
86	unsigned optflags;       // Command line option flags from get_optflags()
87	char **optargs;          // Arguments left over from get_optflags()
88	int optc;                // Count of optargs
89	int exithelp;            // Should error_exit print a usage message first?
90	int old_umask;           // Old umask preserved by TOYFLAG_UMASK
91} toys;
92
93// One big temporary buffer, for use by applets (not library functions).
94
95extern char toybuf[4096];
96
97#define DEFINE_GLOBALS(...)
98