blob: ae0148b2e8b2d0a9c9d0be8944dc2e7ab68ebb29 [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);
96extern int pwd_main(int argc, char** argv);
97extern int reboot_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000098extern int rmdir_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000099extern int rm_main(int argc, char** argv);
100extern int scan_partitions_main(int argc, char** argv);
101extern int sh_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000102extern int sfdisk_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000103extern int sleep_main(int argc, char** argv);
Eric Andersen87590061999-10-18 21:22:59 +0000104extern int swap_on_off_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000105extern int sync_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000106extern int tar_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +0000107extern int touch_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000108extern int tput_main(int argc, char** argv);
109extern int true_main(int argc, char** argv);
110extern int tryopen_main(int argc, char** argv);
111extern int umount_main(int argc, char** argv);
112extern int update_main(int argc, char** argv);
113extern int zcat_main(int argc, char** argv);
114extern int gzip_main(int argc, char** argv);
115
Eric Andersen2b69c401999-10-05 22:58:32 +0000116
117const char *modeString(int mode);
118const char *timeString(time_t timeVal);
Eric Andersenf811e071999-10-09 00:25:00 +0000119int isDirectory(const char *name);
120int isDevice(const char *name);
121int copyFile(const char *srcName, const char *destName, int setModes,
122 int followLinks);
123char *buildName(const char *dirName, const char *fileName);
124int makeString(int argc, const char **argv, char *buf, int bufLen);
Eric Andersen2b69c401999-10-05 22:58:32 +0000125char *getChunk(int size);
126char *chunkstrdup(const char *str);
127void freeChunks(void);
128int fullWrite(int fd, const char *buf, int len);
129int fullRead(int fd, char *buf, int len);
Eric Andersenbed30e91999-10-18 19:02:32 +0000130int recursiveAction(const char *fileName, int recurse, int followLinks, int delayDirAction,
Eric Andersen9b587181999-10-17 05:43:39 +0000131 int (*fileAction) (const char *fileName, struct stat* statbuf),
132 int (*dirAction) (const char *fileName, struct stat* statbuf));
Eric Andersenf811e071999-10-09 00:25:00 +0000133int match(const char* text, const char * pattern);
Eric Andersen17d49ef1999-10-06 20:25:32 +0000134const char* timeString(time_t timeVal);
Eric Andersencc8ed391999-10-05 16:24:54 +0000135
Eric Andersenf6be9441999-10-13 21:12:06 +0000136extern void createPath (const char *name, int mode);
137extern int parse_mode( const char* s, mode_t* theMode);
Eric Andersenb0e9a701999-10-18 22:28:26 +0000138extern volatile void usage(const char *usage);
139
Eric Andersencc8ed391999-10-05 16:24:54 +0000140
141#endif
142