introduce setsockopt_reuseaddr(int fd), setsockopt_broadcast(int fd),
[oweals/busybox.git] / include / libbb.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Busybox main internal header file
4  *
5  * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
6  * Permission has been granted to redistribute this code under the GPL.
7  * 
8  * Licensed under the GPL version 2, see the file LICENSE in this tarball.
9  */
10 #ifndef __LIBBUSYBOX_H__
11 #define __LIBBUSYBOX_H__    1
12
13 #include "platform.h"
14
15 #include <ctype.h>
16 #include <dirent.h>
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <inttypes.h>
20 #include <malloc.h>
21 #include <netdb.h>
22 #include <setjmp.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <strings.h>
29 #include <sys/ioctl.h>
30 #include <sys/mman.h>
31 #include <sys/socket.h>
32 #include <sys/stat.h>
33 #include <sys/statfs.h>
34 #include <sys/time.h>
35 #include <sys/types.h>
36 #include <sys/wait.h>
37 #include <termios.h>
38 #include <time.h>
39 #include <unistd.h>
40 #include <utime.h>
41
42 #ifdef CONFIG_SELINUX
43 #include <selinux/selinux.h>
44 #endif
45
46 #ifdef CONFIG_LOCALE_SUPPORT
47 #include <locale.h>
48 #else
49 #define setlocale(x,y)
50 #endif
51
52 #include "pwd_.h"
53 #include "grp_.h"
54 #include "shadow_.h"
55
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
63 /* Tested to work correctly (IIRC :]) */
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         )
75
76 /* Large file support */
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 */
84 #if ENABLE_LFS
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
90 #  define XSTRTOUOFF xstrtoul
91 #  define OFF_FMT "ld"
92 # else
93 /* "long" is too short, need "long long" */
94 #  define STRTOOFF strtoll
95 #  define SAFE_STRTOOFF safe_strtoll
96 #  define XSTRTOUOFF xstrtoull
97 #  define OFF_FMT "lld"
98 # endif
99 #else
100 # if 0 /* #if UINT_MAX == 0xffffffff */
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
105 #  define XSTRTOUOFF xstrtou
106 #  define OFF_FMT "d"
107 # else
108 #  define STRTOOFF strtol
109 #  define SAFE_STRTOOFF safe_strtol
110 #  define XSTRTOUOFF xstrtoul
111 #  define OFF_FMT "ld"
112 # endif
113 #endif
114 /* scary. better ideas? (but do *test* them first!) */
115 #define OFF_T_MAX  ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
116
117 /* Some useful definitions */
118 #undef FALSE
119 #define FALSE   ((int) 0)
120 #undef TRUE
121 #define TRUE    ((int) 1)
122 #undef SKIP
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
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
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
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.. */
183 };
184 extern int sysinfo(struct sysinfo* info);
185
186
187 extern void chomp(char *s);
188 extern void trim(char *s);
189 extern char *skip_whitespace(const char *);
190
191 extern const char *bb_mode_string(int mode);
192 extern int is_directory(const char *name, int followLinks, struct stat *statBuf);
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,
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);
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 extern int ndelay_on(int fd);
208
209
210 extern DIR *xopendir(const char *path);
211 extern DIR *warn_opendir(const char *path);
212
213 char *xgetcwd(char *cwd);
214 char *xreadlink(const char *path);
215 extern void xstat(char *filename, struct stat *buf);
216 extern pid_t spawn(char **argv);
217 extern pid_t xspawn(char **argv);
218 extern int wait4pid(int pid);
219 extern void xsetgid(gid_t gid);
220 extern void xsetuid(uid_t uid);
221 extern void xdaemon(int nochdir, int noclose);
222 extern void xchdir(const char *path);
223 extern void xsetenv(const char *key, const char *value);
224 extern int xopen(const char *pathname, int flags);
225 extern int xopen3(const char *pathname, int flags, int mode);
226 extern off_t xlseek(int fd, off_t offset, int whence);
227 extern off_t fdlength(int fd);
228
229
230 extern int xsocket(int domain, int type, int protocol);
231 extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
232 extern void xlisten(int s, int backlog);
233 extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
234 extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
235 extern struct hostent *xgethostbyname(const char *name);
236 extern struct hostent *xgethostbyname2(const char *name, int af);
237 extern int xsocket_stream_ip4or6(sa_family_t *fp);
238 typedef union {
239         struct sockaddr sa;
240         struct sockaddr_in sin;
241 #if ENABLE_FEATURE_IPV6
242         struct sockaddr_in6 sin6;
243 #endif
244 } sockaddr_inet;
245 extern int dotted2sockaddr(const char *dotted, struct sockaddr* sp, int socklen);
246 extern int create_and_bind_socket_ip4or6(const char *hostaddr, int port);
247 extern int setsockopt_reuseaddr(int fd);
248 extern int setsockopt_broadcast(int fd);
249
250
251 extern char *xstrdup(const char *s);
252 extern char *xstrndup(const char *s, int n);
253 extern char *safe_strncpy(char *dst, const char *src, size_t size);
254 extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
255
256 /* dmalloc will redefine these to it's own implementation. It is safe
257  * to have the prototypes here unconditionally.  */
258 extern void *xmalloc(size_t size);
259 extern void *xrealloc(void *old, size_t size);
260 extern void *xzalloc(size_t size);
261
262 extern ssize_t safe_read(int fd, void *buf, size_t count);
263 extern ssize_t full_read(int fd, void *buf, size_t count);
264 extern void xread(int fd, void *buf, size_t count);
265 extern unsigned char xread_char(int fd);
266 extern char *reads(int fd, char *buf, size_t count);
267 extern ssize_t read_close(int fd, void *buf, size_t count);
268 extern ssize_t open_read_close(const char *filename, void *buf, size_t count);
269 extern void *xmalloc_open_read_close(const char *filename, size_t *sizep);
270
271 extern ssize_t safe_write(int fd, const void *buf, size_t count);
272 extern ssize_t full_write(int fd, const void *buf, size_t count);
273 extern void xwrite(int fd, void *buf, size_t count);
274
275 /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */
276 extern void xprint_and_close_file(FILE *file);
277 extern char *xmalloc_fgets(FILE *file);
278 /* Read up to (and including) TERMINATING_STRING: */
279 extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string);
280 /* Chops off '\n' from the end, unlike fgets: */
281 extern char *xmalloc_getline(FILE *file);
282 extern char *bb_get_chunk_from_file(FILE *file, int *end);
283 extern void die_if_ferror(FILE *file, const char *msg);
284 extern void die_if_ferror_stdout(void);
285 extern void xfflush_stdout(void);
286 extern void fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
287 extern int fclose_if_not_stdin(FILE *file);
288 extern FILE *xfopen(const char *filename, const char *mode);
289 /* Prints warning to stderr and returns NULL on failure: */
290 extern FILE *fopen_or_warn(const char *filename, const char *mode);
291 /* "Opens" stdin if filename is special, else just opens file: */
292 extern FILE *fopen_or_warn_stdin(const char *filename);
293
294
295 extern void smart_ulltoa5(unsigned long long ul, char buf[5]);
296 extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
297 extern char *utoa(unsigned n);
298 extern void itoa_to_buf(int n, char *buf, unsigned buflen);
299 extern char *itoa(int n);
300
301 // FIXME: the prototype doesn't match libc strtoXX -> confusion
302 // FIXME: alot of unchecked strtoXXX are still in tree
303 // FIXME: atoi_or_else(str, N)?
304 extern int safe_strtoi(const char *arg, int* value);
305 extern int safe_strtou(const char *arg, unsigned* value);
306 extern int safe_strtod(const char *arg, double* value);
307 extern int safe_strtol(const char *arg, long* value);
308 extern int safe_strtoll(const char *arg, long long* value);
309 extern int safe_strtoul(const char *arg, unsigned long* value);
310 extern int safe_strtoull(const char *arg, unsigned long long* value);
311 extern int safe_strtou32(const char *arg, uint32_t* value);
312
313 struct suffix_mult {
314         const char *suffix;
315         unsigned mult;
316 };
317 unsigned long long xstrtoull(const char *numstr, int base);
318 unsigned long long xatoull(const char *numstr);
319 unsigned long xstrtoul_range_sfx(const char *numstr, int base,
320                 unsigned long lower,
321                 unsigned long upper,
322                 const struct suffix_mult *suffixes);
323 unsigned long xstrtoul_range(const char *numstr, int base,
324                 unsigned long lower,
325                 unsigned long upper);
326 unsigned long xstrtoul_sfx(const char *numstr, int base,
327                 const struct suffix_mult *suffixes);
328 unsigned long xstrtoul(const char *numstr, int base);
329 unsigned long xatoul_range_sfx(const char *numstr,
330                 unsigned long lower,
331                 unsigned long upper,
332                 const struct suffix_mult *suffixes);
333 unsigned long xatoul_sfx(const char *numstr,
334                 const struct suffix_mult *suffixes);
335 unsigned long xatoul_range(const char *numstr,
336                 unsigned long lower,
337                 unsigned long upper);
338 unsigned long xatoul(const char *numstr);
339 long xstrtol_range_sfx(const char *numstr, int base,
340                 long lower,
341                 long upper,
342                 const struct suffix_mult *suffixes);
343 long xstrtol_range(const char *numstr, int base, long lower, long upper);
344 long xatol_range_sfx(const char *numstr,
345                 long lower,
346                 long upper,
347                 const struct suffix_mult *suffixes);
348 long xatol_range(const char *numstr, long lower, long upper);
349 long xatol_sfx(const char *numstr, const struct suffix_mult *suffixes);
350 long xatol(const char *numstr);
351 /* Specialized: */
352 unsigned xatou_range(const char *numstr, unsigned lower, unsigned upper);
353 unsigned xatou_sfx(const char *numstr, const struct suffix_mult *suffixes);
354 unsigned xatou(const char *numstr);
355 int xatoi_range(const char *numstr, int lower, int upper);
356 int xatoi(const char *numstr);
357 /* Using xatoi() instead of naive atoi() is not always convenient -
358  * in many places people want *non-negative* values, but store them
359  * in signed int. Therefore we need this one:
360  * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */
361 int xatoi_u(const char *numstr);
362 uint32_t xatou32(const char *numstr);
363 /* Useful for reading port numbers */
364 uint16_t xatou16(const char *numstr);
365
366
367 /* These parse entries in /etc/passwd and /etc/group.  This is desirable
368  * for BusyBox since we want to avoid using the glibc NSS stuff, which
369  * increases target size and is often not needed on embedded systems.  */
370 extern long bb_xgetpwnam(const char *name);
371 extern long bb_xgetgrnam(const char *name);
372 extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);
373 extern char *bb_getpwuid(char *name, long uid, int bufsize);
374 extern char *bb_getgrgid(char *group, long gid, int bufsize);
375 /* from chpst */
376 struct bb_uidgid_t {
377         uid_t uid;
378         gid_t gid;
379 };
380 extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/);
381
382
383 enum { BB_GETOPT_ERROR = 0x80000000 };
384 extern const char *opt_complementary;
385 extern const struct option *applet_long_options;
386 extern uint32_t option_mask32;
387 extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
388
389
390 typedef struct llist_s {
391         char *data;
392         struct llist_s *link;
393 } llist_t;
394 extern void llist_add_to(llist_t **old_head, void *data);
395 extern void llist_add_to_end(llist_t **list_head, void *data);
396 extern void *llist_pop(llist_t **elm);
397 extern void llist_free(llist_t *elm, void (*freeit)(void *data));
398 extern llist_t* rev_llist(llist_t *list);
399
400 enum {
401         LOGMODE_NONE = 0,
402         LOGMODE_STDIO = 1<<0,
403         LOGMODE_SYSLOG = 1<<1,
404         LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
405 };
406 extern const char *msg_eol;
407 extern int logmode;
408 extern int die_sleep;
409 extern int xfunc_error_retval;
410 extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
411 extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
412 extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
413 extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
414 extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
415 extern void bb_vherror_msg(const char *s, va_list p);
416 extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
417 extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
418 extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN;
419 extern void bb_perror_nomsg(void);
420 extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
421 /* These two are used internally -- you shouldn't need to use them */
422 extern void bb_verror_msg(const char *s, va_list p, const char *strerr);
423 extern void bb_vperror_msg(const char *s, va_list p);
424 extern void bb_vinfo_msg(const char *s, va_list p);
425
426
427 extern int bb_echo(int argc, char** argv);
428 extern int bb_test(int argc, char** argv);
429
430 #ifndef BUILD_INDIVIDUAL
431 extern struct BB_applet *find_applet_by_name(const char *name);
432 extern void run_applet_by_name(const char *name, int argc, char **argv);
433 #endif
434
435 extern struct mntent *find_mount_point(const char *name, const char *table);
436 extern void erase_mtab(const char * name);
437 extern unsigned int tty_baud_to_value(speed_t speed);
438 extern speed_t tty_value_to_baud(unsigned int value);
439 extern void bb_warn_ignoring_args(int n);
440
441 extern int get_linux_version_code(void);
442
443 extern char *query_loop(const char *device);
444 extern int del_loop(const char *device);
445 extern int set_loop(char **device, const char *file, unsigned long long offset);
446
447
448 const char *make_human_readable_str(unsigned long long size,
449                 unsigned long block_size, unsigned long display_unit);
450
451 char *bb_askpass(int timeout, const char * prompt);
452 int bb_ask_confirmation(void);
453 int klogctl(int type, char * b, int len);
454
455 extern int bb_parse_mode(const char* s, mode_t* theMode);
456
457 char *concat_path_file(const char *path, const char *filename);
458 char *concat_subpath_file(const char *path, const char *filename);
459 char *last_char_is(const char *s, int c);
460
461 int execable_file(const char *name);
462 char *find_execable(const char *filename);
463 int exists_execable(const char *filename);
464
465 USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
466 int inflate(int in, int out);
467
468 int create_icmp_socket(void);
469 int create_icmp6_socket(void);
470
471 unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port);
472 void bb_lookup_host(struct sockaddr_in *s_in, const char *host);
473
474 int bb_make_directory(char *path, long mode, int flags);
475
476 int get_signum(const char *name);
477 const char *get_signame(int number);
478
479 char *bb_simplify_path(const char *path);
480
481 #define FAIL_DELAY 3
482 extern void bb_do_delay(int seconds);
483 extern void change_identity(const struct passwd *pw);
484 extern const char *change_identity_e2str(const struct passwd *pw);
485 extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args);
486 #ifdef CONFIG_SELINUX
487 extern void renew_current_security_context(void);
488 extern void set_current_security_context(security_context_t sid);
489 #endif
490 extern int run_parts(char **args, const unsigned char test_mode, char **env);
491 extern int restricted_shell(const char *shell);
492 extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw);
493 extern int correct_password(const struct passwd *pw);
494 extern char *pw_encrypt(const char *clear, const char *salt);
495 extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
496 extern int index_in_str_array(const char * const string_array[], const char *key);
497 extern int index_in_substr_array(const char * const string_array[], const char *key);
498 extern void print_login_issue(const char *issue_file, const char *tty);
499 extern void print_login_prompt(void);
500 #ifdef BB_NOMMU
501 extern void vfork_daemon(int nochdir, int noclose);
502 extern void vfork_daemon_rexec(int nochdir, int noclose,
503                 int argc, char **argv, char *foreground_opt);
504 #endif
505 extern int get_terminal_width_height(int fd, int *width, int *height);
506 extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *));
507
508 int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
509 void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
510 void reset_ino_dev_hashtable(void);
511
512
513 #ifndef COMM_LEN
514 #ifdef TASK_COMM_LEN
515 enum { COMM_LEN = TASK_COMM_LEN };
516 #else
517 /* synchronize with sizeof(task_struct.comm) in /usr/include/linux/sched.h */
518 enum { COMM_LEN = 16 };
519 #endif
520 #endif
521 typedef struct {
522         DIR *dir;
523 /* Fields are set to 0/NULL if failed to determine (or not requested) */
524         char *cmd;
525         unsigned long rss;
526         unsigned long stime, utime;
527         unsigned pid;
528         unsigned ppid;
529         unsigned pgid;
530         unsigned sid;
531         unsigned uid;
532         unsigned gid;
533         /* basename of executable file in call to exec(2), size from */
534         /* sizeof(task_struct.comm) in /usr/include/linux/sched.h */
535         char state[4];
536         char comm[COMM_LEN];
537 //      user/group? - use passwd/group parsing functions
538 } procps_status_t;
539 enum {
540         PSSCAN_PID      = 1 << 0,
541         PSSCAN_PPID     = 1 << 1,
542         PSSCAN_PGID     = 1 << 2,
543         PSSCAN_SID      = 1 << 3,
544         PSSCAN_UIDGID   = 1 << 4,
545         PSSCAN_COMM     = 1 << 5,
546         PSSCAN_CMD      = 1 << 6,
547         PSSCAN_STATE    = 1 << 7,
548         PSSCAN_RSS      = 1 << 8,
549         PSSCAN_STIME    = 1 << 9,
550         PSSCAN_UTIME    = 1 << 10,
551         /* These are all retrieved from proc/NN/stat in one go: */
552         PSSCAN_STAT     = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID
553                         | PSSCAN_COMM | PSSCAN_STATE
554                         | PSSCAN_RSS | PSSCAN_STIME | PSSCAN_UTIME,
555 };
556 procps_status_t* alloc_procps_scan(int flags);
557 void free_procps_scan(procps_status_t* sp);
558 procps_status_t* procps_scan(procps_status_t* sp, int flags);
559 pid_t *find_pid_by_name(const char* procName);
560 pid_t *pidlist_reverse(pid_t *pidList);
561 void clear_username_cache(void);
562 const char* get_cached_username(uid_t uid);
563
564
565 extern const char bb_uuenc_tbl_base64[];
566 extern const char bb_uuenc_tbl_std[];
567 void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl);
568
569 typedef struct sha1_ctx_t {
570         uint32_t count[2];
571         uint32_t hash[5];
572         uint32_t wbuf[16];
573 } sha1_ctx_t;
574 void sha1_begin(sha1_ctx_t *ctx);
575 void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx);
576 void *sha1_end(void *resbuf, sha1_ctx_t *ctx);
577
578 typedef struct md5_ctx_t {
579         uint32_t A;
580         uint32_t B;
581         uint32_t C;
582         uint32_t D;
583         uint64_t total;
584         uint32_t buflen;
585         char buffer[128];
586 } md5_ctx_t;
587 void md5_begin(md5_ctx_t *ctx);
588 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
589 void *md5_end(void *resbuf, md5_ctx_t *ctx);
590
591 uint32_t *crc32_filltable(int endian);
592
593
594 enum {  /* DO NOT CHANGE THESE VALUES!  cp.c depends on them. */
595         FILEUTILS_PRESERVE_STATUS = 1,
596         FILEUTILS_DEREFERENCE = 2,
597         FILEUTILS_RECUR = 4,
598         FILEUTILS_FORCE = 8,
599         FILEUTILS_INTERACTIVE = 0x10,
600         FILEUTILS_MAKE_HARDLINK = 0x20,
601         FILEUTILS_MAKE_SOFTLINK = 0x40,
602 };
603 #define FILEUTILS_CP_OPTSTR "pdRfils"
604
605 extern const char *applet_name;
606 extern const char BB_BANNER[];
607
608 extern const char bb_msg_full_version[];
609 extern const char bb_msg_memory_exhausted[];
610 extern const char bb_msg_invalid_date[];
611 extern const char bb_msg_read_error[];
612 extern const char bb_msg_write_error[];
613 extern const char bb_msg_name_longer_than_foo[];
614 extern const char bb_msg_unknown[];
615 extern const char bb_msg_can_not_create_raw_socket[];
616 extern const char bb_msg_perm_denied_are_you_root[];
617 extern const char bb_msg_requires_arg[];
618 extern const char bb_msg_invalid_arg[];
619 extern const char bb_msg_standard_input[];
620 extern const char bb_msg_standard_output[];
621
622 extern const char bb_str_default[];
623
624 extern const char bb_path_mtab_file[];
625 extern const char bb_path_nologin_file[];
626 extern const char bb_path_passwd_file[];
627 extern const char bb_path_shadow_file[];
628 extern const char bb_path_gshadow_file[];
629 extern const char bb_path_group_file[];
630 extern const char bb_path_securetty_file[];
631 extern const char bb_path_motd_file[];
632 extern const char bb_path_wtmp_file[];
633 extern const char bb_dev_null[];
634
635 #ifndef BUFSIZ
636 #define BUFSIZ 4096
637 #endif
638 extern char bb_common_bufsiz1[BUFSIZ+1];
639
640 /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it,
641  * use bb_default_login_shell and following defines.
642  * If you change LIBBB_DEFAULT_LOGIN_SHELL,
643  * don't forget to change increment constant. */
644 #define LIBBB_DEFAULT_LOGIN_SHELL      "-/bin/sh"
645 extern const char bb_default_login_shell[];
646 /* "/bin/sh" */
647 #define DEFAULT_SHELL     (bb_default_login_shell+1)
648 /* "sh" */
649 #define DEFAULT_SHELL_SHORT_NAME     (bb_default_login_shell+6)
650
651
652 #ifdef CONFIG_FEATURE_DEVFS
653 # define CURRENT_VC "/dev/vc/0"
654 # define VC_1 "/dev/vc/1"
655 # define VC_2 "/dev/vc/2"
656 # define VC_3 "/dev/vc/3"
657 # define VC_4 "/dev/vc/4"
658 # define VC_5 "/dev/vc/5"
659 #if defined(__sh__) || defined(__H8300H__) || defined(__H8300S__)
660 /* Yes, this sucks, but both SH (including sh64) and H8 have a SCI(F) for their
661    respective serial ports .. as such, we can't use the common device paths for
662    these. -- PFM */
663 #  define SC_0 "/dev/ttsc/0"
664 #  define SC_1 "/dev/ttsc/1"
665 #  define SC_FORMAT "/dev/ttsc/%d"
666 #else
667 #  define SC_0 "/dev/tts/0"
668 #  define SC_1 "/dev/tts/1"
669 #  define SC_FORMAT "/dev/tts/%d"
670 #endif
671 # define VC_FORMAT "/dev/vc/%d"
672 # define LOOP_FORMAT "/dev/loop/%d"
673 # define LOOP_NAME "/dev/loop/"
674 # define FB_0 "/dev/fb/0"
675 #else
676 # define CURRENT_VC "/dev/tty0"
677 # define VC_1 "/dev/tty1"
678 # define VC_2 "/dev/tty2"
679 # define VC_3 "/dev/tty3"
680 # define VC_4 "/dev/tty4"
681 # define VC_5 "/dev/tty5"
682 #if defined(__sh__) || defined(__H8300H__) || defined(__H8300S__)
683 #  define SC_0 "/dev/ttySC0"
684 #  define SC_1 "/dev/ttySC1"
685 #  define SC_FORMAT "/dev/ttySC%d"
686 #else
687 #  define SC_0 "/dev/ttyS0"
688 #  define SC_1 "/dev/ttyS1"
689 #  define SC_FORMAT "/dev/ttyS%d"
690 #endif
691 # define VC_FORMAT "/dev/tty%d"
692 # define LOOP_FORMAT "/dev/loop%d"
693 # define LOOP_NAME "/dev/loop"
694 # define FB_0 "/dev/fb0"
695 #endif
696
697 /* The following devices are the same on devfs and non-devfs systems.  */
698 #define CURRENT_TTY "/dev/tty"
699 #define CONSOLE_DEV "/dev/console"
700
701
702 #ifndef RB_POWER_OFF
703 /* Stop system and switch power off if possible.  */
704 #define RB_POWER_OFF   0x4321fedc
705 #endif
706
707 // Make sure we call functions instead of macros.
708 #undef isalnum
709 #undef isalpha
710 #undef isascii
711 #undef isblank
712 #undef iscntrl
713 #undef isdigit
714 #undef isgraph
715 #undef islower
716 #undef isprint
717 #undef ispunct
718 #undef isspace
719 #undef isupper
720 #undef isxdigit
721
722 #ifdef DMALLOC
723 #include <dmalloc.h>
724 #endif
725
726 #endif /* __LIBBUSYBOX_H__ */