blob: 686d7527053d70a17704e38b7f7ffd43e3d0c4a6 [file] [log] [blame]
landleyc5621502006-09-28 17:18:51 -04001/* 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
Rob Landley28964802008-01-19 17:08:39 -06009#include "generated/config.h"
Rob Landleyfd1c5ba2007-02-03 14:10:00 -050010
Rob Landley90163772007-01-18 21:54:08 -050011#include "lib/portability.h"
12
landley09ea7ac2006-10-30 01:38:00 -050013#include <ctype.h>
Rob Landleyfd1c5ba2007-02-03 14:10:00 -050014#include <dirent.h>
landley09ea7ac2006-10-30 01:38:00 -050015#include <errno.h>
16#include <fcntl.h>
Rob Landleyc92fde02007-04-23 15:45:55 -040017#include <grp.h>
landley09ea7ac2006-10-30 01:38:00 -050018#include <inttypes.h>
landley4f344e32006-10-05 16:18:03 -040019#include <limits.h>
Rob Landleyc92fde02007-04-23 15:45:55 -040020#include <pwd.h>
Rob Landley6973a1d2006-11-25 16:50:00 -050021#include <setjmp.h>
landley4f344e32006-10-05 16:18:03 -040022#include <stdarg.h>
landley09ea7ac2006-10-30 01:38:00 -050023#include <stdint.h>
landleyc5621502006-09-28 17:18:51 -040024#include <stdio.h>
landley4f344e32006-10-05 16:18:03 -040025#include <stdlib.h>
26#include <string.h>
Rob Landley055cfcb2007-01-14 20:20:06 -050027#include <sys/ioctl.h>
Rob Landleyc92fde02007-04-23 15:45:55 -040028#include <sys/mman.h>
Rob Landleye2580db2007-01-23 13:20:38 -050029#include <sys/mount.h>
landley00f87f12006-10-25 18:38:37 -040030#include <sys/stat.h>
landley09ea7ac2006-10-30 01:38:00 -050031#include <sys/statvfs.h>
32#include <sys/types.h>
33#include <sys/wait.h>
landley4f344e32006-10-05 16:18:03 -040034#include <unistd.h>
Rob Landley07c78d32007-12-28 03:29:33 -060035#include <utime.h>
36
37#define _XOPEN_SOURCE 600
38#include <time.h>
landleyc5621502006-09-28 17:18:51 -040039
landley4f344e32006-10-05 16:18:03 -040040#include "lib/lib.h"
Rob Landleye2580db2007-01-23 13:20:38 -050041#include "toys/e2fs.h"
Rob Landley3ac8d262007-01-28 04:54:01 -050042#include "toys/toylist.h"
landleyc5621502006-09-28 17:18:51 -040043
Rob Landley55928b12008-01-19 17:43:27 -060044// 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
Rob Landleyf2311a42006-11-04 17:45:18 -050050// These live in main.c
landleyc5621502006-09-28 17:18:51 -040051
landley4f344e32006-10-05 16:18:03 -040052struct toy_list *toy_find(char *name);
landleycd9dfc32006-10-18 18:38:16 -040053void toy_init(struct toy_list *which, char *argv[]);
54void toy_exec(char *argv[]);
landleyc5621502006-09-28 17:18:51 -040055
Rob Landleyf2311a42006-11-04 17:45:18 -050056// Global context for any applet.
landleyc5621502006-09-28 17:18:51 -040057
58extern struct toy_context {
landley4f344e32006-10-05 16:18:03 -040059 struct toy_list *which; // Which entry in toy_list is this one?
60 int exitval; // Value error_exit feeds to exit()
Rob Landleyf2f98fa2007-05-17 02:38:27 -040061 char **argv; // Original command line arguments
Rob Landley8324b892006-11-19 02:49:22 -050062 unsigned optflags; // Command line option flags from get_optflags()
63 char **optargs; // Arguments left over from get_optflags()
Rob Landley9abf1362007-10-16 01:49:05 -050064 int exithelp; // Should error_exit print a usage message first? (Option parsing.)
landleyc5621502006-09-28 17:18:51 -040065} toys;
Rob Landley8324b892006-11-19 02:49:22 -050066
67// One big temporary buffer, for use by applets (not library functions).
68
Rob Landley055cfcb2007-01-14 20:20:06 -050069extern char toybuf[4096];