toybox/toys.h
<<
>>
Prefs
   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 <math.h>
  21#include <pwd.h>
  22#include <regex.h>
  23#include <sched.h>
  24#include <setjmp.h>
  25#include <signal.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/utsname.h>
  40#include <sys/wait.h>
  41#include <syslog.h>
  42#include <termios.h>
  43#include <time.h>
  44#include <unistd.h>
  45#include <utime.h>
  46
  47// Posix networking
  48
  49#include <arpa/inet.h>
  50#include <netdb.h>
  51#include <net/if.h>
  52#include <netinet/in.h>
  53#include <netinet/tcp.h>
  54#include <poll.h>
  55#include <sys/socket.h>
  56#include <sys/un.h>
  57
  58// Internationalization support (also in POSIX and LSB)
  59
  60#include <locale.h>
  61#include <wchar.h>
  62#include <wctype.h>
  63
  64// LSB 4.1 headers
  65#include <sys/ioctl.h>
  66
  67#include "lib/lib.h"
  68#include "lib/lsm.h"
  69#include "lib/toyflags.h"
  70
  71// Get list of function prototypes for all enabled command_main() functions.
  72
  73#define NEWTOY(name, opts, flags) void name##_main(void);
  74#define OLDTOY(name, oldname, flags) void oldname##_main(void);
  75#include "generated/newtoys.h"
  76#include "generated/flags.h"
  77#include "generated/globals.h"
  78#include "generated/tags.h"
  79
  80// These live in main.c
  81
  82struct toy_list *toy_find(char *name);
  83void toy_init(struct toy_list *which, char *argv[]);
  84void toy_exec(char *argv[]);
  85
  86// Array of available commands
  87
  88extern struct toy_list {
  89  char *name;
  90  void (*toy_main)(void);
  91  char *options;
  92  int flags;
  93} toy_list[];
  94
  95// Global context shared by all commands.
  96
  97extern struct toy_context {
  98  struct toy_list *which;  // Which entry in toy_list is this one?
  99  char **argv;             // Original command line arguments
 100  char **optargs;          // Arguments left over from get_optflags()
 101  unsigned long long optflags; // Command line option flags from get_optflags()
 102  int optc;                // Count of optargs
 103  int old_umask;           // Old umask preserved by TOYFLAG_UMASK
 104  short toycount;          // Total number of commands in this build
 105  short signal;            // generic_signal() records what signal it saw here
 106  int signalfd;            // and writes signal to this fd, if set
 107  char exitval;            // Value error_exit feeds to exit()
 108  char wasroot;            // dropped setuid
 109
 110  // This is at the end so toy_init() doesn't zero it.
 111  sigjmp_buf *rebound;     // siglongjmp here instead of exit when do_rebound
 112  struct arg_list *xexit;  // atexit() functions for xexit(), set by sigatexit()
 113  void *stacktop;          // nested toy_exec() call count, or 0 if vforked
 114} toys;
 115
 116// Two big temporary buffers: one for use by commands, one for library functions
 117
 118extern char toybuf[4096], libbuf[4096];
 119
 120extern char **environ;
 121
 122#define FLAG(x) (toys.optflags&FLAG_##x)
 123
 124#define GLOBALS(...)
 125#define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))
 126#define TAGGED_ARRAY(X, ...) {__VA_ARGS__}
 127