blob: f2c2d8a7d0136727ef9b93703c79b6ee4a59a1af [file] [log] [blame]
Eric Andersen2b69c401999-10-05 22:58:32 +00001/*
2 * Busybox main header file
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
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 */
Eric Andersencc8ed391999-10-05 16:24:54 +000024#ifndef _INTERNAL_H_
25#define _INTERNAL_H_
26
27#include "busybox.def.h"
28
29#include <stdlib.h>
30#include <string.h>
31#include <unistd.h>
32#include <sys/stat.h>
33
34
35/* Some useful definitions */
Eric Andersencc8ed391999-10-05 16:24:54 +000036#define STDIN 0
37#define STDOUT 1
Eric Andersenf811e071999-10-09 00:25:00 +000038#define FALSE ((int) 1)
39#define TRUE ((int) 0)
Eric Andersencc8ed391999-10-05 16:24:54 +000040
41#define PATH_LEN 1024
42#define BUF_SIZE 8192
43#define EXPAND_ALLOC 1024
44
45#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
46#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
47#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
48#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
49
50
51
Eric Andersencc8ed391999-10-05 16:24:54 +000052struct Applet {
53 const char* name;
54 int (*main)(int argc, char** argv);
55};
56
Eric Andersencc8ed391999-10-05 16:24:54 +000057extern int busybox_main(int argc, char** argv);
58extern int block_device_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +000059extern int cat_main(int argc, char** argv);
Eric Andersen4bea32a1999-10-06 00:30:51 +000060extern int more_main(int argc, char** argv);
Eric Andersenf811e071999-10-09 00:25:00 +000061extern int cp_main(int argc, char** argv);
Eric Andersen1b61f411999-10-13 18:56:42 +000062extern int chmod_chown_chgrp_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000063extern int chroot_main(int argc, char** argv);
64extern int clear_main(int argc, char** argv);
65extern int date_main(int argc, char** argv);
66extern int dd_main(int argc, char** argv);
67extern int df_main(int argc, char** argv);
68extern int dmesg_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +000069extern int dutmp_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000070extern int false_main(int argc, char** argv);
71extern int fdisk_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000072extern int fdflush_main(int argc, char **argv);
Eric Andersene494fdd1999-10-19 20:23:03 +000073extern int fsck_minix_main(int argc, char **argv);
74extern int mkfs_minix_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000075extern int find_main(int argc, char** argv);
76extern int grep_main(int argc, char** argv);
77extern int halt_main(int argc, char** argv);
78extern int init_main(int argc, char** argv);
79extern int kill_main(int argc, char** argv);
80extern int length_main(int argc, char** argv);
81extern int ln_main(int argc, char** argv);
Eric Andersen3e0fbae1999-10-19 06:02:44 +000082extern int loadfont_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000083extern int loadkmap_main(int argc, char** argv);
84extern int losetup_main(int argc, char** argv);
85extern int ls_main(int argc, char** argv);
86extern int makedevs_main(int argc, char** argv);
87extern int math_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000088extern int mkdir_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000089extern int mknod_main(int argc, char** argv);
90extern int mkswap_main(int argc, char** argv);
91extern int mnc_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000092extern int mount_main(int argc, char** argv);
93extern int mt_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +000094extern int mv_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000095extern int printf_main(int argc, char** argv);
Eric Andersenef8b6c71999-10-20 08:05:35 +000096extern int ps_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000097extern int pwd_main(int argc, char** argv);
98extern int reboot_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000099extern int rmdir_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000100extern int rm_main(int argc, char** argv);
101extern int scan_partitions_main(int argc, char** argv);
102extern int sh_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000103extern int sfdisk_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000104extern int sleep_main(int argc, char** argv);
Eric Andersen87590061999-10-18 21:22:59 +0000105extern int swap_on_off_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000106extern int sync_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000107extern int tar_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +0000108extern int touch_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000109extern int tput_main(int argc, char** argv);
110extern int true_main(int argc, char** argv);
111extern int tryopen_main(int argc, char** argv);
112extern int umount_main(int argc, char** argv);
113extern int update_main(int argc, char** argv);
114extern int zcat_main(int argc, char** argv);
115extern int gzip_main(int argc, char** argv);
116
Eric Andersen2b69c401999-10-05 22:58:32 +0000117
118const char *modeString(int mode);
119const char *timeString(time_t timeVal);
Eric Andersenf811e071999-10-09 00:25:00 +0000120int isDirectory(const char *name);
121int isDevice(const char *name);
122int copyFile(const char *srcName, const char *destName, int setModes,
123 int followLinks);
124char *buildName(const char *dirName, const char *fileName);
125int makeString(int argc, const char **argv, char *buf, int bufLen);
Eric Andersen2b69c401999-10-05 22:58:32 +0000126char *getChunk(int size);
127char *chunkstrdup(const char *str);
128void freeChunks(void);
129int fullWrite(int fd, const char *buf, int len);
130int fullRead(int fd, char *buf, int len);
Eric Andersenbed30e91999-10-18 19:02:32 +0000131int recursiveAction(const char *fileName, int recurse, int followLinks, int delayDirAction,
Eric Andersen9b587181999-10-17 05:43:39 +0000132 int (*fileAction) (const char *fileName, struct stat* statbuf),
133 int (*dirAction) (const char *fileName, struct stat* statbuf));
Eric Andersenf811e071999-10-09 00:25:00 +0000134int match(const char* text, const char * pattern);
Eric Andersen17d49ef1999-10-06 20:25:32 +0000135const char* timeString(time_t timeVal);
Eric Andersencc8ed391999-10-05 16:24:54 +0000136
Eric Andersenf6be9441999-10-13 21:12:06 +0000137extern void createPath (const char *name, int mode);
138extern int parse_mode( const char* s, mode_t* theMode);
Eric Andersenb0e9a701999-10-18 22:28:26 +0000139extern volatile void usage(const char *usage);
140
Eric Andersend23f9ba1999-10-20 19:18:15 +0000141extern uid_t my_getpwnam(char *name);
142extern gid_t my_getgrnam(char *name);
143extern void my_getpwuid(char* name, uid_t uid);
144extern void my_getgrgid(char* group, gid_t gid);
145extern int get_kernel_revision();
146
Eric Andersencc8ed391999-10-05 16:24:54 +0000147
Eric Andersene674eb71999-10-19 20:52:57 +0000148
149#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
150
151static inline int bit(char * addr,unsigned int nr)
152{
153 return (addr[nr >> 3] & (1<<(nr & 7))) != 0;
154}
155
156static inline int setbit(char * addr,unsigned int nr)
157{
158 int __res = bit(addr, nr);
159 addr[nr >> 3] |= (1<<(nr & 7));
160 return __res != 0; \
161}
162
163static inline int clrbit(char * addr,unsigned int nr)
164{
165 int __res = bit(addr, nr);
166 addr[nr >> 3] &= ~(1<<(nr & 7));
167 return __res != 0;
168}
169
170#endif
171
172
Eric Andersencc8ed391999-10-05 16:24:54 +0000173#endif
174