blob: 3ff3d8a37ac0f005a3ba32cfb3dc3c6ae52ff584 [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 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +000020 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
Eric Andersenf6b71392000-09-26 01:09:18 +000021 * 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
Eric Andersenbdfd0d72001-10-24 05:00:29 +000027#include "config.h"
Eric Andersenf6b71392000-09-26 01:09:18 +000028
Eric Andersened3ef502001-01-27 08:24:39 +000029#include <stdio.h>
Manuel Novoa III 68474f32004-02-05 14:45:58 +000030#include <stdlib.h>
Eric Andersenf6b71392000-09-26 01:09:18 +000031#include <stdarg.h>
Eric Andersenf6b71392000-09-26 01:09:18 +000032#include <sys/stat.h>
Eric Andersen01bda5d2001-01-02 01:16:38 +000033#include <sys/types.h>
Eric Andersenf6b71392000-09-26 01:09:18 +000034
Mike Frysingerca1b6fc2005-03-04 01:09:43 +000035#if __GNU_LIBRARY__ < 5 && \
36 !defined(__dietlibc__) && \
37 !defined(_NEWLIB_VERSION)
38#error "Sorry, this libc version is not supported :("
Eric Andersen85e5e722003-07-22 08:56:55 +000039#endif
40
Glenn L McGrath7c87b672004-01-13 10:57:32 +000041#ifndef BB_EXTRA_VERSION
Matt Kraai6ba1a802001-04-12 20:11:55 +000042#define BB_BANNER "BusyBox v" BB_VER " (" BB_BT ")"
Glenn L McGrath7c87b672004-01-13 10:57:32 +000043#else
44#define BB_BANNER "BusyBox v" BB_VER " (" BB_EXTRA_VERSION ")"
45#endif
Matt Kraai6ba1a802001-04-12 20:11:55 +000046
Eric Andersen01bda5d2001-01-02 01:16:38 +000047#ifdef DMALLOC
Eric Andersenbdfd0d72001-10-24 05:00:29 +000048#include <dmalloc.h>
Eric Andersen01bda5d2001-01-02 01:16:38 +000049#endif
Eric Andersenf6b71392000-09-26 01:09:18 +000050
Eric Andersen2b1c3672001-03-14 01:36:52 +000051#include <features.h>
Eric Andersenc3196012001-03-14 01:15:06 +000052
Glenn L McGrath60a22ad2002-08-22 15:54:22 +000053/* Pull in the utility routines from libbb */
Robert Grieblc9aca452002-06-04 20:06:25 +000054#include "libbb.h"
Eric Andersenc3196012001-03-14 01:15:06 +000055
Eric Andersenf6b71392000-09-26 01:09:18 +000056enum Location {
57 _BB_DIR_ROOT = 0,
58 _BB_DIR_BIN,
59 _BB_DIR_SBIN,
60 _BB_DIR_USR_BIN,
61 _BB_DIR_USR_SBIN
62};
63
Robert Grieblc9aca452002-06-04 20:06:25 +000064enum SUIDRoot {
65 _BB_SUID_NEVER = 0,
66 _BB_SUID_MAYBE,
67 _BB_SUID_ALWAYS
68};
69
Eric Andersenf6b71392000-09-26 01:09:18 +000070struct BB_applet {
Glenn L McGrath60a22ad2002-08-22 15:54:22 +000071 const char *name;
72 int (*main) (int argc, char **argv);
73 enum Location location:4;
74 enum SUIDRoot need_suid:4;
Eric Andersenf6b71392000-09-26 01:09:18 +000075};
Glenn L McGrath60a22ad2002-08-22 15:54:22 +000076
Eric Andersenf6b71392000-09-26 01:09:18 +000077/* From busybox.c */
78extern const struct BB_applet applets[];
79
Eric Andersen8c725e62000-11-30 00:27:06 +000080/* Automagically pull in all the applet function prototypes and
Eric Andersen87559822000-12-01 19:02:24 +000081 * applet usage strings. These are all of the form:
Eric Andersen8c725e62000-11-30 00:27:06 +000082 * extern int foo_main(int argc, char **argv);
83 * extern const char foo_usage[];
Eric Andersenc7bda1c2004-03-15 08:29:22 +000084 * These are all autogenerated from the set of currently defined applets.
Eric Andersen8c725e62000-11-30 00:27:06 +000085 */
86#define PROTOTYPES
87#include "applets.h"
88#undef PROTOTYPES
Eric Andersenf6b71392000-09-26 01:09:18 +000089
Eric Andersenbdfd0d72001-10-24 05:00:29 +000090#ifdef CONFIG_FEATURE_BUFFERS_GO_ON_STACK
91#define RESERVE_CONFIG_BUFFER(buffer,len) char buffer[len]
92#define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char buffer[len]
93#define RELEASE_CONFIG_BUFFER(buffer) ((void)0)
Eric Andersenaad1a882001-03-16 22:47:14 +000094#else
Eric Andersenbdfd0d72001-10-24 05:00:29 +000095#ifdef CONFIG_FEATURE_BUFFERS_GO_IN_BSS
96#define RESERVE_CONFIG_BUFFER(buffer,len) static char buffer[len]
97#define RESERVE_CONFIG_UBUFFER(buffer,len) static unsigned char buffer[len]
98#define RELEASE_CONFIG_BUFFER(buffer) ((void)0)
Mark Whitley3e310ac2001-04-20 17:40:33 +000099#else
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000100#define RESERVE_CONFIG_BUFFER(buffer,len) char *buffer=xmalloc(len)
101#define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
102#define RELEASE_CONFIG_BUFFER(buffer) free (buffer)
Eric Andersenf6b71392000-09-26 01:09:18 +0000103#endif
Mark Whitley3e310ac2001-04-20 17:40:33 +0000104#endif
Eric Andersenf6b71392000-09-26 01:09:18 +0000105
106
Eric Andersenaad1a882001-03-16 22:47:14 +0000107#ifndef RB_POWER_OFF
108/* Stop system and switch power off if possible. */
109#define RB_POWER_OFF 0x4321fedc
Eric Andersend35c2152001-01-25 23:49:09 +0000110#endif
111
Eric Andersen38ddbed2002-03-16 02:12:30 +0000112/* Try to pull in PATH_MAX */
113#include <limits.h>
Glenn L McGrath60a22ad2002-08-22 15:54:22 +0000114
Eric Andersen38ddbed2002-03-16 02:12:30 +0000115/* for PATH_MAX on systems that don't have it in limits.h */
Glenn L McGrath60a22ad2002-08-22 15:54:22 +0000116#include <sys/param.h>
117#ifndef PATH_MAX
Eric Andersen20d739a2002-01-26 23:58:22 +0000118#define PATH_MAX 256
119#endif
Mark Whitleye0bf91d2001-03-13 00:40:19 +0000120
Glenn L McGrath60a22ad2002-08-22 15:54:22 +0000121#endif /* _BB_INTERNAL_H_ */