landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 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 | |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 9 | #include <ctype.h> |
| 10 | #include <errno.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <inttypes.h> |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 13 | #include <limits.h> |
Rob Landley | 6973a1d | 2006-11-25 16:50:00 -0500 | [diff] [blame] | 14 | #include <setjmp.h> |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 15 | #include <stdarg.h> |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 16 | #include <stdint.h> |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 17 | #include <stdio.h> |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 20 | #include <strings.h> |
landley | 00f87f1 | 2006-10-25 18:38:37 -0400 | [diff] [blame] | 21 | #include <sys/stat.h> |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 22 | #include <sys/statvfs.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/wait.h> |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 25 | #include <unistd.h> |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 26 | |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 27 | #include "lib/lib.h" |
Rob Landley | f2311a4 | 2006-11-04 17:45:18 -0500 | [diff] [blame] | 28 | #include "gen_config.h" |
| 29 | #include "toys/toylist.h" |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 30 | |
Rob Landley | f2311a4 | 2006-11-04 17:45:18 -0500 | [diff] [blame] | 31 | // These live in main.c |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 32 | |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 33 | struct toy_list *toy_find(char *name); |
landley | cd9dfc3 | 2006-10-18 18:38:16 -0400 | [diff] [blame] | 34 | void toy_init(struct toy_list *which, char *argv[]); |
| 35 | void toy_exec(char *argv[]); |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 36 | |
Rob Landley | f2311a4 | 2006-11-04 17:45:18 -0500 | [diff] [blame] | 37 | // Global context for any applet. |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 38 | |
| 39 | extern struct toy_context { |
landley | 4f344e3 | 2006-10-05 16:18:03 -0400 | [diff] [blame] | 40 | struct toy_list *which; // Which entry in toy_list is this one? |
| 41 | int exitval; // Value error_exit feeds to exit() |
landley | 09ea7ac | 2006-10-30 01:38:00 -0500 | [diff] [blame] | 42 | char **argv; // Command line arguments |
Rob Landley | 8324b89 | 2006-11-19 02:49:22 -0500 | [diff] [blame] | 43 | unsigned optflags; // Command line option flags from get_optflags() |
| 44 | char **optargs; // Arguments left over from get_optflags() |
landley | c562150 | 2006-09-28 17:18:51 -0400 | [diff] [blame] | 45 | } toys; |
Rob Landley | 8324b89 | 2006-11-19 02:49:22 -0500 | [diff] [blame] | 46 | |
| 47 | // One big temporary buffer, for use by applets (not library functions). |
| 48 | |
Rob Landley | 1521a9e | 2006-11-25 16:06:55 -0500 | [diff] [blame] | 49 | char toybuf[4096]; |