diff options
author | Erik Andersen | 2000-05-12 19:41:47 +0000 |
---|---|---|
committer | Erik Andersen | 2000-05-12 19:41:47 +0000 |
commit | 7ab9c7ee52db8759d457819f5480378fa3aa97cc (patch) | |
tree | 37ef0fb8b142a4925b866c7caa5207b71b4ecae6 /utility.c | |
parent | 3d427ac5efd249dc25dd03deb30520335f68911a (diff) | |
download | busybox-7ab9c7ee52db8759d457819f5480378fa3aa97cc.zip busybox-7ab9c7ee52db8759d457819f5480378fa3aa97cc.tar.gz |
Lots of updates. Finished implementing BB_FEATURE_TRIVIAL_HELP
which lets you compile out most of the "--help" output, saving
up to 17k.
Renamed mnc to nc.
-Erik
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 74 |
1 files changed, 8 insertions, 66 deletions
@@ -33,6 +33,7 @@ || defined (BB_INSMOD) /* same conditions as recursiveAction */ #define bb_need_name_too_long +#define bb_need_memory_exhausted #endif #define BB_DECLARE_EXTERN #include "messages.c" @@ -111,7 +112,6 @@ extern void fatalError(const char *s, ...) exit( FALSE); } -#if defined BB_INIT /* Returns kernel version encoded as major*65536 + minor*256 + patch, * so, for example, to check if the kernel is greater than 2.2.11: * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> } @@ -128,9 +128,7 @@ extern int get_kernel_revision(void) sscanf(name.version, "%d.%d.%d", &major, &minor, &patch); return major * 65536 + minor * 256 + patch; } -#endif /* BB_INIT */ -#if defined (BB_CP_MV) || defined (BB_DU) #define HASH_SIZE 311 /* Should be prime */ #define hash_inode(i) ((i) % HASH_SIZE) @@ -197,9 +195,7 @@ void reset_ino_dev_hashtable(void) } } -#endif /* BB_CP_MV || BB_DU */ -#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN) /* * Return TRUE if a fileName is a directory. * Nonexistant files return FALSE. @@ -230,9 +226,7 @@ int isDirectory(const char *fileName, const int followLinks, struct stat *statBu } return status; } -#endif -#if defined (BB_CP_MV) /* * Copy one file to another, while possibly preserving its modes, times, and * modes. Returns TRUE if successful, or FALSE on a failure with an error @@ -382,11 +376,8 @@ copyFile(const char *srcName, const char *destName, return FALSE; } -#endif /* BB_CP_MV */ - -#if defined BB_TAR || defined BB_LS #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) @@ -429,10 +420,8 @@ const char *modeString(int mode) } return buf; } -#endif /* BB_TAR || BB_LS */ -#if defined BB_TAR /* * Return the standard ls-like time string from a time_t * This is static and so is overwritten on each call. @@ -457,9 +446,7 @@ const char *timeString(time_t timeVal) return buf; } -#endif /* BB_TAR */ -#if defined BB_TAR || defined BB_CP_MV /* * Write all of the supplied buffer out to a file. * This does multiple writes as necessary. @@ -485,10 +472,8 @@ int fullWrite(int fd, const char *buf, int len) return total; } -#endif /* BB_TAR || BB_CP_MV */ -#if defined BB_TAR || defined BB_TAIL /* * Read all of the supplied buffer from a file. * This does multiple reads as necessary. @@ -518,16 +503,8 @@ int fullRead(int fd, char *buf, int len) return total; } -#endif /* BB_TAR || BB_TAIL */ -#if defined (BB_CHMOD_CHOWN_CHGRP) \ - || defined (BB_CP_MV) \ - || defined (BB_FIND) \ - || defined (BB_INSMOD) \ - || defined (BB_RM) \ - || defined (BB_TAR) - /* * Walk down all the directories under the specified * location, and do something (something specified @@ -640,11 +617,9 @@ int recursiveAction(const char *fileName, return TRUE; } -#endif /* BB_CHMOD_CHOWN_CHGRP || BB_CP_MV || BB_FIND || BB_LS || BB_INSMOD */ -#if defined (BB_TAR) || defined (BB_MKDIR) /* * Attempt to create the directories along the specified path, except for * the final component. The mode is given for the final directory only, @@ -674,15 +649,10 @@ extern int createPath(const char *name, int mode) } return TRUE; } -#endif /* BB_TAR || BB_MKDIR */ -#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR) /* [ugoa]{+|-|=}[rwxst] */ - - - extern int parse_mode(const char *s, mode_t * theMode) { mode_t andMode = @@ -775,14 +745,9 @@ extern int parse_mode(const char *s, mode_t * theMode) } -#endif /* BB_CHMOD_CHOWN_CHGRP || BB_MKDIR */ - - -#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS || defined BB_TAR || defined BB_ID - /* This parses 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 or wanted for embedded @@ -887,10 +852,6 @@ gid_t my_getpwnamegid(char *name) return gid; } -#endif /* BB_CHMOD_CHOWN_CHGRP || BB_PS || BB_LS || BB_TAR || BB_ID */ - - -#if (defined BB_CHVT) || (defined BB_DEALLOCVT) #include <linux/kd.h> @@ -975,11 +936,9 @@ int get_console_fd(char *tty_name) } -#endif /* BB_CHVT || BB_DEALLOCVT */ -#if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED) - +#if !defined BB_REGEXP /* Do a case insensitive strstr() */ char *stristr(char *haystack, const char *needle) { @@ -1050,11 +1009,9 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, else return FALSE; } - -#endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */ +#endif /* ! BB_REGEXP */ -#if defined BB_FIND /* * Routine to see if a text string is matched by a wildcard pattern. * Returns TRUE if the text is matched, or FALSE if it is not matched @@ -1154,12 +1111,10 @@ extern int check_wildcard_match(const char *text, const char *pattern) return TRUE; } -#endif /* BB_FIND */ -#if defined BB_DF || defined BB_MTAB /* * Given a block device, find the mount table entry if that block device * is mounted. @@ -1198,11 +1153,9 @@ extern struct mntent *findMountPoint(const char *name, const char *table) endmntent(mountTable); return mountEntry; } -#endif /* BB_DF || BB_MTAB */ -#if defined BB_DD || defined BB_TAIL /* * Read a number with a possible multiplier. * Returns -1 if the number format is illegal. @@ -1249,10 +1202,8 @@ extern long getNum(const char *cp) return value; } -#endif /* BB_DD || BB_TAIL */ -#if defined BB_INIT || defined BB_SYSLOGD /* try to open up the specified device */ extern int device_open(char *device, int mode) { @@ -1271,15 +1222,11 @@ extern int device_open(char *device, int mode) fcntl(fd, F_SETFL, mode); return fd; } -#endif /* BB_INIT BB_SYSLOGD */ -#if defined BB_KILLALL || ( defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF )) #ifdef BB_FEATURE_USE_DEVPS_PATCH #include <linux/devps.h> -#endif -#if defined BB_FEATURE_USE_DEVPS_PATCH /* findPidByName() * * This finds the pid of the specified process, @@ -1336,7 +1283,7 @@ extern pid_t* findPidByName( char* pidName) && (strlen(pidName) == strlen(info.command_line))) { pidList=realloc( pidList, sizeof(pid_t) * (j+2)); if (pidList==NULL) - fatalError("out of memory\n"); + fatalError(memory_exhausted, ""); pidList[j++]=info.pid; } } @@ -1409,7 +1356,7 @@ extern pid_t* findPidByName( char* pidName) && (strlen(pidName) == strlen(p))) { pidList=realloc( pidList, sizeof(pid_t) * (i+2)); if (pidList==NULL) - fatalError("out of memory\n"); + fatalError(memory_exhausted, ""); pidList[i++]=strtol(next->d_name, NULL, 0); } } @@ -1418,7 +1365,6 @@ extern pid_t* findPidByName( char* pidName) return pidList; } #endif /* BB_FEATURE_USE_DEVPS_PATCH */ -#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */ /* this should really be farmed out to libbusybox.a */ extern void *xmalloc(size_t size) @@ -1426,11 +1372,11 @@ extern void *xmalloc(size_t size) void *cp = malloc(size); if (cp == NULL) - fatalError("out of memory\n"); + fatalError(memory_exhausted, ""); return cp; } -#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) +#if (__GLIBC__ < 2) extern int vdprintf(int d, const char *format, va_list ap) { char buf[BUF_SIZE]; @@ -1439,9 +1385,8 @@ extern int vdprintf(int d, const char *format, va_list ap) len = vsprintf(buf, format, ap); return write(d, buf, len); } -#endif /* BB_SYSLOGD */ +#endif -#if defined BB_FEATURE_MOUNT_LOOP extern int del_loop(const char *device) { int fd; @@ -1525,9 +1470,7 @@ extern char *find_unused_loop_device(void) } return NULL; } -#endif /* BB_FEATURE_MOUNT_LOOP */ -#if defined BB_MOUNT || defined BB_DF || ( defined BB_UMOUNT && ! defined BB_MTAB) extern int find_real_root_device_name(char* name) { DIR *dir; @@ -1569,7 +1512,6 @@ extern int find_real_root_device_name(char* name) return( FALSE); } -#endif const unsigned int CSTRING_BUFFER_LENGTH = 128; /* recursive parser that returns cstrings of arbitrary length |