blob: 9c7dda4d4052bab9479d645c0431803d2a0d6f4a [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 */
36typedef int BOOL;
37#define STDIN 0
38#define STDOUT 1
Eric Andersen2b69c401999-10-05 22:58:32 +000039#define FALSE ((BOOL) 1)
40#define TRUE ((BOOL) 0)
Eric Andersencc8ed391999-10-05 16:24:54 +000041
42#define PATH_LEN 1024
43#define BUF_SIZE 8192
44#define EXPAND_ALLOC 1024
45
46#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
47#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
48#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
49#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
50
51
52
53struct FileInfo {
54 unsigned int complainInPostProcess:1;
55 unsigned int changeUserID:1;
56 unsigned int changeGroupID:1;
57 unsigned int changeMode:1;
58 unsigned int create:1;
59 unsigned int force:1;
60 unsigned int recursive:1;
61 unsigned int processDirectoriesAfterTheirContents;
62 unsigned int makeParentDirectories:1;
63 unsigned int didOperation:1;
64 unsigned int isSymbolicLink:1;
65 unsigned int makeSymbolicLink:1;
66 unsigned int dyadic:1;
67 const char* source;
68 const char* destination;
69 int directoryLength;
70 uid_t userID;
71 gid_t groupID;
72 mode_t andWithMode;
73 mode_t orWithMode;
74 struct stat stat;
75 const struct Applet *
76 applet;
77};
78
79struct Applet {
80 const char* name;
81 int (*main)(int argc, char** argv);
82};
83
84extern void name_and_error(const char*);
85extern int is_a_directory(const char*);
86extern char* join_paths(char *, const char *, const char *);
87
88extern int descend(
89 struct FileInfo *o
90 ,int (*function)(const struct FileInfo * i));
91
92extern struct mntent *
93 findMountPoint(const char*, const char *);
94
95extern void usage(const char*);
96extern int busybox_main(int argc, char** argv);
97extern int block_device_main(int argc, char** argv);
98extern int cat_more_main(int argc, char** argv);
Eric Andersen4bea32a1999-10-06 00:30:51 +000099extern int more_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000100extern int chgrp_main(int argc, char** argv);
101extern int chmod_main(int argc, char** argv);
102extern int chown_main(int argc, char** argv);
103extern int chroot_main(int argc, char** argv);
104extern int clear_main(int argc, char** argv);
105extern int date_main(int argc, char** argv);
106extern int dd_main(int argc, char** argv);
107extern int df_main(int argc, char** argv);
108extern int dmesg_main(int argc, char** argv);
109extern int dyadic_main(int argc, char** argv);
110extern int false_main(int argc, char** argv);
111extern int fdisk_main(int argc, char** argv);
112extern int find_main(int argc, char** argv);
113extern int grep_main(int argc, char** argv);
114extern int halt_main(int argc, char** argv);
115extern int init_main(int argc, char** argv);
116extern int kill_main(int argc, char** argv);
117extern int length_main(int argc, char** argv);
118extern int ln_main(int argc, char** argv);
119extern int loadkmap_main(int argc, char** argv);
120extern int losetup_main(int argc, char** argv);
121extern int ls_main(int argc, char** argv);
122extern int makedevs_main(int argc, char** argv);
123extern int math_main(int argc, char** argv);
124extern int mknod_main(int argc, char** argv);
125extern int mkswap_main(int argc, char** argv);
126extern int mnc_main(int argc, char** argv);
127extern int monadic_main(int argc, char** argv);
128extern int mount_main(int argc, char** argv);
129extern int mt_main(int argc, char** argv);
130extern int printf_main(int argc, char** argv);
131extern int pwd_main(int argc, char** argv);
132extern int reboot_main(int argc, char** argv);
133extern int rm_main(int argc, char** argv);
134extern int scan_partitions_main(int argc, char** argv);
135extern int sh_main(int argc, char** argv);
136extern int sleep_main(int argc, char** argv);
137extern int tar_main(int argc, char** argv);
138extern int sync_main(int argc, char** argv);
139extern int tput_main(int argc, char** argv);
140extern int true_main(int argc, char** argv);
141extern int tryopen_main(int argc, char** argv);
142extern int umount_main(int argc, char** argv);
143extern int update_main(int argc, char** argv);
144extern int zcat_main(int argc, char** argv);
145extern int gzip_main(int argc, char** argv);
146
147extern int
148parse_mode(
149 const char* s
150,mode_t * or
151,mode_t * and
152,int * group_execute);
153
154extern int parse_user_name(const char* string, struct FileInfo * i);
155
Eric Andersencc8ed391999-10-05 16:24:54 +0000156
Eric Andersen2b69c401999-10-05 22:58:32 +0000157/*
158 * A chunk of data.
159 * Chunks contain data which is allocated as needed, but which is
160 * not freed until all of the data needs freeing, such as at
161 * the beginning of the next command.
162 */
163typedef struct chunk CHUNK;
164#define CHUNK_INIT_SIZE 4
165
166struct chunk {
167 CHUNK *next;
168 char data[CHUNK_INIT_SIZE]; /* actually of varying length */
169};
170
171const char *modeString(int mode);
172const char *timeString(time_t timeVal);
173BOOL isDirectory(const char *name);
174BOOL isDevice(const char *name);
175BOOL copyFile(const char *srcName, const char *destName, BOOL setModes);
176const char *buildName(const char *dirName, const char *fileName);
177BOOL makeString(int argc, const char **argv, char *buf, int bufLen);
178char *getChunk(int size);
179char *chunkstrdup(const char *str);
180void freeChunks(void);
181int fullWrite(int fd, const char *buf, int len);
182int fullRead(int fd, char *buf, int len);
Eric Andersen9d3aba71999-10-06 09:04:55 +0000183int recursiveAction(const char *fileName, BOOL recurse, BOOL followLinks,
Eric Andersen2b69c401999-10-05 22:58:32 +0000184 int (*fileAction) (const char *fileName),
185 int (*dirAction) (const char *fileName));
Eric Andersen17d49ef1999-10-06 20:25:32 +0000186BOOL match(const char* text, const char * pattern);
187const char* timeString(time_t timeVal);
Eric Andersencc8ed391999-10-05 16:24:54 +0000188
189
190#endif
191