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