2e54ac55e7818c4270062657ce2ab3473c34e3e5
[oweals/busybox.git] / include / busybox.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Busybox main internal header file
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
21  * Permission has been granted to redistribute this code under the GPL.
22  *
23  */
24 #ifndef _BB_INTERNAL_H_
25 #define _BB_INTERNAL_H_    1
26
27 #include "config.h"
28
29 #include <stdio.h>
30 #include <stdarg.h>
31 #include <sys/stat.h>
32 #include <sys/types.h>
33
34 #define BB_BANNER "BusyBox v" BB_VER " (" BB_BT ")"
35
36 #ifdef DMALLOC
37 #include <dmalloc.h>
38 #endif
39
40 #include <features.h>
41
42 #include "libbb.h"
43
44 enum Location {
45         _BB_DIR_ROOT = 0,
46         _BB_DIR_BIN,
47         _BB_DIR_SBIN,
48         _BB_DIR_USR_BIN,
49         _BB_DIR_USR_SBIN
50 };
51
52 enum SUIDRoot {
53         _BB_SUID_NEVER = 0,
54         _BB_SUID_MAYBE,
55         _BB_SUID_ALWAYS
56 };
57
58 struct BB_applet {
59         const   char*   name;
60         int     (*main)(int argc, char** argv);
61         enum    Location        location  : 4;
62         enum    SUIDRoot        need_suid : 4;
63 };
64 /* From busybox.c */
65 extern const struct BB_applet applets[];
66
67 /* Automagically pull in all the applet function prototypes and
68  * applet usage strings.  These are all of the form:
69  *              extern int foo_main(int argc, char **argv);
70  *              extern const char foo_usage[];
71  * These are all autogenerated from the set of currently defined applets. 
72  */
73 #define PROTOTYPES
74 #include "applets.h"
75 #undef PROTOTYPES
76
77 #ifdef CONFIG_FEATURE_BUFFERS_GO_ON_STACK
78 #define RESERVE_CONFIG_BUFFER(buffer,len)           char buffer[len]
79 #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char buffer[len]
80 #define RELEASE_CONFIG_BUFFER(buffer)      ((void)0)
81 #else
82 #ifdef CONFIG_FEATURE_BUFFERS_GO_IN_BSS
83 #define RESERVE_CONFIG_BUFFER(buffer,len)  static          char buffer[len]
84 #define RESERVE_CONFIG_UBUFFER(buffer,len) static unsigned char buffer[len]
85 #define RELEASE_CONFIG_BUFFER(buffer)      ((void)0)
86 #else
87 #define RESERVE_CONFIG_BUFFER(buffer,len)           char *buffer=xmalloc(len)
88 #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
89 #define RELEASE_CONFIG_BUFFER(buffer)      free (buffer)
90 #endif
91 #endif
92
93
94 /* Bit map related macros -- libc5 doens't provide these... sigh.  */
95 #ifndef setbit
96 #define NBBY            CHAR_BIT
97 #define setbit(a,i)     ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
98 #define clrbit(a,i)     ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
99 #define isset(a,i)      ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
100 #define isclr(a,i)      (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
101 #endif
102
103 #ifndef RB_POWER_OFF
104 /* Stop system and switch power off if possible.  */
105 #define RB_POWER_OFF   0x4321fedc
106 #endif
107
108
109 /* Pull in the utility routines from libbb */
110 // #include "libbb.h"
111
112 /* Try to pull in PATH_MAX */
113 #include <limits.h>
114 /* for PATH_MAX on systems that don't have it in limits.h */
115 #include <sys/param.h> 
116 #ifndef PATH_MAX 
117 #define  PATH_MAX         256
118 #endif
119
120 #endif /* _BB_INTERNAL_H_ */