Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 3 | * Busybox main internal header file |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 4 | * |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell |
| 21 | * Permission has been granted to redistribute this code under the GPL. |
| 22 | * |
| 23 | */ |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 24 | #ifndef _BB_INTERNAL_H_ |
| 25 | #define _BB_INTERNAL_H_ 1 |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 26 | |
| 27 | #include "busybox.def.h" |
| 28 | |
Eric Andersen | ae6eae0 | 2000-07-19 17:35:54 +0000 | [diff] [blame] | 29 | #ifdef DMALLOC |
| 30 | #include "dmalloc.h" |
| 31 | #endif |
| 32 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 33 | #include <stdlib.h> |
Erik Andersen | 5509af7 | 2000-01-23 18:19:02 +0000 | [diff] [blame] | 34 | #include <stdarg.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 35 | #include <string.h> |
| 36 | #include <unistd.h> |
Eric Andersen | 10dc9d4 | 2000-06-26 10:45:52 +0000 | [diff] [blame] | 37 | #include <errno.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 38 | #include <sys/stat.h> |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 39 | #include <sys/param.h> |
Eric Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 40 | #include <mntent.h> |
Mark Whitley | df5f6ba | 2000-07-11 16:53:56 +0000 | [diff] [blame] | 41 | #include <regex.h> |
Eric Andersen | be909b1 | 2000-07-11 17:52:22 +0000 | [diff] [blame] | 42 | /* for the _syscall() macros */ |
| 43 | #include <sys/syscall.h> |
| 44 | #include <linux/unistd.h> |
| 45 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 46 | |
| 47 | /* Some useful definitions */ |
Eric Andersen | f811e07 | 1999-10-09 00:25:00 +0000 | [diff] [blame] | 48 | #define FALSE ((int) 1) |
| 49 | #define TRUE ((int) 0) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 50 | |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 51 | /* for mtab.c */ |
| 52 | #define MTAB_GETMOUNTPT '1' |
| 53 | #define MTAB_GETDEVICE '2' |
| 54 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 55 | #define BUF_SIZE 8192 |
| 56 | #define EXPAND_ALLOC 1024 |
| 57 | |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 58 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 59 | #define isBlank(ch) (((ch) == ' ') || ((ch) == '\t')) |
| 60 | #define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9')) |
| 61 | #define isOctal(ch) (((ch) >= '0') && ((ch) <= '7')) |
| 62 | #define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '[')) |
| 63 | |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 64 | /* Macros for min/max. */ |
| 65 | #ifndef MIN |
| 66 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
| 67 | #endif |
| 68 | |
| 69 | #ifndef MAX |
| 70 | #define MAX(a,b) (((a)>(b))?(a):(b)) |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | /* I don't like nested includes, but the string and io functions are used |
| 75 | * too often |
| 76 | */ |
| 77 | #include <stdio.h> |
| 78 | #if !defined(NO_STRING_H) || defined(STDC_HEADERS) |
| 79 | # include <string.h> |
| 80 | # if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__) |
| 81 | # include <memory.h> |
| 82 | # endif |
| 83 | # define memzero(s, n) memset ((void *)(s), 0, (n)) |
| 84 | #else |
| 85 | # include <strings.h> |
| 86 | # define strchr index |
| 87 | # define strrchr rindex |
| 88 | # define memcpy(d, s, n) bcopy((s), (d), (n)) |
| 89 | # define memcmp(s1, s2, n) bcmp((s1), (s2), (n)) |
| 90 | # define memzero(s, n) bzero((s), (n)) |
| 91 | #endif |
| 92 | |
| 93 | |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 94 | enum Location { |
| 95 | _BB_DIR_ROOT = 0, |
| 96 | _BB_DIR_BIN, |
| 97 | _BB_DIR_SBIN, |
| 98 | _BB_DIR_USR_BIN, |
| 99 | _BB_DIR_USR_SBIN |
| 100 | }; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 101 | |
Erik Andersen | bcd6177 | 2000-05-13 06:33:19 +0000 | [diff] [blame] | 102 | struct BB_applet { |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 103 | const char* name; |
| 104 | int (*main)(int argc, char** argv); |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 105 | enum Location location; |
Matt Kraai | 27a8042 | 2000-07-19 19:24:01 +0000 | [diff] [blame] | 106 | const char* usage; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 107 | }; |
Erik Andersen | bcd6177 | 2000-05-13 06:33:19 +0000 | [diff] [blame] | 108 | /* From busybox.c */ |
| 109 | extern const struct BB_applet applets[]; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 110 | |
Eric Andersen | 86ab8a3 | 2000-06-02 03:21:42 +0000 | [diff] [blame] | 111 | extern int ar_main(int argc, char **argv); |
Erik Andersen | e272915 | 2000-02-18 21:34:17 +0000 | [diff] [blame] | 112 | extern int basename_main(int argc, char **argv); |
Eric Andersen | 1b355eb | 2000-09-05 17:37:48 +0000 | [diff] [blame] | 113 | extern int bogomips_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 114 | extern int busybox_main(int argc, char** argv); |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 115 | extern int cat_main(int argc, char** argv); |
Eric Andersen | 1b61f41 | 1999-10-13 18:56:42 +0000 | [diff] [blame] | 116 | extern int chmod_chown_chgrp_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 117 | extern int chroot_main(int argc, char** argv); |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 118 | extern int chvt_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 119 | extern int clear_main(int argc, char** argv); |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 120 | extern int cp_mv_main(int argc, char** argv); |
| 121 | extern int cut_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 122 | extern int date_main(int argc, char** argv); |
John Beppu | 0021679 | 2000-06-21 19:06:16 +0000 | [diff] [blame] | 123 | extern int dc_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 124 | extern int dd_main(int argc, char** argv); |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 125 | extern int dirname_main(int argc, char** argv); |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 126 | extern int deallocvt_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 127 | extern int df_main(int argc, char** argv); |
| 128 | extern int dmesg_main(int argc, char** argv); |
John Beppu | 7a98606 | 1999-12-09 18:29:29 +0000 | [diff] [blame] | 129 | extern int du_main(int argc, char** argv); |
Eric Andersen | 61dc057 | 2000-07-11 17:29:36 +0000 | [diff] [blame] | 130 | extern int dumpkmap_main(int argc, char** argv); |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 131 | extern int dutmp_main(int argc, char** argv); |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 132 | extern int echo_main(int argc, char** argv); |
Eric Andersen | 1b355eb | 2000-09-05 17:37:48 +0000 | [diff] [blame] | 133 | extern int expr_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 134 | extern int false_main(int argc, char** argv); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 135 | extern int fbset_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 136 | extern int fdisk_main(int argc, char** argv); |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 137 | extern int fdflush_main(int argc, char **argv); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 138 | extern int fsck_minix_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 139 | extern int find_main(int argc, char** argv); |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 140 | extern int free_main(int argc, char** argv); |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 141 | extern int freeramdisk_main(int argc, char** argv); |
Eric Andersen | a1f16bb | 2000-08-21 22:02:34 +0000 | [diff] [blame] | 142 | extern int getopt_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 143 | extern int grep_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 144 | extern int gunzip_main (int argc, char** argv); |
| 145 | extern int gzip_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 146 | extern int halt_main(int argc, char** argv); |
John Beppu | 3157b1f | 1999-12-10 07:42:50 +0000 | [diff] [blame] | 147 | extern int head_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 148 | extern int hostid_main(int argc, char** argv); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 149 | extern int hostname_main(int argc, char** argv); |
Erik Andersen | 94f5e0b | 2000-05-01 19:10:52 +0000 | [diff] [blame] | 150 | extern int id_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 151 | extern int init_main(int argc, char** argv); |
Erik Andersen | 6da0ae8 | 1999-12-17 01:08:27 +0000 | [diff] [blame] | 152 | extern int insmod_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 153 | extern int kill_main(int argc, char** argv); |
| 154 | extern int length_main(int argc, char** argv); |
| 155 | extern int ln_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 156 | extern int loadacm_main(int argc, char** argv); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 157 | extern int loadfont_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 158 | extern int loadkmap_main(int argc, char** argv); |
| 159 | extern int losetup_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 160 | extern int logger_main(int argc, char **argv); |
| 161 | extern int logname_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 162 | extern int ls_main(int argc, char** argv); |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 163 | extern int lsmod_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 164 | extern int makedevs_main(int argc, char** argv); |
Eric Andersen | 2b6ab3c | 2000-06-13 06:54:53 +0000 | [diff] [blame] | 165 | extern int md5sum_main(int argc, char** argv); |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 166 | extern int mkdir_main(int argc, char** argv); |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 167 | extern int mkfifo_main(int argc, char **argv); |
| 168 | extern int mkfs_minix_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 169 | extern int mknod_main(int argc, char** argv); |
| 170 | extern int mkswap_main(int argc, char** argv); |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 171 | extern int mktemp_main(int argc, char **argv); |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 172 | extern int nc_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 173 | extern int more_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 174 | extern int mount_main(int argc, char** argv); |
| 175 | extern int mt_main(int argc, char** argv); |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 176 | extern int nslookup_main(int argc, char **argv); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 177 | extern int ping_main(int argc, char **argv); |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 178 | extern int poweroff_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 179 | extern int printf_main(int argc, char** argv); |
Eric Andersen | ef8b6c7 | 1999-10-20 08:05:35 +0000 | [diff] [blame] | 180 | extern int ps_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 181 | extern int pwd_main(int argc, char** argv); |
Eric Andersen | 918507e | 2000-08-21 22:46:33 +0000 | [diff] [blame] | 182 | extern int rdate_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 183 | extern int reboot_main(int argc, char** argv); |
Eric Andersen | bf960f5 | 2000-07-21 21:32:12 +0000 | [diff] [blame] | 184 | extern int renice_main(int argc, char** argv); |
Eric Andersen | fa405d0 | 2000-08-21 21:18:52 +0000 | [diff] [blame] | 185 | extern int reset_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 186 | extern int rm_main(int argc, char** argv); |
Erik Andersen | 3d7e341 | 1999-12-16 23:04:20 +0000 | [diff] [blame] | 187 | extern int rmdir_main(int argc, char **argv); |
| 188 | extern int rmmod_main(int argc, char** argv); |
Eric Andersen | c1525e8 | 1999-10-29 00:07:31 +0000 | [diff] [blame] | 189 | extern int sed_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 190 | extern int sfdisk_main(int argc, char** argv); |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 191 | extern int setkeycodes_main(int argc, char** argv); |
Erik Andersen | 3522eb1 | 2000-03-12 23:49:18 +0000 | [diff] [blame] | 192 | extern int shell_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 193 | extern int sleep_main(int argc, char** argv); |
John Beppu | 019513a | 1999-12-22 17:57:31 +0000 | [diff] [blame] | 194 | extern int sort_main(int argc, char** argv); |
Eric Andersen | 8759006 | 1999-10-18 21:22:59 +0000 | [diff] [blame] | 195 | extern int swap_on_off_main(int argc, char** argv); |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 196 | extern int sync_main(int argc, char** argv); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 197 | extern int syslogd_main(int argc, char **argv); |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 198 | extern int tail_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 199 | extern int tar_main(int argc, char** argv); |
John Beppu | 059f152 | 1999-12-10 05:27:16 +0000 | [diff] [blame] | 200 | extern int tee_main(int argc, char** argv); |
Erik Andersen | d75af99 | 2000-03-16 08:09:09 +0000 | [diff] [blame] | 201 | extern int test_main(int argc, char** argv); |
Erik Andersen | f7c49ef | 2000-02-22 17:17:45 +0000 | [diff] [blame] | 202 | extern int telnet_main(int argc, char** argv); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 203 | extern int touch_main(int argc, char** argv); |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 204 | extern int tr_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 205 | extern int true_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 206 | extern int tput_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 207 | extern int tryopen_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 208 | extern int tty_main(int argc, char** argv); |
Eric Andersen | 2b6ab3c | 2000-06-13 06:54:53 +0000 | [diff] [blame] | 209 | extern int uuencode_main(int argc, char** argv); |
| 210 | extern int uudecode_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 211 | extern int umount_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 212 | extern int uname_main(int argc, char** argv); |
Erik Andersen | 66be5e7 | 2000-03-05 07:52:05 +0000 | [diff] [blame] | 213 | extern int uptime_main(int argc, char** argv); |
John Beppu | abb4772 | 2000-01-06 00:48:21 +0000 | [diff] [blame] | 214 | extern int uniq_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 215 | extern int update_main(int argc, char** argv); |
Erik Andersen | b99ca13 | 2000-04-04 18:49:18 +0000 | [diff] [blame] | 216 | extern int usleep_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 217 | extern int wc_main(int argc, char** argv); |
Eric Andersen | 9670083 | 2000-09-04 15:15:55 +0000 | [diff] [blame] | 218 | extern int wget_main(int argc, char** argv); |
Erik Andersen | 330fd2b | 2000-05-19 05:35:19 +0000 | [diff] [blame] | 219 | extern int which_main(int argc, char** argv); |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 220 | extern int whoami_main(int argc, char** argv); |
| 221 | extern int yes_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 222 | |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 223 | extern const char ar_usage[]; |
| 224 | extern const char basename_usage[]; |
| 225 | extern const char cat_usage[]; |
| 226 | extern const char chgrp_usage[]; |
| 227 | extern const char chmod_usage[]; |
| 228 | extern const char chown_usage[]; |
| 229 | extern const char chroot_usage[]; |
| 230 | extern const char chvt_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 231 | extern const char clear_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 232 | extern const char cp_usage[]; |
| 233 | extern const char cut_usage[]; |
| 234 | extern const char date_usage[]; |
| 235 | extern const char dc_usage[]; |
| 236 | extern const char dd_usage[]; |
| 237 | extern const char deallocvt_usage[]; |
| 238 | extern const char df_usage[]; |
| 239 | extern const char dirname_usage[]; |
| 240 | extern const char dmesg_usage[]; |
| 241 | extern const char du_usage[]; |
| 242 | extern const char dumpkmap_usage[]; |
| 243 | extern const char dutmp_usage[]; |
| 244 | extern const char echo_usage[]; |
Eric Andersen | 1b355eb | 2000-09-05 17:37:48 +0000 | [diff] [blame] | 245 | extern const char expr_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 246 | extern const char false_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 247 | extern const char fdflush_usage[]; |
| 248 | extern const char find_usage[]; |
| 249 | extern const char free_usage[]; |
| 250 | extern const char freeramdisk_usage[]; |
| 251 | extern const char fsck_minix_usage[]; |
| 252 | extern const char grep_usage[]; |
| 253 | extern const char gunzip_usage[]; |
| 254 | extern const char gzip_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 255 | extern const char halt_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 256 | extern const char head_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 257 | extern const char hostid_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 258 | extern const char hostname_usage[]; |
| 259 | extern const char id_usage[]; |
| 260 | extern const char insmod_usage[]; |
| 261 | extern const char kill_usage[]; |
| 262 | extern const char killall_usage[]; |
| 263 | extern const char length_usage[]; |
| 264 | extern const char ln_usage[]; |
| 265 | extern const char loadacm_usage[]; |
| 266 | extern const char loadfont_usage[]; |
| 267 | extern const char loadkmap_usage[]; |
| 268 | extern const char logger_usage[]; |
| 269 | extern const char logname_usage[]; |
| 270 | extern const char ls_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 271 | extern const char lsmod_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 272 | extern const char makedevs_usage[]; |
| 273 | extern const char md5sum_usage[]; |
| 274 | extern const char mkdir_usage[]; |
| 275 | extern const char mkfifo_usage[]; |
| 276 | extern const char mkfs_minix_usage[]; |
| 277 | extern const char mknod_usage[]; |
| 278 | extern const char mkswap_usage[]; |
| 279 | extern const char mktemp_usage[]; |
| 280 | extern const char more_usage[]; |
| 281 | extern const char mount_usage[]; |
| 282 | extern const char mt_usage[]; |
| 283 | extern const char mv_usage[]; |
| 284 | extern const char nc_usage[]; |
| 285 | extern const char nslookup_usage[]; |
| 286 | extern const char ping_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 287 | extern const char poweroff_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 288 | extern const char printf_usage[]; |
| 289 | extern const char ps_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 290 | extern const char pwd_usage[]; |
Eric Andersen | 918507e | 2000-08-21 22:46:33 +0000 | [diff] [blame] | 291 | extern const char rdate_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 292 | extern const char reboot_usage[]; |
Eric Andersen | bf960f5 | 2000-07-21 21:32:12 +0000 | [diff] [blame] | 293 | extern const char renice_usage[]; |
Eric Andersen | fa405d0 | 2000-08-21 21:18:52 +0000 | [diff] [blame] | 294 | extern const char reset_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 295 | extern const char rm_usage[]; |
| 296 | extern const char rmdir_usage[]; |
| 297 | extern const char rmmod_usage[]; |
| 298 | extern const char sed_usage[]; |
| 299 | extern const char setkeycodes_usage[]; |
| 300 | extern const char shell_usage[]; |
| 301 | extern const char sleep_usage[]; |
| 302 | extern const char sort_usage[]; |
| 303 | extern const char swapoff_usage[]; |
| 304 | extern const char swapon_usage[]; |
| 305 | extern const char sync_usage[]; |
| 306 | extern const char syslogd_usage[]; |
| 307 | extern const char tail_usage[]; |
| 308 | extern const char tar_usage[]; |
| 309 | extern const char tee_usage[]; |
| 310 | extern const char telnet_usage[]; |
| 311 | extern const char test_usage[]; |
| 312 | extern const char touch_usage[]; |
| 313 | extern const char tr_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 314 | extern const char true_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 315 | extern const char tty_usage[]; |
| 316 | extern const char umount_usage[]; |
| 317 | extern const char uname_usage[]; |
| 318 | extern const char uniq_usage[]; |
| 319 | extern const char update_usage[]; |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 320 | extern const char uptime_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 321 | extern const char usleep_usage[]; |
| 322 | extern const char uudecode_usage[]; |
| 323 | extern const char uuencode_usage[]; |
| 324 | extern const char wc_usage[]; |
Eric Andersen | 9670083 | 2000-09-04 15:15:55 +0000 | [diff] [blame] | 325 | extern const char wget_usage[]; |
Matt Kraai | bf181b9 | 2000-07-16 20:57:15 +0000 | [diff] [blame] | 326 | extern const char which_usage[]; |
| 327 | extern const char whoami_usage[]; |
| 328 | extern const char yes_usage[]; |
| 329 | |
Eric Andersen | 501c88b | 2000-07-28 15:14:45 +0000 | [diff] [blame] | 330 | extern const char *applet_name; |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 331 | |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 332 | extern void usage(const char *usage) __attribute__ ((noreturn)); |
Erik Andersen | 93d6513 | 2000-04-06 08:06:36 +0000 | [diff] [blame] | 333 | extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 334 | extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 335 | |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 336 | const char *modeString(int mode); |
| 337 | const char *timeString(time_t timeVal); |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 338 | int isDirectory(const char *name, const int followLinks, struct stat *statBuf); |
Eric Andersen | f811e07 | 1999-10-09 00:25:00 +0000 | [diff] [blame] | 339 | int isDevice(const char *name); |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 340 | |
| 341 | typedef struct ino_dev_hash_bucket_struct { |
| 342 | struct ino_dev_hash_bucket_struct *next; |
| 343 | ino_t ino; |
| 344 | dev_t dev; |
| 345 | char name[1]; |
| 346 | } ino_dev_hashtable_bucket_t; |
| 347 | int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name); |
| 348 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); |
| 349 | void reset_ino_dev_hashtable(void); |
| 350 | |
Erik Andersen | 59b9e87 | 2000-05-10 05:05:45 +0000 | [diff] [blame] | 351 | int copyFile(const char *srcName, const char *destName, |
| 352 | int setModes, int followLinks, int forceFlag); |
Glenn L McGrath | 06aeb6c | 2000-08-25 03:50:10 +0000 | [diff] [blame] | 353 | int copySubFile(int srcFd, int dstFd, size_t remaining); |
Eric Andersen | f811e07 | 1999-10-09 00:25:00 +0000 | [diff] [blame] | 354 | char *buildName(const char *dirName, const char *fileName); |
| 355 | int makeString(int argc, const char **argv, char *buf, int bufLen); |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 356 | char *getChunk(int size); |
| 357 | char *chunkstrdup(const char *str); |
| 358 | void freeChunks(void); |
| 359 | int fullWrite(int fd, const char *buf, int len); |
| 360 | int fullRead(int fd, char *buf, int len); |
Eric Andersen | 63a0e53 | 1999-10-22 05:12:14 +0000 | [diff] [blame] | 361 | int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst, |
Erik Andersen | 3364d78 | 2000-03-28 00:58:14 +0000 | [diff] [blame] | 362 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData), |
| 363 | int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData), |
| 364 | void* userData); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 365 | |
Erik Andersen | 06936df | 2000-01-23 02:14:20 +0000 | [diff] [blame] | 366 | extern int createPath (const char *name, int mode); |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 367 | extern int parse_mode( const char* s, mode_t* theMode); |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 368 | |
Erik Andersen | 1ad302a | 2000-03-24 00:54:46 +0000 | [diff] [blame] | 369 | extern int get_kernel_revision(void); |
Erik Andersen | 94f5e0b | 2000-05-01 19:10:52 +0000 | [diff] [blame] | 370 | |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 371 | extern int get_console_fd(char* tty_name); |
Eric Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 372 | extern struct mntent *findMountPoint(const char *name, const char *table); |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 373 | extern void write_mtab(char* blockDevice, char* directory, |
| 374 | char* filesystemType, long flags, char* string_flags); |
| 375 | extern void erase_mtab(const char * name); |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 376 | extern void mtab_read(void); |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 377 | extern char *mtab_first(void **iter); |
| 378 | extern char *mtab_next(void **iter); |
| 379 | extern char *mtab_getinfo(const char *match, const char which); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 380 | extern int check_wildcard_match(const char* text, const char* pattern); |
Eric Andersen | 1792f8c | 1999-12-09 06:11:36 +0000 | [diff] [blame] | 381 | extern long getNum (const char *cp); |
Erik Andersen | 825aead | 2000-04-07 06:00:07 +0000 | [diff] [blame] | 382 | extern pid_t* findPidByName( char* pidName); |
Erik Andersen | ec5bd90 | 2000-03-22 07:12:05 +0000 | [diff] [blame] | 383 | extern int find_real_root_device_name(char* name); |
Mark Whitley | 1ca4177 | 2000-06-28 22:15:26 +0000 | [diff] [blame] | 384 | extern char *get_line_from_file(FILE *file); |
Pavel Roskin | cc8a66b | 2000-07-17 20:18:42 +0000 | [diff] [blame] | 385 | extern void print_file(FILE *file); |
| 386 | extern int print_file_by_name(char *filename); |
Eric Andersen | f7cf2f7 | 2000-07-05 17:26:35 +0000 | [diff] [blame] | 387 | extern char process_escape_sequence(char **ptr); |
Eric Andersen | 0b4551f | 2000-07-10 16:44:03 +0000 | [diff] [blame] | 388 | extern char *get_last_path_component(char *path); |
Mark Whitley | c41e8c8 | 2000-07-12 23:35:21 +0000 | [diff] [blame] | 389 | extern void xregcomp(regex_t *preg, const char *regex, int cflags); |
John Beppu | 5a728cf | 2000-04-17 04:22:09 +0000 | [diff] [blame] | 390 | |
Eric Andersen | ae6eae0 | 2000-07-19 17:35:54 +0000 | [diff] [blame] | 391 | #ifndef DMALLOC |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 392 | extern void *xmalloc (size_t size); |
Matt Kraai | 8690572 | 2000-07-19 18:20:02 +0000 | [diff] [blame] | 393 | extern void *xrealloc(void *old, size_t size); |
Eric Andersen | 501c88b | 2000-07-28 15:14:45 +0000 | [diff] [blame] | 394 | extern void *xcalloc(size_t nmemb, size_t size); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 395 | extern char *xstrdup (const char *s); |
Eric Andersen | ae6eae0 | 2000-07-19 17:35:54 +0000 | [diff] [blame] | 396 | #endif |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 397 | extern char *xstrndup (const char *s, int n); |
| 398 | |
| 399 | |
Erik Andersen | 94f5e0b | 2000-05-01 19:10:52 +0000 | [diff] [blame] | 400 | /* These parse entries in /etc/passwd and /etc/group. This is desirable |
| 401 | * for BusyBox since we want to avoid using the glibc NSS stuff, which |
| 402 | * increases target size and is often not needed embedded systems. */ |
Eric Andersen | fad04fd | 2000-07-14 06:49:52 +0000 | [diff] [blame] | 403 | extern long my_getpwnam(char *name); |
| 404 | extern long my_getgrnam(char *name); |
| 405 | extern void my_getpwuid(char *name, long uid); |
| 406 | extern void my_getgrgid(char *group, long gid); |
| 407 | extern long my_getpwnamegid(char *name); |
Erik Andersen | 94f5e0b | 2000-05-01 19:10:52 +0000 | [diff] [blame] | 408 | |
Erik Andersen | d0480c2 | 2000-02-07 20:35:14 +0000 | [diff] [blame] | 409 | extern int device_open(char *device, int mode); |
Pavel Roskin | 21ddb38 | 2000-07-17 19:31:54 +0000 | [diff] [blame] | 410 | |
Erik Andersen | 5cbdd71 | 2000-01-26 20:06:48 +0000 | [diff] [blame] | 411 | #if defined BB_FEATURE_MOUNT_LOOP |
| 412 | extern int del_loop(const char *device); |
Erik Andersen | de7965c | 2000-01-26 23:49:21 +0000 | [diff] [blame] | 413 | extern int set_loop(const char *device, const char *file, int offset, int *loopro); |
| 414 | extern char *find_unused_loop_device (void); |
Erik Andersen | 5cbdd71 | 2000-01-26 20:06:48 +0000 | [diff] [blame] | 415 | #endif |
| 416 | |
Erik Andersen | 3fe39dc | 2000-01-25 18:13:53 +0000 | [diff] [blame] | 417 | |
Erik Andersen | 5509af7 | 2000-01-23 18:19:02 +0000 | [diff] [blame] | 418 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 419 | extern int vdprintf(int d, const char *format, va_list ap); |
| 420 | #endif |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 421 | |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 422 | #if defined BB_NFSMOUNT |
Eric Andersen | e7413a9 | 2000-07-14 06:19:41 +0000 | [diff] [blame] | 423 | int nfsmount(const char *spec, const char *node, int *flags, |
| 424 | char **extra_opts, char **mount_opts, int running_bg); |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 425 | #endif |
Eric Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 426 | |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 427 | #ifndef RB_POWER_OFF |
Eric Andersen | 74c66ad | 2000-06-16 19:57:44 +0000 | [diff] [blame] | 428 | /* Stop system and switch power off if possible. */ |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 429 | #define RB_POWER_OFF 0x4321fedc |
| 430 | #endif |
| 431 | |
Eric Andersen | 10dc9d4 | 2000-06-26 10:45:52 +0000 | [diff] [blame] | 432 | /* Include our own copy of struct sysinfo to avoid binary compatability |
| 433 | * problems with Linux 2.4, which changed things. Grumble, grumble. */ |
| 434 | struct sysinfo { |
| 435 | long uptime; /* Seconds since boot */ |
| 436 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ |
| 437 | unsigned long totalram; /* Total usable main memory size */ |
| 438 | unsigned long freeram; /* Available memory size */ |
| 439 | unsigned long sharedram; /* Amount of shared memory */ |
| 440 | unsigned long bufferram; /* Memory used by buffers */ |
| 441 | unsigned long totalswap; /* Total swap space size */ |
| 442 | unsigned long freeswap; /* swap space still available */ |
| 443 | unsigned short procs; /* Number of current processes */ |
| 444 | unsigned long totalhigh; /* Total high memory size */ |
| 445 | unsigned long freehigh; /* Available high memory size */ |
| 446 | unsigned int mem_unit; /* Memory unit size in bytes */ |
| 447 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ |
| 448 | }; |
| 449 | extern int sysinfo (struct sysinfo* info); |
Eric Andersen | aa0765e | 1999-10-22 04:30:20 +0000 | [diff] [blame] | 450 | |
Eric Andersen | bd4a75f | 2000-06-19 20:03:48 +0000 | [diff] [blame] | 451 | /* Bit map related macros -- libc5 doens't provide these... sigh. */ |
Eric Andersen | 10dc9d4 | 2000-06-26 10:45:52 +0000 | [diff] [blame] | 452 | #ifndef setbit |
Eric Andersen | bd4a75f | 2000-06-19 20:03:48 +0000 | [diff] [blame] | 453 | #define NBBY CHAR_BIT |
| 454 | #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) |
| 455 | #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) |
| 456 | #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) |
| 457 | #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) |
| 458 | #endif |
| 459 | |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 460 | #endif /* _BB_INTERNAL_H_ */ |