blob: f79dac8c880f9f705f08d309e74a64b79d82e7f8 [file] [log] [blame]
Eric Andersenf6b71392000-09-26 01:09:18 +00001/* 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
Eric Andersened3ef502001-01-27 08:24:39 +000029#include <stdio.h>
Eric Andersenf6b71392000-09-26 01:09:18 +000030#include <stdarg.h>
Eric Andersenf6b71392000-09-26 01:09:18 +000031#include <sys/stat.h>
Eric Andersen01bda5d2001-01-02 01:16:38 +000032#include <sys/types.h>
Eric Andersenf6b71392000-09-26 01:09:18 +000033
Matt Kraai6ba1a802001-04-12 20:11:55 +000034#define BB_BANNER "BusyBox v" BB_VER " (" BB_BT ")"
35
Eric Andersen01bda5d2001-01-02 01:16:38 +000036#ifdef DMALLOC
37#include "dmalloc.h"
38#endif
Eric Andersenf6b71392000-09-26 01:09:18 +000039
Eric Andersen2b1c3672001-03-14 01:36:52 +000040#include <features.h>
Eric Andersenc3196012001-03-14 01:15:06 +000041
42
Eric Andersenf6b71392000-09-26 01:09:18 +000043enum Location {
44 _BB_DIR_ROOT = 0,
45 _BB_DIR_BIN,
46 _BB_DIR_SBIN,
47 _BB_DIR_USR_BIN,
48 _BB_DIR_USR_SBIN
49};
50
51struct BB_applet {
52 const char* name;
53 int (*main)(int argc, char** argv);
54 enum Location location;
Eric Andersenf6b71392000-09-26 01:09:18 +000055};
56/* From busybox.c */
57extern const struct BB_applet applets[];
58
Eric Andersen8c725e62000-11-30 00:27:06 +000059/* Automagically pull in all the applet function prototypes and
Eric Andersen87559822000-12-01 19:02:24 +000060 * applet usage strings. These are all of the form:
Eric Andersen8c725e62000-11-30 00:27:06 +000061 * extern int foo_main(int argc, char **argv);
62 * extern const char foo_usage[];
63 * These are all autogenerated from the set of currently defined applets.
64 */
65#define PROTOTYPES
66#include "applets.h"
67#undef PROTOTYPES
Eric Andersenf6b71392000-09-26 01:09:18 +000068
Eric Andersenaad1a882001-03-16 22:47:14 +000069#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
70#define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
71#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
Matt Kraaic1cda4a2001-07-19 15:00:14 +000072#define RELEASE_BB_BUFFER(buffer) ((void)0)
Eric Andersenaad1a882001-03-16 22:47:14 +000073#else
Mark Whitley3e310ac2001-04-20 17:40:33 +000074#ifdef BB_FEATURE_BUFFERS_GO_IN_BSS
75#define RESERVE_BB_BUFFER(buffer,len) static char buffer[len]
76#define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len]
Matt Kraaic1cda4a2001-07-19 15:00:14 +000077#define RELEASE_BB_BUFFER(buffer) ((void)0)
Mark Whitley3e310ac2001-04-20 17:40:33 +000078#else
Eric Andersenaad1a882001-03-16 22:47:14 +000079#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
80#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
Matt Kraaic1cda4a2001-07-19 15:00:14 +000081#define RELEASE_BB_BUFFER(buffer) free (buffer)
Eric Andersenf6b71392000-09-26 01:09:18 +000082#endif
Mark Whitley3e310ac2001-04-20 17:40:33 +000083#endif
Eric Andersenf6b71392000-09-26 01:09:18 +000084
85
Eric Andersenf6b71392000-09-26 01:09:18 +000086/* Bit map related macros -- libc5 doens't provide these... sigh. */
87#ifndef setbit
88#define NBBY CHAR_BIT
89#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
90#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
91#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
92#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
93#endif
94
Eric Andersenaad1a882001-03-16 22:47:14 +000095#ifndef RB_POWER_OFF
96/* Stop system and switch power off if possible. */
97#define RB_POWER_OFF 0x4321fedc
Eric Andersend35c2152001-01-25 23:49:09 +000098#endif
99
Eric Andersenaad1a882001-03-16 22:47:14 +0000100
101/* Pull in the utility routines from libbb */
102#include "libbb/libbb.h"
103
104
Mark Whitleye0bf91d2001-03-13 00:40:19 +0000105
Eric Andersenf6b71392000-09-26 01:09:18 +0000106#endif /* _BB_INTERNAL_H_ */