diff options
author | Manuel Novoa III | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /include | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip busybox-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz |
Major coreutils update.
Diffstat (limited to 'include')
-rw-r--r-- | include/dump.h | 11 | ||||
-rw-r--r-- | include/libbb.h | 216 | ||||
-rw-r--r-- | include/usage.h | 97 |
3 files changed, 214 insertions, 110 deletions
diff --git a/include/dump.h b/include/dump.h index 0e8dbe0..3f4b480 100644 --- a/include/dump.h +++ b/include/dump.h @@ -38,5 +38,12 @@ typedef struct _fs { /* format strings */ int bcnt; } FS; -void add(char *fmt); -int dump (char **argv); +extern void bb_dump_add(const char *fmt); +extern int bb_dump_dump (char **argv); +extern int bb_dump_size(FS * fs); + +extern FS *bb_dump_fshead; /* head of format strings */ +extern int bb_dump_blocksize; /* data block size */ +extern int bb_dump_length; /* max bytes to read */ +extern enum _vflag bb_dump_vflag; +extern off_t bb_dump_skip; /* bytes to skip */ diff --git a/include/libbb.h b/include/libbb.h index 8cb72de..f79def3 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -28,6 +28,7 @@ #include <stdarg.h> #include <sys/stat.h> #include <sys/types.h> +#include <termios.h> #include <netdb.h> @@ -86,84 +87,132 @@ char *strtok_r(char *s, const char *delim, char **ptrptr); #define MAX(a,b) (((a)>(b))?(a):(b)) #endif -extern void show_usage(void) __attribute__ ((noreturn)); -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))); -extern void vherror_msg(const char *s, va_list p); -extern void herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); -extern void herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); +extern void bb_show_usage(void) __attribute__ ((noreturn)); +extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); +extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); +extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); +extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); +extern void bb_vherror_msg(const char *s, va_list p); +extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); +extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); + +extern void bb_perror_nomsg_and_die(void) __attribute__ ((noreturn)); +extern void bb_perror_nomsg(void); /* These two are used internally -- you shouldn't need to use them */ -extern void verror_msg(const char *s, va_list p); -extern void vperror_msg(const char *s, va_list p); - -const char *mode_string(int mode); -const char *time_string(time_t timeVal); -int is_directory(const char *name, int followLinks, struct stat *statBuf); -int isDevice(const char *name); - -int remove_file(const char *path, int flags); -int copy_file(const char *source, const char *dest, int flags); -int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize); -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); -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, +extern void bb_verror_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0))); +extern void bb_vperror_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0))); + +extern const char *bb_mode_string(int mode); +extern int is_directory(const char *name, int followLinks, struct stat *statBuf); + +extern int remove_file(const char *path, int flags); +extern int copy_file(const char *source, const char *dest, int flags); +extern ssize_t safe_read(int fd, void *buf, size_t count); +extern ssize_t bb_full_write(int fd, const void *buf, size_t len); +extern ssize_t bb_full_read(int fd, void *buf, size_t len); +extern 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 parse_mode( const char* s, mode_t* theMode); +extern int bb_parse_mode( const char* s, mode_t* theMode); extern long bb_xgetlarg(char *arg, int base, long lower, long upper); +extern unsigned long bb_baud_to_value(speed_t speed); +extern speed_t bb_value_to_baud(unsigned long value); + extern int get_kernel_revision(void); extern int get_console_fd(void); 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); + char* filesystemType, long flags, char* string_flags); extern void erase_mtab(const char * name); -extern long atoi_w_units (const char *cp); -extern long* find_pid_by_name( const char* pidName); +extern long *find_pid_by_name( const char* pidName); extern char *find_real_root_device_name(const char* name); -extern char *get_line_from_file(FILE *file); -extern void print_file(FILE *file); -extern int copyfd(int fd1, int fd2, const off_t chunksize); -extern int print_file_by_name(char *filename); -extern char process_escape_sequence(const char **ptr); -extern char *get_last_path_component(char *path); -extern FILE *wfopen(const char *path, const char *mode); -extern FILE *xfopen(const char *path, const char *mode); +extern char *bb_get_line_from_file(FILE *file); +extern char *bb_get_chomped_line_from_file(FILE *file); +extern int bb_copyfd(int fd1, int fd2, const off_t chunksize); +extern void bb_xprint_and_close_file(FILE *file); +extern int bb_xprint_file_by_name(const char *filename); +extern char bb_process_escape_sequence(const char **ptr); +extern char *bb_get_last_path_component(char *path); +extern FILE *bb_wfopen(const char *path, const char *mode); +extern FILE *bb_xfopen(const char *path, const char *mode); + +//#warning rename? +extern int bb_fclose_nonstdin(FILE *f); +extern void bb_fflush_stdout_and_exit(int retval) __attribute__ ((noreturn)); +extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts); +//#warning rename? +extern FILE *bb_wfopen_input(const char *filename); + +extern int bb_vfprintf(FILE * __restrict stream, const char * __restrict format, + va_list arg) __attribute__ ((format (printf, 2, 0))); +extern int bb_vprintf(const char * __restrict format, va_list arg) + __attribute__ ((format (printf, 1, 0))); +extern int bb_fprintf(FILE * __restrict stream, const char * __restrict format, ...) + __attribute__ ((format (printf, 2, 3))); +extern int bb_printf(const char * __restrict format, ...) + __attribute__ ((format (printf, 1, 2))); + +//#warning rename to xferror_filename? +extern void bb_xferror(FILE *fp, const char *fn); +extern void bb_xferror_stdout(void); +extern void bb_xfflush_stdout(void); + +extern void bb_warn_ignoring_args(int n); + extern void chomp(char *s); extern void trim(char *s); +extern const char *bb_skip_whitespace(const char *); + extern struct BB_applet *find_applet_by_name(const char *name); void run_applet_by_name(const char *name, int argc, char **argv); +//#warning is this needed anymore? #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); -extern char *xstrdup (const char *s); +extern char *bb_xstrdup (const char *s); #endif -extern char *xstrndup (const char *s, int n); +extern char *bb_xstrndup (const char *s, int n); extern char * safe_strncpy(char *dst, const char *src, size_t size); struct suffix_mult { const char *suffix; - int mult; + unsigned int mult; }; -extern unsigned long parse_number(const char *numstr, +extern unsigned long bb_xgetularg_bnd_sfx(const char *arg, int base, + unsigned long lower, + unsigned long upper, + const struct suffix_mult *suffixes); +extern unsigned long bb_xgetularg_bnd(const char *arg, int base, + unsigned long lower, + unsigned long upper); +extern unsigned long bb_xgetularg10_bnd(const char *arg, + unsigned long lower, + unsigned long upper); +extern unsigned long bb_xgetularg10(const char *arg); + +extern long bb_xgetlarg_bnd_sfx(const char *arg, int base, + long lower, + long upper, + const struct suffix_mult *suffixes); +extern long bb_xgetlarg10_sfx(const char *arg, const struct suffix_mult *suffixes); + + +//#warning pitchable now? +extern unsigned long bb_xparse_number(const char *numstr, const struct suffix_mult *suffixes); +//#warning change names? + /* 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 * increases target size and is often not needed embedded systems. */ @@ -217,7 +266,7 @@ enum { }; const char *make_human_readable_str(unsigned long size, unsigned long block_size, unsigned long display_unit); -int ask_confirmation(void); +int bb_ask_confirmation(void); int klogctl(int type, char * b, int len); char *xgetcwd(char *cwd); @@ -228,6 +277,7 @@ char *last_char_is(const char *s, int c); extern long arith (const char *startbuf, int *errcode); int read_package_field(const char *package_buffer, char **field_name, char **field_value); +//#warning yuk! char *fgets_str(FILE *file, const char *terminating_string); extern int uncompress(int fd_in, int fd_out); @@ -239,19 +289,15 @@ extern int create_icmp_socket(void); extern int create_icmp6_socket(void); extern int xconnect(const char *host, const char *port); +//#warning wrap this? char *dirname (char *path); -int make_directory (char *path, long mode, int flags); +int bb_make_directory (char *path, long mode, int flags); const char *u_signal_names(const char *str_sig, int *signo, int startnum); -char *simplify_path(const char *path); - -#define CT_AUTO 0 -#define CT_UNIX2DOS 1 -#define CT_DOS2UNIX 2 -/* extern int convert(char *fn, int ConvType); */ +char *bb_simplify_path(const char *path); -enum { +enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ FILEUTILS_PRESERVE_STATUS = 1, FILEUTILS_DEREFERENCE = 2, FILEUTILS_RECUR = 4, @@ -259,29 +305,31 @@ enum { FILEUTILS_INTERACTIVE = 16 }; -extern const char *applet_name; -extern const char * const full_version; -extern const char * const name_too_long; -extern const char * const omitting_directory; -extern const char * const not_a_directory; -extern const char * const memory_exhausted; -extern const char * const invalid_date; -extern const char * const invalid_option; -extern const char * const io_error; -extern const char * const dash_dash_help; -extern const char * const write_error; -extern const char * const too_few_args; -extern const char * const name_longer_than_foo; -extern const char * const unknown; -extern const char * const can_not_create_raw_socket; -extern const char * const nologin_file; -extern const char * const passwd_file; -extern const char * const shadow_file; -extern const char * const gshadow_file; -extern const char * const group_file; -extern const char * const securetty_file; -extern const char * const motd_file; -extern const char * const _path_login; +extern const char *bb_applet_name; + +extern const char * const bb_msg_full_version; +extern const char * const bb_msg_memory_exhausted; +extern const char * const bb_msg_invalid_date; +extern const char * const bb_msg_io_error; +extern const char * const bb_msg_write_error; +extern const char * const bb_msg_name_longer_than_foo; +extern const char * const bb_msg_unknown; +extern const char * const bb_msg_can_not_create_raw_socket; +extern const char * const bb_msg_perm_denied_are_you_root; +extern const char * const bb_msg_standard_input; +extern const char * const bb_msg_standard_output; + +extern const char * const bb_path_nologin_file; +extern const char * const bb_path_passwd_file; +extern const char * const bb_path_shadow_file; +extern const char * const bb_path_gshadow_file; +extern const char * const bb_path_group_file; +extern const char * const bb_path_securetty_file; +extern const char * const bb_path_motd_file; + +extern const char bb_path_mtab_file[]; + +extern int bb_default_error_retval; #ifdef CONFIG_FEATURE_DEVFS # define CURRENT_VC "/dev/vc/0" @@ -309,6 +357,8 @@ extern const char * const _path_login; # define LOOP_FORMAT "/dev/loop%d" #endif +//#warning put these in .o files + /* The following devices are the same on devfs and non-devfs systems. */ #define CURRENT_TTY "/dev/tty" #define CONSOLE_DEV "/dev/console" @@ -318,10 +368,10 @@ void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); void reset_ino_dev_hashtable(void); /* Stupid gcc always includes its own builtin strlen()... */ -extern size_t xstrlen(const char *string); -#define strlen(x) xstrlen(x) +extern size_t bb_strlen(const char *string); +#define strlen(x) bb_strlen(x) -void bb_asprintf(char **string_ptr, const char *format, ...) __attribute__ ((format (printf, 2, 3))); +void bb_xasprintf(char **string_ptr, const char *format, ...) __attribute__ ((format (printf, 2, 3))); #define FAIL_DELAY 3 @@ -335,10 +385,10 @@ extern char *pw_encrypt(const char *clear, const char *salt); extern struct spwd *pwd_to_spwd(const struct passwd *pw); extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); -extern int xopen(const char *pathname, int flags); -extern ssize_t xread(int fd, void *buf, size_t count); -extern void xread_all(int fd, void *buf, size_t count); -extern unsigned char xread_char(int fd); +extern int bb_xopen(const char *pathname, int flags); +extern ssize_t bb_xread(int fd, void *buf, size_t count); +extern void bb_xread_all(int fd, void *buf, size_t count); +extern unsigned char bb_xread_char(int fd); typedef struct { int pid; diff --git a/include/usage.h b/include/usage.h index 8fc12f1..bbc0bab 100644 --- a/include/usage.h +++ b/include/usage.h @@ -98,9 +98,11 @@ "\t-y\tDisplay the entire year." #define cat_trivial_usage \ - "[FILE]..." + "[-u] [FILE]..." #define cat_full_usage \ - "Concatenates FILE(s) and prints them to stdout." + "Concatenates FILE(s) and prints them to stdout.\n\n" \ + "Options:\n" \ + "\t-u\tignored since unbuffered i/o is always used" #define cat_example_usage \ "$ cat /proc/uptime\n" \ "110716.72 17.67" @@ -397,20 +399,34 @@ #define dpkg_deb_example_usage \ "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n" +#ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K +#define USAGE_DU_DEFALT_BLOCKSIZE_1k(a) a +#define USAGE_NOT_DU_DEFALT_BLOCKSIZE_1k(a) +#else +#define USAGE_DU_DEFALT_BLOCKSIZE_1k(a) +#define USAGE_NOT_DU_DEFALT_BLOCKSIZE_1k(a) a +#endif + #define du_trivial_usage \ - "[-lsx" USAGE_HUMAN_READABLE("hm") USAGE_NOT_HUMAN_READABLE("") "k] [FILE]..." + "[-aHLdclsx" USAGE_HUMAN_READABLE("hm") "k] [FILE]..." #define du_full_usage \ "Summarizes disk space used for each FILE and/or directory.\n" \ - "Disk space is printed in units of 1024 bytes.\n\n" \ - "Options:\n" \ + "Disk space is printed in units of " \ + USAGE_DU_DEFALT_BLOCKSIZE_1k("1024") USAGE_NOT_DU_DEFALT_BLOCKSIZE_1k("512") \ + " bytes.\n\n" \ + "Options:\n" \ + "\t-a\tshow sizes of files in addition to directories\n" \ + "\t-H\tfollow symbolic links that are FILE command line args\n" \ + "\t-L\tfollow all symbolic links encountered\n" \ + "\t-d N\tlimit output to directories (and files with -a) of depth < N\n" \ + "\t-c\toutput a grand total\n" \ "\t-l\tcount sizes many times if hard linked\n" \ - "\t-s\tdisplay only a total for each argument" \ - USAGE_HUMAN_READABLE( \ - "\n\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" \ - "\t-m\tprint sizes in megabytes\n" \ + "\t-s\tdisplay only a total for each argument\n" \ "\t-x\tskip directories on different filesystems\n" \ - "\t-k\tprint sizes in kilobytes(default)") USAGE_NOT_HUMAN_READABLE( \ - "\n\t-k\tprint sizes in kilobytes(compatibility)") + USAGE_HUMAN_READABLE( \ + "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" \ + "\t-m\tprint sizes in megabytes\n" ) \ + "\t-k\tprint sizes in kilobytes" USAGE_DU_DEFALT_BLOCKSIZE_1k("(default)") #define du_example_usage \ "$ du\n" \ "16 ./CVS\n" \ @@ -451,25 +467,31 @@ "8|125||l4|||0|0|0|955637629|998367|0\n" \ "6|245|tty1|1|LOGIN||0|0|0|955637630|998974|0\n" \ "6|246|tty2|2|LOGIN||0|0|0|955637630|999498|0\n" \ - "7|336|pts/0|vt00andersen|andersen|:0.0|0|0|0|955637763|0|0\n" + "7|336|pts/0|vt00|andersen|:0.0|0|0|0|955637763|0|0\n" + +#ifdef CONFIG_FEATURE_FANCY_ECHO + #define USAGE_FANCY_ECHO(a) a +#else + #define USAGE_FANCY_ECHO(a) +#endif #define echo_trivial_usage \ - "[-neE] [ARG ...]" + USAGE_FANCY_ECHO("[-neE] ") "[ARG ...]" #define echo_full_usage \ "Prints the specified ARGs to stdout\n\n" \ - "Options:\n" \ + USAGE_FANCY_ECHO("Options:\n" \ "\t-n\tsuppress trailing newline\n" \ "\t-e\tinterpret backslash-escaped characters (i.e., \\t=tab)\n" \ - "\t-E\tdisable interpretation of backslash-escaped characters" + "\t-E\tdisable interpretation of backslash-escaped characters") #define echo_example_usage \ "$ echo "Erik is cool"\n" \ "Erik is cool\n" \ - "$ echo -e "Erik\\nis\\ncool"\n" \ + USAGE_FANCY_ECHO("$ echo -e "Erik\\nis\\ncool"\n" \ "Erik\n" \ "is\n" \ "cool\n" \ "$ echo "Erik\\nis\\ncool"\n" \ - "Erik\\nis\\ncool\n" + "Erik\\nis\\ncool\n") #define env_trivial_usage \ "[-iu] [-] [name=value]... [command]" @@ -757,6 +779,12 @@ #define halt_full_usage \ "Halt the system." +#ifdef CONFIG_FEATURE_FANCY_HEAD +#define USAGE_FANCY_HEAD(a) a +#else +#define USAGE_FANCY_HEAD(a) +#endif + #define head_trivial_usage \ "[OPTION] [FILE]..." #define head_full_usage \ @@ -764,7 +792,11 @@ "With more than one FILE, precede each with a header giving the\n" \ "file name. With no FILE, or when FILE is -, read standard input.\n\n" \ "Options:\n" \ - "\t-n NUM\t\tPrint first NUM lines instead of first 10" + "\t-n NUM\t\tPrint first NUM lines instead of first 10" \ + USAGE_FANCY_HEAD( \ + "\n\t-c NUM\t\toutput the first NUM bytes\n" \ + "\t-q\t\tnever output headers giving file names\n" \ + "\t-v\t\talways output headers giving file names" ) #define head_example_usage \ "$ head -n 2 /etc/passwd\n" \ "root:x:0:0:root:/root:/bin/bash\n" \ @@ -1762,7 +1794,7 @@ "Remove (unlink) the FILE(s). You may use '--' to\n" \ "indicate that all following arguments are non-options.\n\n" \ "Options:\n" \ - "\t-i\t\talways prompt before removing each destination" \ + "\t-i\t\talways prompt before removing each destination\n" \ "\t-f\t\tremove existing destinations, never prompt\n" \ "\t-r or -R\tremove the contents of directories recursively" #define rm_example_usage \ @@ -1864,14 +1896,26 @@ #define sha1sum_full_usage \ "[OPTION] [FILE]" +#ifdef CONFIG_FEATURE_FANCY_SLEEP + #define USAGE_FANCY_SLEEP(a) a + #define USAGE_NOT_FANCY_SLEEP(a) +#else + #define USAGE_FANCY_SLEEP(a) + #define USAGE_NOT_FANCY_SLEEP(a) a +#endif + #define sleep_trivial_usage \ - "N" + USAGE_FANCY_SLEEP("[") "N" USAGE_FANCY_SLEEP("]...") #define sleep_full_usage \ - "Pause for N seconds." + USAGE_NOT_FANCY_SLEEP("Pause for N seconds.") \ + USAGE_FANCY_SLEEP( \ +"Pause for a time equal to the total of the args given, where each arg can\n" \ +"have an optional suffix of (s)econds, (m)inutes, (h)ours, or (d)ays.") #define sleep_example_usage \ "$ sleep 2\n" \ - "[2 second delay results]\n" - + "[2 second delay results]\n" \ + USAGE_FANCY_SLEEP("$ sleep 1d 3h 22m 8s\n" \ + "[98528 second delay results]\n") #ifdef CONFIG_FEATURE_SORT_UNIQUE #define USAGE_SORT_UNIQUE(a) a @@ -2077,7 +2121,8 @@ #define tee_full_usage \ "Copy standard input to each FILE, and also to standard output.\n\n" \ "Options:\n" \ - "\t-a\tappend to the given FILEs, do not overwrite" + "\t-a\tappend to the given FILEs, do not overwrite\n" \ + "\t-i\tignore interrupt signals (SIGINT)" #define tee_example_usage \ "$ echo "Hello" | tee /tmp/foo\n" \ "$ cat /tmp/foo\n" \ @@ -2312,7 +2357,9 @@ "Options:\n" \ "\t-c\tprefix lines by the number of occurrences\n" \ "\t-d\tonly print duplicate lines\n" \ - "\t-u\tonly print unique lines" + "\t-u\tonly print unique lines\n" \ + "\t-f N\tskip the first N fields\n" \ + "\t-s N\tskip the first N chars (after any skipped fields)" #define uniq_example_usage \ "$ echo -e \"a\\na\\nb\\nc\\nc\\na\" | sort | uniq\n" \ "a\n" \ |