Fix missing header file.
[oweals/busybox.git] / busybox.h
index 4a4f44aea3dec2dcc7e63ef71d1221549d644c66..5f9425a5bf28513b9e34af79d243ff38d7549bb9 100644 (file)
--- a/busybox.h
+++ b/busybox.h
 
 #include "Config.h"
 
-#ifdef DMALLOC
-#include "dmalloc.h"
-#endif
-
-#include <stdlib.h>
+#include <stdio.h>
 #include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
 #include <sys/stat.h>
-#include <sys/param.h>
-#include <mntent.h>
-#include <regex.h>
-/* for the _syscall() macros */
-#include <sys/syscall.h>
-#include <linux/unistd.h>
+#include <sys/types.h>
 
+#ifdef DMALLOC
+#include "dmalloc.h"
+#endif
 
 /* Some useful definitions */
 #define FALSE   ((int) 0)
 #define TRUE    ((int) 1)
+#define SKIP   ((int) 2)
 
 /* for mtab.c */
 #define MTAB_GETMOUNTPT '1'
 #define BUF_SIZE        8192
 #define EXPAND_ALLOC    1024
 
-
-#define isBlank(ch)     (((ch) == ' ') || ((ch) == '\t'))
-#define isDecimal(ch)   (((ch) >= '0') && ((ch) <= '9'))
-#define isOctal(ch)     (((ch) >= '0') && ((ch) <= '7'))
-#define isWildCard(ch)  (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
+static inline int is_decimal(ch) { return ((ch >= '0') && (ch <= '9')); }
+static inline int is_octal(ch)   { return ((ch >= '0') && (ch <= '7')); }
 
 /* Macros for min/max.  */
 #ifndef MIN
 #endif
 
 
-/* I don't like nested includes, but the string and io functions are used
- * too often
- */
-#include <stdio.h>
-#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
-#  include <string.h>
-#  if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
-#    include <memory.h>
-#  endif
-#  define memzero(s, n)     memset ((void *)(s), 0, (n))
-#else
-#  include <strings.h>
-#  define strchr            index
-#  define strrchr           rindex
-#  define memcpy(d, s, n)   bcopy((s), (d), (n))
-#  define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
-#  define memzero(s, n)     bzero((s), (n))
-#endif
-
-
 enum Location {
        _BB_DIR_ROOT = 0,
        _BB_DIR_BIN,
@@ -122,14 +91,14 @@ extern const char *applet_name;
 extern int applet_name_compare(const void *x, const void *y);
 
 extern void usage(const char *usage) __attribute__ ((noreturn));
-extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
-extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
-extern void perrorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
-extern void fatalPerror(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
-
-const char *modeString(int mode);
-const char *timeString(time_t timeVal);
-int isDirectory(const char *name, const int followLinks, struct stat *statBuf);
+extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
+extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
+extern void perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
+extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
+
+const char *mode_string(int mode);
+const char *time_string(time_t timeVal);
+int is_directory(const char *name, const int followLinks, struct stat *statBuf);
 int isDevice(const char *name);
 
 typedef struct ino_dev_hash_bucket_struct {
@@ -142,28 +111,29 @@ int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
 void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
 void reset_ino_dev_hashtable(void);
 
-int copyFile(const char *srcName, const char *destName,
+int copy_file(const char *srcName, const char *destName,
                 int setModes, int followLinks, int forceFlag);
-int copySubFile(int srcFd, int dstFd, size_t remaining);
+int copy_file_chunk(int srcFd, int dstFd, size_t remaining);
 char *buildName(const char *dirName, const char *fileName);
 int makeString(int argc, const char **argv, char *buf, int bufLen);
 char *getChunk(int size);
 char *chunkstrdup(const char *str);
 void freeChunks(void);
-int fullWrite(int fd, const char *buf, int len);
-int fullRead(int fd, char *buf, int len);
-int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
+ssize_t safe_read(int fd, void *buf, size_t count);
+int full_write(int fd, const char *buf, int len);
+int full_read(int fd, char *buf, int len);
+int recursive_action(const char *fileName, int recurse, int followLinks, int depthFirst,
          int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
          int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
          void* userData);
 
-extern int createPath (const char *name, int mode);
+extern int create_path (const char *name, int mode);
 extern int parse_mode( const char* s, mode_t* theMode);
 
 extern int get_kernel_revision(void);
 
 extern int get_console_fd(char* tty_name);
-extern struct mntent *findMountPoint(const char *name, const char *table);
+extern struct mntent *find_mount_point(const char *name, const char *table);
 extern void write_mtab(char* blockDevice, char* directory, 
        char* filesystemType, long flags, char* string_flags);
 extern void erase_mtab(const char * name);
@@ -172,19 +142,18 @@ extern char *mtab_first(void **iter);
 extern char *mtab_next(void **iter);
 extern char *mtab_getinfo(const char *match, const char which);
 extern int check_wildcard_match(const char* text, const char* pattern);
-extern long getNum (const char *cp);
-extern pid_t* findPidByName( char* pidName);
+extern long atoi_w_units (const char *cp);
+extern pid_t* find_pid_by_name( char* pidName);
 extern int find_real_root_device_name(char* name);
 extern char *get_line_from_file(FILE *file);
 extern void print_file(FILE *file);
 extern int print_file_by_name(char *filename);
 extern char process_escape_sequence(char **ptr);
 extern char *get_last_path_component(char *path);
-extern void xregcomp(regex_t *preg, const char *regex, int cflags);
 extern FILE *wfopen(const char *path, const char *mode);
 extern FILE *xfopen(const char *path, const char *mode);
 
-#ifndef DMALLOC 
+#ifndef DMALLOC
 extern void *xmalloc (size_t size);
 extern void *xrealloc(void *old, size_t size);
 extern void *xcalloc(size_t nmemb, size_t size);
@@ -192,6 +161,13 @@ extern char *xstrdup (const char *s);
 #endif
 extern char *xstrndup (const char *s, int n);
 
+struct suffix_mult {
+       char *suffix;
+       int mult;
+};
+
+extern unsigned long parse_number(const char *numstr, struct suffix_mult *suffixes);
+
 
 /* These parse entries in /etc/passwd and /etc/group.  This is desirable
  * for BusyBox since we want to avoid using the glibc NSS stuff, which
@@ -253,4 +229,19 @@ extern int sysinfo (struct sysinfo* info);
 #define isclr(a,i)      (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
 #endif
 
+#ifdef BB_FEATURE_HUMAN_READABLE
+char *format(unsigned long val, unsigned long hr);
+#define KILOBYTE 1024
+#define MEGABYTE (KILOBYTE*1024)
+#define GIGABYTE (MEGABYTE*1024)
+#endif
+
+#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
+#define RESERVE_BB_BUFFER(buffer,len)           char buffer[len]
+#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
+#else
+#define RESERVE_BB_BUFFER(buffer,len)           char *buffer=xmalloc(len)
+#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
+#endif
+
 #endif /* _BB_INTERNAL_H_ */