Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Busybox main internal header file |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 6 | * Permission has been granted to redistribute this code under the GPL. |
Rob Landley | eb84a42 | 2006-09-20 21:41:13 +0000 | [diff] [blame] | 7 | * |
| 8 | * Licensed under the GPL version 2, see the file LICENSE in this tarball. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 9 | */ |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 10 | #ifndef __LIBBUSYBOX_H__ |
| 11 | #define __LIBBUSYBOX_H__ 1 |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 12 | |
Bernhard Reutner-Fischer | 781e42d | 2006-05-26 14:41:40 +0000 | [diff] [blame] | 13 | #include "platform.h" |
| 14 | |
Rob Landley | 5d9c42a | 2006-06-24 17:55:02 +0000 | [diff] [blame] | 15 | #include <ctype.h> |
Rob Landley | b623a54 | 2006-05-31 22:09:03 +0000 | [diff] [blame] | 16 | #include <dirent.h> |
Rob Landley | c9c1a41 | 2006-07-12 19:17:55 +0000 | [diff] [blame] | 17 | #include <errno.h> |
Rob Landley | 5d9c42a | 2006-06-24 17:55:02 +0000 | [diff] [blame] | 18 | #include <fcntl.h> |
Rob Landley | b623a54 | 2006-05-31 22:09:03 +0000 | [diff] [blame] | 19 | #include <inttypes.h> |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 20 | #include <malloc.h> |
Rob Landley | b623a54 | 2006-05-31 22:09:03 +0000 | [diff] [blame] | 21 | #include <netdb.h> |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 22 | #include <setjmp.h> |
Rob Landley | 1cca948 | 2006-07-10 19:45:20 +0000 | [diff] [blame] | 23 | #include <signal.h> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
Manuel Novoa III | 68474f3 | 2004-02-05 14:45:58 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 26 | #include <stdarg.h> |
Rob Landley | 5d9c42a | 2006-06-24 17:55:02 +0000 | [diff] [blame] | 27 | #include <string.h> |
| 28 | #include <strings.h> |
Rob Landley | c9c1a41 | 2006-07-12 19:17:55 +0000 | [diff] [blame] | 29 | #include <sys/ioctl.h> |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 30 | #include <sys/mman.h> |
Rob Landley | 5d9c42a | 2006-06-24 17:55:02 +0000 | [diff] [blame] | 31 | #include <sys/socket.h> |
"Vladimir N. Oleynik" | 7fe6520 | 2005-09-20 10:02:36 +0000 | [diff] [blame] | 32 | #include <sys/stat.h> |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 33 | #include <sys/statfs.h> |
Rob Landley | 299a6b4 | 2006-05-27 21:42:58 +0000 | [diff] [blame] | 34 | #include <sys/time.h> |
Rob Landley | b623a54 | 2006-05-31 22:09:03 +0000 | [diff] [blame] | 35 | #include <sys/types.h> |
Rob Landley | c9c1a41 | 2006-07-12 19:17:55 +0000 | [diff] [blame] | 36 | #include <sys/wait.h> |
Rob Landley | b623a54 | 2006-05-31 22:09:03 +0000 | [diff] [blame] | 37 | #include <termios.h> |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 38 | #include <time.h> |
Rob Landley | b13fee4 | 2006-06-20 22:38:00 +0000 | [diff] [blame] | 39 | #include <unistd.h> |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 40 | #include <utime.h> |
Rob Landley | 299a6b4 | 2006-05-27 21:42:58 +0000 | [diff] [blame] | 41 | |
Eric Andersen | 9e48045 | 2003-07-03 10:07:04 +0000 | [diff] [blame] | 42 | #ifdef CONFIG_SELINUX |
Bernhard Reutner-Fischer | d4cffd1 | 2005-09-21 17:38:30 +0000 | [diff] [blame] | 43 | #include <selinux/selinux.h> |
Eric Andersen | 9e48045 | 2003-07-03 10:07:04 +0000 | [diff] [blame] | 44 | #endif |
Robert Griebl | c9aca45 | 2002-06-04 20:06:25 +0000 | [diff] [blame] | 45 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 46 | #ifdef CONFIG_LOCALE_SUPPORT |
| 47 | #include <locale.h> |
Rob Landley | eb84a42 | 2006-09-20 21:41:13 +0000 | [diff] [blame] | 48 | #else |
| 49 | #define setlocale(x,y) |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Eric Andersen | 887ca79 | 2002-07-03 23:19:26 +0000 | [diff] [blame] | 52 | #include "pwd_.h" |
| 53 | #include "grp_.h" |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 54 | #include "shadow_.h" |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 55 | |
Rob Landley | 362dc2b | 2006-06-05 17:35:24 +0000 | [diff] [blame] | 56 | /* Try to pull in PATH_MAX */ |
| 57 | #include <limits.h> |
| 58 | #include <sys/param.h> |
| 59 | #ifndef PATH_MAX |
| 60 | #define PATH_MAX 256 |
| 61 | #endif |
| 62 | |
Denis Vlasenko | 9229794 | 2006-11-21 11:58:14 +0000 | [diff] [blame] | 63 | /* Tested to work correctly (IIRC :]) */ |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 64 | #define MAXINT(T) (T)( \ |
| 65 | ((T)-1) > 0 \ |
| 66 | ? (T)-1 \ |
| 67 | : (T)~((T)1 << (sizeof(T)*8-1)) \ |
| 68 | ) |
| 69 | |
| 70 | #define MININT(T) (T)( \ |
| 71 | ((T)-1) > 0 \ |
| 72 | ? (T)0 \ |
| 73 | : ((T)1 << (sizeof(T)*8-1)) \ |
| 74 | ) |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 75 | |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 76 | /* Large file support */ |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 77 | /* Note that CONFIG_LFS forces bbox to be built with all common ops |
| 78 | * (stat, lseek etc) mapped to "largefile" variants by libc. |
| 79 | * Practically it means that open() automatically has O_LARGEFILE added |
| 80 | * and all filesize/file_offset parameters and struct members are "large" |
| 81 | * (in today's world - signed 64bit). For full support of large files, |
| 82 | * we need a few helper #defines (below) and careful use of off_t |
| 83 | * instead of int/ssize_t. No lseek64(), O_LARGEFILE etc necessary */ |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 84 | #if ENABLE_LFS |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 85 | /* CONFIG_LFS is on */ |
| 86 | # if ULONG_MAX > 0xffffffff |
| 87 | /* "long" is long enough on this system */ |
| 88 | # define STRTOOFF strtol |
| 89 | # define SAFE_STRTOOFF safe_strtol |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 90 | # define XSTRTOUOFF xstrtoul |
Denis Vlasenko | 5c75960 | 2006-10-28 12:37:16 +0000 | [diff] [blame] | 91 | # define OFF_FMT "ld" |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 92 | # else |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 93 | /* "long" is too short, need "long long" */ |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 94 | # define STRTOOFF strtoll |
| 95 | # define SAFE_STRTOOFF safe_strtoll |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 96 | # define XSTRTOUOFF xstrtoull |
Denis Vlasenko | 5c75960 | 2006-10-28 12:37:16 +0000 | [diff] [blame] | 97 | # define OFF_FMT "lld" |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 98 | # endif |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 99 | #else |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 100 | # if 0 /* #if UINT_MAX == 0xffffffff */ |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 101 | /* Doesn't work. off_t is a long. gcc will throw warnings on printf("%d", off_t) |
| 102 | * even if long==int on this arch. Crap... */ |
| 103 | # define STRTOOFF strtol |
| 104 | # define SAFE_STRTOOFF safe_strtoi |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 105 | # define XSTRTOUOFF xstrtou |
Denis Vlasenko | 5c75960 | 2006-10-28 12:37:16 +0000 | [diff] [blame] | 106 | # define OFF_FMT "d" |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 107 | # else |
| 108 | # define STRTOOFF strtol |
| 109 | # define SAFE_STRTOOFF safe_strtol |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 110 | # define XSTRTOUOFF xstrtoul |
Denis Vlasenko | 5c75960 | 2006-10-28 12:37:16 +0000 | [diff] [blame] | 111 | # define OFF_FMT "ld" |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 112 | # endif |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 113 | #endif |
| 114 | /* scary. better ideas? (but do *test* them first!) */ |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 115 | #define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1))) |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 116 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 117 | /* Some useful definitions */ |
Bernhard Reutner-Fischer | 781e42d | 2006-05-26 14:41:40 +0000 | [diff] [blame] | 118 | #undef FALSE |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 119 | #define FALSE ((int) 0) |
Bernhard Reutner-Fischer | 781e42d | 2006-05-26 14:41:40 +0000 | [diff] [blame] | 120 | #undef TRUE |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 121 | #define TRUE ((int) 1) |
Bernhard Reutner-Fischer | 781e42d | 2006-05-26 14:41:40 +0000 | [diff] [blame] | 122 | #undef SKIP |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 123 | #define SKIP ((int) 2) |
| 124 | |
| 125 | /* for mtab.c */ |
| 126 | #define MTAB_GETMOUNTPT '1' |
| 127 | #define MTAB_GETDEVICE '2' |
| 128 | |
| 129 | #define BUF_SIZE 8192 |
| 130 | #define EXPAND_ALLOC 1024 |
| 131 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 132 | /* Macros for min/max. */ |
| 133 | #ifndef MIN |
| 134 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
| 135 | #endif |
| 136 | |
| 137 | #ifndef MAX |
| 138 | #define MAX(a,b) (((a)>(b))?(a):(b)) |
| 139 | #endif |
| 140 | |
Bernhard Reutner-Fischer | 421d9e5 | 2006-04-03 16:39:31 +0000 | [diff] [blame] | 141 | /* buffer allocation schemes */ |
| 142 | #ifdef CONFIG_FEATURE_BUFFERS_GO_ON_STACK |
| 143 | #define RESERVE_CONFIG_BUFFER(buffer,len) char buffer[len] |
| 144 | #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char buffer[len] |
| 145 | #define RELEASE_CONFIG_BUFFER(buffer) ((void)0) |
| 146 | #else |
| 147 | #ifdef CONFIG_FEATURE_BUFFERS_GO_IN_BSS |
| 148 | #define RESERVE_CONFIG_BUFFER(buffer,len) static char buffer[len] |
| 149 | #define RESERVE_CONFIG_UBUFFER(buffer,len) static unsigned char buffer[len] |
| 150 | #define RELEASE_CONFIG_BUFFER(buffer) ((void)0) |
| 151 | #else |
| 152 | #define RESERVE_CONFIG_BUFFER(buffer,len) char *buffer=xmalloc(len) |
| 153 | #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) |
| 154 | #define RELEASE_CONFIG_BUFFER(buffer) free (buffer) |
| 155 | #endif |
| 156 | #endif |
| 157 | |
| 158 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 159 | #if (__GLIBC__ < 2) |
| 160 | int vdprintf(int d, const char *format, va_list ap); |
| 161 | #endif |
| 162 | // This is declared here rather than #including <libgen.h> in order to avoid |
| 163 | // confusing the two versions of basename. See the dirname/basename man page |
| 164 | // for details. |
| 165 | char *dirname(char *path); |
| 166 | /* Include our own copy of struct sysinfo to avoid binary compatibility |
| 167 | * problems with Linux 2.4, which changed things. Grumble, grumble. */ |
| 168 | struct sysinfo { |
| 169 | long uptime; /* Seconds since boot */ |
| 170 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ |
| 171 | unsigned long totalram; /* Total usable main memory size */ |
| 172 | unsigned long freeram; /* Available memory size */ |
| 173 | unsigned long sharedram; /* Amount of shared memory */ |
| 174 | unsigned long bufferram; /* Memory used by buffers */ |
| 175 | unsigned long totalswap; /* Total swap space size */ |
| 176 | unsigned long freeswap; /* swap space still available */ |
| 177 | unsigned short procs; /* Number of current processes */ |
| 178 | unsigned short pad; /* Padding needed for m68k */ |
| 179 | unsigned long totalhigh; /* Total high memory size */ |
| 180 | unsigned long freehigh; /* Available high memory size */ |
| 181 | unsigned int mem_unit; /* Memory unit size in bytes */ |
| 182 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 183 | }; |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 184 | extern int sysinfo(struct sysinfo* info); |
Denis Vlasenko | 3538b9a | 2006-09-06 18:36:50 +0000 | [diff] [blame] | 185 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 186 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 187 | extern void chomp(char *s); |
| 188 | extern void trim(char *s); |
| 189 | extern char *skip_whitespace(const char *); |
Paul Fox | 0b62158 | 2005-08-09 19:38:05 +0000 | [diff] [blame] | 190 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 191 | extern const char *bb_mode_string(int mode); |
| 192 | extern int is_directory(const char *name, int followLinks, struct stat *statBuf); |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 193 | extern int remove_file(const char *path, int flags); |
| 194 | extern int copy_file(const char *source, const char *dest, int flags); |
| 195 | extern int recursive_action(const char *fileName, int recurse, |
Denis Vlasenko | 8c35d65 | 2006-10-27 23:42:25 +0000 | [diff] [blame] | 196 | int followLinks, int depthFirst, |
| 197 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData, int depth), |
| 198 | int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth), |
| 199 | void* userData, int depth); |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 200 | extern int device_open(const char *device, int mode); |
| 201 | extern int get_console_fd(void); |
| 202 | extern char *find_block_device(char *path); |
| 203 | extern off_t bb_copyfd_size(int fd1, int fd2, off_t size); |
| 204 | extern off_t bb_copyfd_eof(int fd1, int fd2); |
| 205 | extern char bb_process_escape_sequence(const char **ptr); |
| 206 | extern char *bb_get_last_path_component(char *path); |
| 207 | |
| 208 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 209 | extern DIR *xopendir(const char *path); |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 210 | extern DIR *warn_opendir(const char *path); |
| 211 | |
| 212 | char *xgetcwd(char *cwd); |
| 213 | char *xreadlink(const char *path); |
| 214 | extern void xstat(char *filename, struct stat *buf); |
| 215 | extern pid_t spawn(char **argv); |
| 216 | extern pid_t xspawn(char **argv); |
| 217 | extern int wait4pid(int pid); |
| 218 | extern void xsetgid(gid_t gid); |
| 219 | extern void xsetuid(uid_t uid); |
| 220 | extern void xdaemon(int nochdir, int noclose); |
| 221 | extern void xchdir(const char *path); |
| 222 | extern void xsetenv(const char *key, const char *value); |
| 223 | extern int xopen(const char *pathname, int flags); |
| 224 | extern int xopen3(const char *pathname, int flags, int mode); |
| 225 | extern off_t xlseek(int fd, off_t offset, int whence); |
| 226 | extern off_t fdlength(int fd); |
| 227 | |
| 228 | extern int xsocket(int domain, int type, int protocol); |
| 229 | extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); |
| 230 | extern void xlisten(int s, int backlog); |
| 231 | extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen); |
| 232 | extern int xconnect_tcp_v4(struct sockaddr_in *s_addr); |
| 233 | extern struct hostent *xgethostbyname(const char *name); |
| 234 | extern struct hostent *xgethostbyname2(const char *name, int af); |
| 235 | |
| 236 | extern char *xstrdup(const char *s); |
| 237 | extern char *xstrndup(const char *s, int n); |
| 238 | extern char *safe_strncpy(char *dst, const char *src, size_t size); |
| 239 | extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); |
| 240 | |
| 241 | /* dmalloc will redefine these to it's own implementation. It is safe |
| 242 | * to have the prototypes here unconditionally. */ |
| 243 | extern void *xmalloc(size_t size); |
| 244 | extern void *xrealloc(void *old, size_t size); |
| 245 | extern void *xzalloc(size_t size); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 246 | |
Denis Vlasenko | ea62077 | 2006-10-14 02:23:43 +0000 | [diff] [blame] | 247 | extern ssize_t safe_read(int fd, void *buf, size_t count); |
| 248 | extern ssize_t full_read(int fd, void *buf, size_t count); |
| 249 | extern void xread(int fd, void *buf, size_t count); |
| 250 | extern unsigned char xread_char(int fd); |
| 251 | extern char *reads(int fd, char *buf, size_t count); |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 252 | extern ssize_t read_close(int fd, void *buf, size_t count); |
| 253 | extern ssize_t open_read_close(const char *filename, void *buf, size_t count); |
| 254 | extern void *xmalloc_open_read_close(const char *filename, size_t *sizep); |
Denis Vlasenko | ea62077 | 2006-10-14 02:23:43 +0000 | [diff] [blame] | 255 | |
| 256 | extern ssize_t safe_write(int fd, const void *buf, size_t count); |
| 257 | extern ssize_t full_write(int fd, const void *buf, size_t count); |
| 258 | extern void xwrite(int fd, void *buf, size_t count); |
| 259 | |
Denis Vlasenko | 1de0830 | 2006-10-26 23:32:43 +0000 | [diff] [blame] | 260 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ |
Denis Vlasenko | ddec5af | 2006-10-26 23:25:17 +0000 | [diff] [blame] | 261 | extern void xprint_and_close_file(FILE *file); |
| 262 | extern char *xmalloc_fgets(FILE *file); |
Denis Vlasenko | 1de0830 | 2006-10-26 23:32:43 +0000 | [diff] [blame] | 263 | /* Read up to (and including) TERMINATING_STRING: */ |
Denis Vlasenko | ddec5af | 2006-10-26 23:25:17 +0000 | [diff] [blame] | 264 | extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string); |
| 265 | /* Chops off '\n' from the end, unlike fgets: */ |
| 266 | extern char *xmalloc_getline(FILE *file); |
| 267 | extern char *bb_get_chunk_from_file(FILE *file, int *end); |
| 268 | extern void die_if_ferror(FILE *file, const char *msg); |
| 269 | extern void die_if_ferror_stdout(void); |
| 270 | extern void xfflush_stdout(void); |
Denis Vlasenko | f0ed376 | 2006-10-26 23:21:47 +0000 | [diff] [blame] | 271 | extern void fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; |
Denis Vlasenko | ddec5af | 2006-10-26 23:25:17 +0000 | [diff] [blame] | 272 | extern int fclose_if_not_stdin(FILE *file); |
| 273 | extern FILE *xfopen(const char *filename, const char *mode); |
| 274 | /* Prints warning to stderr and returns NULL on failure: */ |
| 275 | extern FILE *fopen_or_warn(const char *filename, const char *mode); |
| 276 | /* "Opens" stdin if filename is special, else just opens file: */ |
| 277 | extern FILE *fopen_or_warn_stdin(const char *filename); |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 278 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 279 | |
Denis Vlasenko | aae0311 | 2006-11-05 00:44:39 +0000 | [diff] [blame] | 280 | extern void smart_ulltoa5(unsigned long long ul, char buf[5]); |
Rob Landley | c9c1a41 | 2006-07-12 19:17:55 +0000 | [diff] [blame] | 281 | extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen); |
| 282 | extern char *utoa(unsigned n); |
| 283 | extern void itoa_to_buf(int n, char *buf, unsigned buflen); |
| 284 | extern char *itoa(int n); |
Rob Landley | c5b1d4d | 2006-03-13 15:45:16 +0000 | [diff] [blame] | 285 | |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 286 | // FIXME: the prototype doesn't match libc strtoXX -> confusion |
| 287 | // FIXME: alot of unchecked strtoXXX are still in tree |
| 288 | // FIXME: atoi_or_else(str, N)? |
| 289 | extern int safe_strtoi(const char *arg, int* value); |
| 290 | extern int safe_strtou(const char *arg, unsigned* value); |
| 291 | extern int safe_strtod(const char *arg, double* value); |
| 292 | extern int safe_strtol(const char *arg, long* value); |
| 293 | extern int safe_strtoll(const char *arg, long long* value); |
| 294 | extern int safe_strtoul(const char *arg, unsigned long* value); |
| 295 | extern int safe_strtoull(const char *arg, unsigned long long* value); |
| 296 | extern int safe_strtou32(const char *arg, uint32_t* value); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 297 | |
| 298 | struct suffix_mult { |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 299 | const char *suffix; |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 300 | unsigned mult; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 301 | }; |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 302 | unsigned long long xstrtoull(const char *numstr, int base); |
| 303 | unsigned long long xatoull(const char *numstr); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 304 | unsigned long xstrtoul_range_sfx(const char *numstr, int base, |
Denis Vlasenko | cf94446 | 2006-10-03 19:02:20 +0000 | [diff] [blame] | 305 | unsigned long lower, |
| 306 | unsigned long upper, |
| 307 | const struct suffix_mult *suffixes); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 308 | unsigned long xstrtoul_range(const char *numstr, int base, |
Denis Vlasenko | cf94446 | 2006-10-03 19:02:20 +0000 | [diff] [blame] | 309 | unsigned long lower, |
| 310 | unsigned long upper); |
Denis Vlasenko | 1114de7 | 2006-10-10 23:26:05 +0000 | [diff] [blame] | 311 | unsigned long xstrtoul_sfx(const char *numstr, int base, |
| 312 | const struct suffix_mult *suffixes); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 313 | unsigned long xstrtoul(const char *numstr, int base); |
| 314 | unsigned long xatoul_range_sfx(const char *numstr, |
| 315 | unsigned long lower, |
| 316 | unsigned long upper, |
| 317 | const struct suffix_mult *suffixes); |
| 318 | unsigned long xatoul_sfx(const char *numstr, |
| 319 | const struct suffix_mult *suffixes); |
| 320 | unsigned long xatoul_range(const char *numstr, |
Denis Vlasenko | cf94446 | 2006-10-03 19:02:20 +0000 | [diff] [blame] | 321 | unsigned long lower, |
| 322 | unsigned long upper); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 323 | unsigned long xatoul(const char *numstr); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 324 | long xstrtol_range_sfx(const char *numstr, int base, |
Denis Vlasenko | cf94446 | 2006-10-03 19:02:20 +0000 | [diff] [blame] | 325 | long lower, |
| 326 | long upper, |
| 327 | const struct suffix_mult *suffixes); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 328 | long xstrtol_range(const char *numstr, int base, long lower, long upper); |
| 329 | long xatol_range_sfx(const char *numstr, |
| 330 | long lower, |
| 331 | long upper, |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 332 | const struct suffix_mult *suffixes); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 333 | long xatol_range(const char *numstr, long lower, long upper); |
| 334 | long xatol_sfx(const char *numstr, const struct suffix_mult *suffixes); |
| 335 | long xatol(const char *numstr); |
| 336 | /* Specialized: */ |
Denis Vlasenko | 83ea643 | 2006-11-16 02:27:24 +0000 | [diff] [blame] | 337 | unsigned xatou_range(const char *numstr, unsigned lower, unsigned upper); |
| 338 | unsigned xatou_sfx(const char *numstr, const struct suffix_mult *suffixes); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 339 | unsigned xatou(const char *numstr); |
Denis Vlasenko | ca3c981 | 2006-10-08 23:36:17 +0000 | [diff] [blame] | 340 | int xatoi_range(const char *numstr, int lower, int upper); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 341 | int xatoi(const char *numstr); |
| 342 | /* Using xatoi() instead of naive atoi() is not always convenient - |
| 343 | * in many places people want *non-negative* values, but store them |
| 344 | * in signed int. Therefore we need this one: |
| 345 | * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */ |
| 346 | int xatoi_u(const char *numstr); |
| 347 | uint32_t xatou32(const char *numstr); |
| 348 | /* Useful for reading port numbers */ |
| 349 | uint16_t xatou16(const char *numstr); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 350 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 351 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 352 | /* These parse entries in /etc/passwd and /etc/group. This is desirable |
| 353 | * for BusyBox since we want to avoid using the glibc NSS stuff, which |
Bernhard Reutner-Fischer | d5bd137 | 2005-09-20 21:06:17 +0000 | [diff] [blame] | 354 | * increases target size and is often not needed on embedded systems. */ |
| 355 | extern long bb_xgetpwnam(const char *name); |
| 356 | extern long bb_xgetgrnam(const char *name); |
Denis Vlasenko | cf94446 | 2006-10-03 19:02:20 +0000 | [diff] [blame] | 357 | extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix); |
| 358 | extern char *bb_getpwuid(char *name, long uid, int bufsize); |
| 359 | extern char *bb_getgrgid(char *group, long gid, int bufsize); |
Denis Vlasenko | de59c0f | 2006-10-05 22:50:22 +0000 | [diff] [blame] | 360 | /* from chpst */ |
| 361 | struct bb_uidgid_t { |
| 362 | uid_t uid; |
| 363 | gid_t gid; |
| 364 | }; |
| 365 | extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/); |
| 366 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 367 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 368 | enum { BB_GETOPT_ERROR = 0x80000000 }; |
| 369 | extern const char *opt_complementary; |
| 370 | extern const struct option *applet_long_options; |
| 371 | extern uint32_t option_mask32; |
| 372 | extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); |
| 373 | |
| 374 | |
| 375 | typedef struct llist_s { |
| 376 | char *data; |
| 377 | struct llist_s *link; |
| 378 | } llist_t; |
| 379 | extern void llist_add_to(llist_t **old_head, void *data); |
| 380 | extern void llist_add_to_end(llist_t **list_head, void *data); |
| 381 | extern void *llist_pop(llist_t **elm); |
| 382 | extern void llist_free(llist_t *elm, void (*freeit)(void *data)); |
| 383 | extern llist_t* rev_llist(llist_t *list); |
| 384 | |
| 385 | enum { |
| 386 | LOGMODE_NONE = 0, |
| 387 | LOGMODE_STDIO = 1<<0, |
| 388 | LOGMODE_SYSLOG = 1<<1, |
| 389 | LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO, |
| 390 | }; |
| 391 | extern const char *msg_eol; |
| 392 | extern int logmode; |
| 393 | extern int die_sleep; |
| 394 | extern int xfunc_error_retval; |
| 395 | extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; |
| 396 | extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 397 | extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
| 398 | extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 399 | extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
| 400 | extern void bb_vherror_msg(const char *s, va_list p); |
| 401 | extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 402 | extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
| 403 | extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN; |
| 404 | extern void bb_perror_nomsg(void); |
| 405 | extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 406 | /* These two are used internally -- you shouldn't need to use them */ |
| 407 | extern void bb_verror_msg(const char *s, va_list p, const char *strerr); |
| 408 | extern void bb_vperror_msg(const char *s, va_list p); |
| 409 | extern void bb_vinfo_msg(const char *s, va_list p); |
| 410 | |
| 411 | |
| 412 | extern int bb_echo(int argc, char** argv); |
| 413 | extern int bb_test(int argc, char** argv); |
| 414 | |
| 415 | #ifndef BUILD_INDIVIDUAL |
| 416 | extern struct BB_applet *find_applet_by_name(const char *name); |
| 417 | extern void run_applet_by_name(const char *name, int argc, char **argv); |
| 418 | #endif |
| 419 | |
| 420 | extern struct mntent *find_mount_point(const char *name, const char *table); |
| 421 | extern void erase_mtab(const char * name); |
| 422 | extern unsigned int tty_baud_to_value(speed_t speed); |
| 423 | extern speed_t tty_value_to_baud(unsigned int value); |
| 424 | extern void bb_warn_ignoring_args(int n); |
| 425 | |
| 426 | extern int get_linux_version_code(void); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 427 | |
Rob Landley | 1d589b2 | 2005-11-29 23:47:10 +0000 | [diff] [blame] | 428 | extern char *query_loop(const char *device); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 429 | extern int del_loop(const char *device); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 430 | extern int set_loop(char **device, const char *file, unsigned long long offset); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 431 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 432 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 433 | const char *make_human_readable_str(unsigned long long size, |
Eric Andersen | 97e2426 | 2003-08-22 23:08:37 +0000 | [diff] [blame] | 434 | unsigned long block_size, unsigned long display_unit); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 435 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 436 | char *bb_askpass(int timeout, const char * prompt); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 437 | int bb_ask_confirmation(void); |
Eric Andersen | e76c3b0 | 2001-04-05 03:14:39 +0000 | [diff] [blame] | 438 | int klogctl(int type, char * b, int len); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 439 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 440 | extern int bb_parse_mode(const char* s, mode_t* theMode); |
| 441 | |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 442 | char *concat_path_file(const char *path, const char *filename); |
Glenn L McGrath | 393183d | 2003-05-26 14:07:50 +0000 | [diff] [blame] | 443 | char *concat_subpath_file(const char *path, const char *filename); |
Eric Andersen | c911a43 | 2001-05-15 17:42:16 +0000 | [diff] [blame] | 444 | char *last_char_is(const char *s, int c); |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 445 | |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 446 | int execable_file(const char *name); |
| 447 | char *find_execable(const char *filename); |
| 448 | int exists_execable(const char *filename); |
| 449 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 450 | USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out); |
| 451 | int inflate(int in, int out); |
Glenn L McGrath | 4949faf | 2001-04-11 16:23:35 +0000 | [diff] [blame] | 452 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 453 | int create_icmp_socket(void); |
| 454 | int create_icmp6_socket(void); |
Denis Vlasenko | 1457915 | 2006-10-26 01:09:46 +0000 | [diff] [blame] | 455 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 456 | unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port); |
| 457 | void bb_lookup_host(struct sockaddr_in *s_in, const char *host); |
Glenn L McGrath | 78b0e37 | 2001-06-26 02:06:08 +0000 | [diff] [blame] | 458 | |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 459 | int bb_make_directory(char *path, long mode, int flags); |
Matt Kraai | ceeff73 | 2001-06-21 19:41:37 +0000 | [diff] [blame] | 460 | |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 461 | int get_signum(const char *name); |
| 462 | const char *get_signame(int number); |
Rob Landley | c9c1a41 | 2006-07-12 19:17:55 +0000 | [diff] [blame] | 463 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 464 | char *bb_simplify_path(const char *path); |
Eric Andersen | 3450636 | 2001-08-02 05:02:46 +0000 | [diff] [blame] | 465 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 466 | #define FAIL_DELAY 3 |
| 467 | extern void bb_do_delay(int seconds); |
| 468 | extern void change_identity(const struct passwd *pw); |
| 469 | extern const char *change_identity_e2str(const struct passwd *pw); |
| 470 | extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args); |
| 471 | #ifdef CONFIG_SELINUX |
| 472 | extern void renew_current_security_context(void); |
| 473 | extern void set_current_security_context(security_context_t sid); |
| 474 | #endif |
| 475 | extern int run_parts(char **args, const unsigned char test_mode, char **env); |
| 476 | extern int restricted_shell(const char *shell); |
| 477 | extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); |
| 478 | extern int correct_password(const struct passwd *pw); |
| 479 | extern char *pw_encrypt(const char *clear, const char *salt); |
| 480 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); |
Denis Vlasenko | 5af906e | 2006-11-05 18:05:09 +0000 | [diff] [blame] | 481 | extern int index_in_str_array(const char * const string_array[], const char *key); |
| 482 | extern int index_in_substr_array(const char * const string_array[], const char *key); |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 483 | extern void print_login_issue(const char *issue_file, const char *tty); |
| 484 | extern void print_login_prompt(void); |
| 485 | #ifdef BB_NOMMU |
| 486 | extern void vfork_daemon(int nochdir, int noclose); |
| 487 | extern void vfork_daemon_rexec(int nochdir, int noclose, |
| 488 | int argc, char **argv, char *foreground_opt); |
| 489 | #endif |
| 490 | extern int get_terminal_width_height(int fd, int *width, int *height); |
| 491 | extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *)); |
| 492 | |
| 493 | int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name); |
| 494 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); |
| 495 | void reset_ino_dev_hashtable(void); |
| 496 | |
| 497 | |
| 498 | #ifndef COMM_LEN |
| 499 | #ifdef TASK_COMM_LEN |
Denis Vlasenko | fa07680 | 2006-11-05 00:38:51 +0000 | [diff] [blame] | 500 | enum { COMM_LEN = TASK_COMM_LEN }; |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 501 | #else |
| 502 | /* synchronize with sizeof(task_struct.comm) in /usr/include/linux/sched.h */ |
Denis Vlasenko | fa07680 | 2006-11-05 00:38:51 +0000 | [diff] [blame] | 503 | enum { COMM_LEN = 16 }; |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 504 | #endif |
| 505 | #endif |
| 506 | typedef struct { |
Denis Vlasenko | 459e4d6 | 2006-11-05 00:43:51 +0000 | [diff] [blame] | 507 | DIR *dir; |
| 508 | /* Fields are set to 0/NULL if failed to determine (or not requested) */ |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 509 | char *cmd; |
Denis Vlasenko | 459e4d6 | 2006-11-05 00:43:51 +0000 | [diff] [blame] | 510 | unsigned long rss; |
| 511 | unsigned long stime, utime; |
| 512 | unsigned pid; |
| 513 | unsigned ppid; |
| 514 | unsigned pgid; |
| 515 | unsigned sid; |
| 516 | unsigned uid; |
| 517 | unsigned gid; |
| 518 | /* basename of executable file in call to exec(2), size from */ |
| 519 | /* sizeof(task_struct.comm) in /usr/include/linux/sched.h */ |
| 520 | char state[4]; |
| 521 | char comm[COMM_LEN]; |
| 522 | // user/group? - use passwd/group parsing functions |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 523 | } procps_status_t; |
Denis Vlasenko | 459e4d6 | 2006-11-05 00:43:51 +0000 | [diff] [blame] | 524 | enum { |
| 525 | PSSCAN_PID = 1 << 0, |
| 526 | PSSCAN_PPID = 1 << 1, |
| 527 | PSSCAN_PGID = 1 << 2, |
| 528 | PSSCAN_SID = 1 << 3, |
| 529 | PSSCAN_UIDGID = 1 << 4, |
| 530 | PSSCAN_COMM = 1 << 5, |
| 531 | PSSCAN_CMD = 1 << 6, |
| 532 | PSSCAN_STATE = 1 << 7, |
| 533 | PSSCAN_RSS = 1 << 8, |
| 534 | PSSCAN_STIME = 1 << 9, |
| 535 | PSSCAN_UTIME = 1 << 10, |
| 536 | /* These are all retrieved from proc/NN/stat in one go: */ |
| 537 | PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID |
| 538 | | PSSCAN_COMM | PSSCAN_STATE |
| 539 | | PSSCAN_RSS | PSSCAN_STIME | PSSCAN_UTIME, |
| 540 | }; |
| 541 | procps_status_t* alloc_procps_scan(int flags); |
| 542 | void free_procps_scan(procps_status_t* sp); |
| 543 | procps_status_t* procps_scan(procps_status_t* sp, int flags); |
Denis Vlasenko | 35fb512 | 2006-11-01 09:16:49 +0000 | [diff] [blame] | 544 | pid_t *find_pid_by_name(const char* procName); |
| 545 | pid_t *pidlist_reverse(pid_t *pidList); |
Denis Vlasenko | 459e4d6 | 2006-11-05 00:43:51 +0000 | [diff] [blame] | 546 | void clear_username_cache(void); |
| 547 | const char* get_cached_username(uid_t uid); |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 548 | |
| 549 | |
| 550 | extern const char bb_uuenc_tbl_base64[]; |
| 551 | extern const char bb_uuenc_tbl_std[]; |
| 552 | void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl); |
| 553 | |
Denis Vlasenko | dd539f7 | 2006-11-01 20:20:37 +0000 | [diff] [blame] | 554 | typedef struct sha1_ctx_t { |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 555 | uint32_t count[2]; |
| 556 | uint32_t hash[5]; |
| 557 | uint32_t wbuf[16]; |
| 558 | } sha1_ctx_t; |
| 559 | void sha1_begin(sha1_ctx_t *ctx); |
| 560 | void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx); |
| 561 | void *sha1_end(void *resbuf, sha1_ctx_t *ctx); |
| 562 | |
Denis Vlasenko | dd539f7 | 2006-11-01 20:20:37 +0000 | [diff] [blame] | 563 | typedef struct md5_ctx_t { |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 564 | uint32_t A; |
| 565 | uint32_t B; |
| 566 | uint32_t C; |
| 567 | uint32_t D; |
| 568 | uint64_t total; |
| 569 | uint32_t buflen; |
| 570 | char buffer[128]; |
| 571 | } md5_ctx_t; |
| 572 | void md5_begin(md5_ctx_t *ctx); |
| 573 | void md5_hash(const void *data, size_t length, md5_ctx_t *ctx); |
| 574 | void *md5_end(void *resbuf, md5_ctx_t *ctx); |
| 575 | |
| 576 | uint32_t *crc32_filltable(int endian); |
| 577 | |
| 578 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 579 | enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 580 | FILEUTILS_PRESERVE_STATUS = 1, |
Matt Kraai | 4c557bf | 2001-10-05 01:35:10 +0000 | [diff] [blame] | 581 | FILEUTILS_DEREFERENCE = 2, |
Matt Kraai | 0144103 | 2001-04-24 01:30:02 +0000 | [diff] [blame] | 582 | FILEUTILS_RECUR = 4, |
| 583 | FILEUTILS_FORCE = 8, |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 584 | FILEUTILS_INTERACTIVE = 0x10, |
| 585 | FILEUTILS_MAKE_HARDLINK = 0x20, |
| 586 | FILEUTILS_MAKE_SOFTLINK = 0x40, |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 587 | }; |
Denis Vlasenko | f24e1f4 | 2006-10-21 23:40:20 +0000 | [diff] [blame] | 588 | #define FILEUTILS_CP_OPTSTR "pdRfils" |
Matt Kraai | 91b2855 | 2001-04-23 18:53:07 +0000 | [diff] [blame] | 589 | |
Denis Vlasenko | 8f8f268 | 2006-10-03 21:00:43 +0000 | [diff] [blame] | 590 | extern const char *applet_name; |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 591 | extern const char BB_BANNER[]; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 592 | |
Denis Vlasenko | 0b5fd45 | 2006-09-19 09:55:09 +0000 | [diff] [blame] | 593 | extern const char bb_msg_full_version[]; |
| 594 | extern const char bb_msg_memory_exhausted[]; |
| 595 | extern const char bb_msg_invalid_date[]; |
Denis Vlasenko | 0b5fd45 | 2006-09-19 09:55:09 +0000 | [diff] [blame] | 596 | extern const char bb_msg_read_error[]; |
| 597 | extern const char bb_msg_write_error[]; |
| 598 | extern const char bb_msg_name_longer_than_foo[]; |
| 599 | extern const char bb_msg_unknown[]; |
| 600 | extern const char bb_msg_can_not_create_raw_socket[]; |
| 601 | extern const char bb_msg_perm_denied_are_you_root[]; |
| 602 | extern const char bb_msg_requires_arg[]; |
| 603 | extern const char bb_msg_invalid_arg[]; |
| 604 | extern const char bb_msg_standard_input[]; |
| 605 | extern const char bb_msg_standard_output[]; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 606 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 607 | extern const char bb_path_mtab_file[]; |
Denis Vlasenko | 0b5fd45 | 2006-09-19 09:55:09 +0000 | [diff] [blame] | 608 | extern const char bb_path_nologin_file[]; |
| 609 | extern const char bb_path_passwd_file[]; |
| 610 | extern const char bb_path_shadow_file[]; |
| 611 | extern const char bb_path_gshadow_file[]; |
| 612 | extern const char bb_path_group_file[]; |
| 613 | extern const char bb_path_securetty_file[]; |
| 614 | extern const char bb_path_motd_file[]; |
| 615 | extern const char bb_path_wtmp_file[]; |
| 616 | extern const char bb_dev_null[]; |
"Vladimir N. Oleynik" | 6f347ef | 2005-10-15 10:23:55 +0000 | [diff] [blame] | 617 | |
| 618 | #ifndef BUFSIZ |
| 619 | #define BUFSIZ 4096 |
| 620 | #endif |
| 621 | extern char bb_common_bufsiz1[BUFSIZ+1]; |
| 622 | |
Denis Vlasenko | dca0b70 | 2006-10-27 09:05:02 +0000 | [diff] [blame] | 623 | /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, |
| 624 | * use bb_default_login_shell and following defines. |
| 625 | * If you change LIBBB_DEFAULT_LOGIN_SHELL, |
| 626 | * don't forget to change increment constant. */ |
Glenn L McGrath | dc4e75e | 2003-09-02 02:36:18 +0000 | [diff] [blame] | 627 | #define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" |
Denis Vlasenko | 0b5fd45 | 2006-09-19 09:55:09 +0000 | [diff] [blame] | 628 | extern const char bb_default_login_shell[]; |
Glenn L McGrath | dc4e75e | 2003-09-02 02:36:18 +0000 | [diff] [blame] | 629 | /* "/bin/sh" */ |
| 630 | #define DEFAULT_SHELL (bb_default_login_shell+1) |
| 631 | /* "sh" */ |
| 632 | #define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) |
| 633 | |
| 634 | |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 635 | #ifdef CONFIG_FEATURE_DEVFS |
Matt Kraai | 439e3df | 2001-07-23 14:52:08 +0000 | [diff] [blame] | 636 | # define CURRENT_VC "/dev/vc/0" |
| 637 | # define VC_1 "/dev/vc/1" |
| 638 | # define VC_2 "/dev/vc/2" |
| 639 | # define VC_3 "/dev/vc/3" |
| 640 | # define VC_4 "/dev/vc/4" |
| 641 | # define VC_5 "/dev/vc/5" |
Eric Andersen | 592ebd5 | 2003-07-22 07:33:14 +0000 | [diff] [blame] | 642 | #if defined(__sh__) || defined(__H8300H__) || defined(__H8300S__) |
| 643 | /* Yes, this sucks, but both SH (including sh64) and H8 have a SCI(F) for their |
| 644 | respective serial ports .. as such, we can't use the common device paths for |
| 645 | these. -- PFM */ |
| 646 | # define SC_0 "/dev/ttsc/0" |
| 647 | # define SC_1 "/dev/ttsc/1" |
| 648 | # define SC_FORMAT "/dev/ttsc/%d" |
| 649 | #else |
| 650 | # define SC_0 "/dev/tts/0" |
| 651 | # define SC_1 "/dev/tts/1" |
| 652 | # define SC_FORMAT "/dev/tts/%d" |
| 653 | #endif |
Matt Kraai | 439e3df | 2001-07-23 14:52:08 +0000 | [diff] [blame] | 654 | # define VC_FORMAT "/dev/vc/%d" |
Eric Andersen | c7a3fb9 | 2002-03-20 15:25:25 +0000 | [diff] [blame] | 655 | # define LOOP_FORMAT "/dev/loop/%d" |
Denis Vlasenko | 0b193a7 | 2006-09-29 21:47:11 +0000 | [diff] [blame] | 656 | # define LOOP_NAME "/dev/loop/" |
Eric Andersen | 5f28455 | 2003-11-14 03:11:29 +0000 | [diff] [blame] | 657 | # define FB_0 "/dev/fb/0" |
Matt Kraai | 439e3df | 2001-07-23 14:52:08 +0000 | [diff] [blame] | 658 | #else |
| 659 | # define CURRENT_VC "/dev/tty0" |
| 660 | # define VC_1 "/dev/tty1" |
| 661 | # define VC_2 "/dev/tty2" |
| 662 | # define VC_3 "/dev/tty3" |
| 663 | # define VC_4 "/dev/tty4" |
| 664 | # define VC_5 "/dev/tty5" |
Eric Andersen | 592ebd5 | 2003-07-22 07:33:14 +0000 | [diff] [blame] | 665 | #if defined(__sh__) || defined(__H8300H__) || defined(__H8300S__) |
| 666 | # define SC_0 "/dev/ttySC0" |
| 667 | # define SC_1 "/dev/ttySC1" |
| 668 | # define SC_FORMAT "/dev/ttySC%d" |
| 669 | #else |
| 670 | # define SC_0 "/dev/ttyS0" |
| 671 | # define SC_1 "/dev/ttyS1" |
| 672 | # define SC_FORMAT "/dev/ttyS%d" |
| 673 | #endif |
Matt Kraai | 439e3df | 2001-07-23 14:52:08 +0000 | [diff] [blame] | 674 | # define VC_FORMAT "/dev/tty%d" |
Eric Andersen | c7a3fb9 | 2002-03-20 15:25:25 +0000 | [diff] [blame] | 675 | # define LOOP_FORMAT "/dev/loop%d" |
Denis Vlasenko | 0b193a7 | 2006-09-29 21:47:11 +0000 | [diff] [blame] | 676 | # define LOOP_NAME "/dev/loop" |
Eric Andersen | 5f28455 | 2003-11-14 03:11:29 +0000 | [diff] [blame] | 677 | # define FB_0 "/dev/fb0" |
Matt Kraai | 439e3df | 2001-07-23 14:52:08 +0000 | [diff] [blame] | 678 | #endif |
| 679 | |
| 680 | /* The following devices are the same on devfs and non-devfs systems. */ |
| 681 | #define CURRENT_TTY "/dev/tty" |
| 682 | #define CONSOLE_DEV "/dev/console" |
| 683 | |
Rob Landley | c57ec37 | 2006-04-10 17:07:15 +0000 | [diff] [blame] | 684 | |
Rob Landley | b623a54 | 2006-05-31 22:09:03 +0000 | [diff] [blame] | 685 | #ifndef RB_POWER_OFF |
| 686 | /* Stop system and switch power off if possible. */ |
| 687 | #define RB_POWER_OFF 0x4321fedc |
| 688 | #endif |
| 689 | |
Rob Landley | 4ae905a | 2006-07-06 17:22:54 +0000 | [diff] [blame] | 690 | // Make sure we call functions instead of macros. |
| 691 | #undef isalnum |
| 692 | #undef isalpha |
| 693 | #undef isascii |
| 694 | #undef isblank |
| 695 | #undef iscntrl |
| 696 | #undef isdigit |
| 697 | #undef isgraph |
| 698 | #undef islower |
| 699 | #undef isprint |
| 700 | #undef ispunct |
| 701 | #undef isspace |
| 702 | #undef isupper |
| 703 | #undef isxdigit |
| 704 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 705 | #ifdef DMALLOC |
| 706 | #include <dmalloc.h> |
| 707 | #endif |
| 708 | |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 709 | #endif /* __LIBBUSYBOX_H__ */ |