diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-05-13 00:28:25 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-05-13 00:28:25 +0000 |
commit | 23dea9b712daf0f29bdbb0e6adce1d697f53cefc (patch) | |
tree | cc33af862cd2980866ca4ef9048e8b2d42e8eb0b /utility.c | |
parent | 7ab9c7ee52db8759d457819f5480378fa3aa97cc (diff) | |
download | busybox-w32-23dea9b712daf0f29bdbb0e6adce1d697f53cefc.tar.gz busybox-w32-23dea9b712daf0f29bdbb0e6adce1d697f53cefc.tar.bz2 busybox-w32-23dea9b712daf0f29bdbb0e6adce1d697f53cefc.zip |
So much for my evil optimization. Doesn't seem to work. Will test
more on it later.
-Erik
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 67 |
1 files changed, 63 insertions, 4 deletions
@@ -112,6 +112,7 @@ extern void fatalError(const char *s, ...) | |||
112 | exit( FALSE); | 112 | exit( FALSE); |
113 | } | 113 | } |
114 | 114 | ||
115 | #if defined BB_INIT | ||
115 | /* Returns kernel version encoded as major*65536 + minor*256 + patch, | 116 | /* Returns kernel version encoded as major*65536 + minor*256 + patch, |
116 | * so, for example, to check if the kernel is greater than 2.2.11: | 117 | * so, for example, to check if the kernel is greater than 2.2.11: |
117 | * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> } | 118 | * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> } |
@@ -128,7 +129,9 @@ extern int get_kernel_revision(void) | |||
128 | sscanf(name.version, "%d.%d.%d", &major, &minor, &patch); | 129 | sscanf(name.version, "%d.%d.%d", &major, &minor, &patch); |
129 | return major * 65536 + minor * 256 + patch; | 130 | return major * 65536 + minor * 256 + patch; |
130 | } | 131 | } |
132 | #endif /* BB_INIT */ | ||
131 | 133 | ||
134 | #if defined (BB_CP_MV) || defined (BB_DU) | ||
132 | 135 | ||
133 | #define HASH_SIZE 311 /* Should be prime */ | 136 | #define HASH_SIZE 311 /* Should be prime */ |
134 | #define hash_inode(i) ((i) % HASH_SIZE) | 137 | #define hash_inode(i) ((i) % HASH_SIZE) |
@@ -195,7 +198,9 @@ void reset_ino_dev_hashtable(void) | |||
195 | } | 198 | } |
196 | } | 199 | } |
197 | 200 | ||
201 | #endif /* BB_CP_MV || BB_DU */ | ||
198 | 202 | ||
203 | #if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN) | ||
199 | /* | 204 | /* |
200 | * Return TRUE if a fileName is a directory. | 205 | * Return TRUE if a fileName is a directory. |
201 | * Nonexistant files return FALSE. | 206 | * Nonexistant files return FALSE. |
@@ -226,7 +231,9 @@ int isDirectory(const char *fileName, const int followLinks, struct stat *statBu | |||
226 | } | 231 | } |
227 | return status; | 232 | return status; |
228 | } | 233 | } |
234 | #endif | ||
229 | 235 | ||
236 | #if defined (BB_CP_MV) | ||
230 | /* | 237 | /* |
231 | * Copy one file to another, while possibly preserving its modes, times, and | 238 | * Copy one file to another, while possibly preserving its modes, times, and |
232 | * modes. Returns TRUE if successful, or FALSE on a failure with an error | 239 | * modes. Returns TRUE if successful, or FALSE on a failure with an error |
@@ -376,8 +383,11 @@ copyFile(const char *srcName, const char *destName, | |||
376 | 383 | ||
377 | return FALSE; | 384 | return FALSE; |
378 | } | 385 | } |
386 | #endif /* BB_CP_MV */ | ||
387 | |||
379 | 388 | ||
380 | 389 | ||
390 | #if defined BB_TAR || defined BB_LS | ||
381 | 391 | ||
382 | #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) | 392 | #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) |
383 | #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) | 393 | #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) |
@@ -420,8 +430,10 @@ const char *modeString(int mode) | |||
420 | } | 430 | } |
421 | return buf; | 431 | return buf; |
422 | } | 432 | } |
433 | #endif /* BB_TAR || BB_LS */ | ||
423 | 434 | ||
424 | 435 | ||
436 | #if defined BB_TAR | ||
425 | /* | 437 | /* |
426 | * Return the standard ls-like time string from a time_t | 438 | * Return the standard ls-like time string from a time_t |
427 | * This is static and so is overwritten on each call. | 439 | * This is static and so is overwritten on each call. |
@@ -446,7 +458,9 @@ const char *timeString(time_t timeVal) | |||
446 | 458 | ||
447 | return buf; | 459 | return buf; |
448 | } | 460 | } |
461 | #endif /* BB_TAR */ | ||
449 | 462 | ||
463 | #if defined BB_TAR || defined BB_CP_MV | ||
450 | /* | 464 | /* |
451 | * Write all of the supplied buffer out to a file. | 465 | * Write all of the supplied buffer out to a file. |
452 | * This does multiple writes as necessary. | 466 | * This does multiple writes as necessary. |
@@ -472,8 +486,10 @@ int fullWrite(int fd, const char *buf, int len) | |||
472 | 486 | ||
473 | return total; | 487 | return total; |
474 | } | 488 | } |
489 | #endif /* BB_TAR || BB_CP_MV */ | ||
475 | 490 | ||
476 | 491 | ||
492 | #if defined BB_TAR || defined BB_TAIL | ||
477 | /* | 493 | /* |
478 | * Read all of the supplied buffer from a file. | 494 | * Read all of the supplied buffer from a file. |
479 | * This does multiple reads as necessary. | 495 | * This does multiple reads as necessary. |
@@ -503,8 +519,16 @@ int fullRead(int fd, char *buf, int len) | |||
503 | 519 | ||
504 | return total; | 520 | return total; |
505 | } | 521 | } |
522 | #endif /* BB_TAR || BB_TAIL */ | ||
506 | 523 | ||
507 | 524 | ||
525 | #if defined (BB_CHMOD_CHOWN_CHGRP) \ | ||
526 | || defined (BB_CP_MV) \ | ||
527 | || defined (BB_FIND) \ | ||
528 | || defined (BB_INSMOD) \ | ||
529 | || defined (BB_RM) \ | ||
530 | || defined (BB_TAR) | ||
531 | |||
508 | /* | 532 | /* |
509 | * Walk down all the directories under the specified | 533 | * Walk down all the directories under the specified |
510 | * location, and do something (something specified | 534 | * location, and do something (something specified |
@@ -617,9 +641,11 @@ int recursiveAction(const char *fileName, | |||
617 | return TRUE; | 641 | return TRUE; |
618 | } | 642 | } |
619 | 643 | ||
644 | #endif /* BB_CHMOD_CHOWN_CHGRP || BB_CP_MV || BB_FIND || BB_LS || BB_INSMOD */ | ||
620 | 645 | ||
621 | 646 | ||
622 | 647 | ||
648 | #if defined (BB_TAR) || defined (BB_MKDIR) | ||
623 | /* | 649 | /* |
624 | * Attempt to create the directories along the specified path, except for | 650 | * Attempt to create the directories along the specified path, except for |
625 | * the final component. The mode is given for the final directory only, | 651 | * the final component. The mode is given for the final directory only, |
@@ -649,10 +675,15 @@ extern int createPath(const char *name, int mode) | |||
649 | } | 675 | } |
650 | return TRUE; | 676 | return TRUE; |
651 | } | 677 | } |
678 | #endif /* BB_TAR || BB_MKDIR */ | ||
652 | 679 | ||
653 | 680 | ||
654 | 681 | ||
682 | #if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR) | ||
655 | /* [ugoa]{+|-|=}[rwxst] */ | 683 | /* [ugoa]{+|-|=}[rwxst] */ |
684 | |||
685 | |||
686 | |||
656 | extern int parse_mode(const char *s, mode_t * theMode) | 687 | extern int parse_mode(const char *s, mode_t * theMode) |
657 | { | 688 | { |
658 | mode_t andMode = | 689 | mode_t andMode = |
@@ -745,9 +776,14 @@ extern int parse_mode(const char *s, mode_t * theMode) | |||
745 | } | 776 | } |
746 | 777 | ||
747 | 778 | ||
779 | #endif /* BB_CHMOD_CHOWN_CHGRP || BB_MKDIR */ | ||
780 | |||
781 | |||
748 | 782 | ||
749 | 783 | ||
750 | 784 | ||
785 | #if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS || defined BB_TAR || defined BB_ID | ||
786 | |||
751 | /* This parses entries in /etc/passwd and /etc/group. This is desirable | 787 | /* This parses entries in /etc/passwd and /etc/group. This is desirable |
752 | * for BusyBox, since we want to avoid using the glibc NSS stuff, which | 788 | * for BusyBox, since we want to avoid using the glibc NSS stuff, which |
753 | * increases target size and is often not needed or wanted for embedded | 789 | * increases target size and is often not needed or wanted for embedded |
@@ -852,6 +888,10 @@ gid_t my_getpwnamegid(char *name) | |||
852 | return gid; | 888 | return gid; |
853 | } | 889 | } |
854 | 890 | ||
891 | #endif /* BB_CHMOD_CHOWN_CHGRP || BB_PS || BB_LS || BB_TAR || BB_ID */ | ||
892 | |||
893 | |||
894 | #if (defined BB_CHVT) || (defined BB_DEALLOCVT) | ||
855 | 895 | ||
856 | 896 | ||
857 | #include <linux/kd.h> | 897 | #include <linux/kd.h> |
@@ -936,9 +976,11 @@ int get_console_fd(char *tty_name) | |||
936 | } | 976 | } |
937 | 977 | ||
938 | 978 | ||
979 | #endif /* BB_CHVT || BB_DEALLOCVT */ | ||
939 | 980 | ||
940 | 981 | ||
941 | #if !defined BB_REGEXP | 982 | #if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED) |
983 | |||
942 | /* Do a case insensitive strstr() */ | 984 | /* Do a case insensitive strstr() */ |
943 | char *stristr(char *haystack, const char *needle) | 985 | char *stristr(char *haystack, const char *needle) |
944 | { | 986 | { |
@@ -1009,9 +1051,11 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, | |||
1009 | else | 1051 | else |
1010 | return FALSE; | 1052 | return FALSE; |
1011 | } | 1053 | } |
1012 | #endif /* ! BB_REGEXP */ | 1054 | |
1055 | #endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */ | ||
1013 | 1056 | ||
1014 | 1057 | ||
1058 | #if defined BB_FIND | ||
1015 | /* | 1059 | /* |
1016 | * Routine to see if a text string is matched by a wildcard pattern. | 1060 | * Routine to see if a text string is matched by a wildcard pattern. |
1017 | * Returns TRUE if the text is matched, or FALSE if it is not matched | 1061 | * Returns TRUE if the text is matched, or FALSE if it is not matched |
@@ -1111,10 +1155,12 @@ extern int check_wildcard_match(const char *text, const char *pattern) | |||
1111 | 1155 | ||
1112 | return TRUE; | 1156 | return TRUE; |
1113 | } | 1157 | } |
1158 | #endif /* BB_FIND */ | ||
1114 | 1159 | ||
1115 | 1160 | ||
1116 | 1161 | ||
1117 | 1162 | ||
1163 | #if defined BB_DF || defined BB_MTAB | ||
1118 | /* | 1164 | /* |
1119 | * Given a block device, find the mount table entry if that block device | 1165 | * Given a block device, find the mount table entry if that block device |
1120 | * is mounted. | 1166 | * is mounted. |
@@ -1153,9 +1199,11 @@ extern struct mntent *findMountPoint(const char *name, const char *table) | |||
1153 | endmntent(mountTable); | 1199 | endmntent(mountTable); |
1154 | return mountEntry; | 1200 | return mountEntry; |
1155 | } | 1201 | } |
1202 | #endif /* BB_DF || BB_MTAB */ | ||
1156 | 1203 | ||
1157 | 1204 | ||
1158 | 1205 | ||
1206 | #if defined BB_DD || defined BB_TAIL | ||
1159 | /* | 1207 | /* |
1160 | * Read a number with a possible multiplier. | 1208 | * Read a number with a possible multiplier. |
1161 | * Returns -1 if the number format is illegal. | 1209 | * Returns -1 if the number format is illegal. |
@@ -1202,8 +1250,10 @@ extern long getNum(const char *cp) | |||
1202 | 1250 | ||
1203 | return value; | 1251 | return value; |
1204 | } | 1252 | } |
1253 | #endif /* BB_DD || BB_TAIL */ | ||
1205 | 1254 | ||
1206 | 1255 | ||
1256 | #if defined BB_INIT || defined BB_SYSLOGD | ||
1207 | /* try to open up the specified device */ | 1257 | /* try to open up the specified device */ |
1208 | extern int device_open(char *device, int mode) | 1258 | extern int device_open(char *device, int mode) |
1209 | { | 1259 | { |
@@ -1222,11 +1272,15 @@ extern int device_open(char *device, int mode) | |||
1222 | fcntl(fd, F_SETFL, mode); | 1272 | fcntl(fd, F_SETFL, mode); |
1223 | return fd; | 1273 | return fd; |
1224 | } | 1274 | } |
1275 | #endif /* BB_INIT BB_SYSLOGD */ | ||
1225 | 1276 | ||
1226 | 1277 | ||
1278 | #if defined BB_KILLALL || ( defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF )) | ||
1227 | #ifdef BB_FEATURE_USE_DEVPS_PATCH | 1279 | #ifdef BB_FEATURE_USE_DEVPS_PATCH |
1228 | #include <linux/devps.h> | 1280 | #include <linux/devps.h> |
1281 | #endif | ||
1229 | 1282 | ||
1283 | #if defined BB_FEATURE_USE_DEVPS_PATCH | ||
1230 | /* findPidByName() | 1284 | /* findPidByName() |
1231 | * | 1285 | * |
1232 | * This finds the pid of the specified process, | 1286 | * This finds the pid of the specified process, |
@@ -1365,6 +1419,7 @@ extern pid_t* findPidByName( char* pidName) | |||
1365 | return pidList; | 1419 | return pidList; |
1366 | } | 1420 | } |
1367 | #endif /* BB_FEATURE_USE_DEVPS_PATCH */ | 1421 | #endif /* BB_FEATURE_USE_DEVPS_PATCH */ |
1422 | #endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */ | ||
1368 | 1423 | ||
1369 | /* this should really be farmed out to libbusybox.a */ | 1424 | /* this should really be farmed out to libbusybox.a */ |
1370 | extern void *xmalloc(size_t size) | 1425 | extern void *xmalloc(size_t size) |
@@ -1376,7 +1431,7 @@ extern void *xmalloc(size_t size) | |||
1376 | return cp; | 1431 | return cp; |
1377 | } | 1432 | } |
1378 | 1433 | ||
1379 | #if (__GLIBC__ < 2) | 1434 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) |
1380 | extern int vdprintf(int d, const char *format, va_list ap) | 1435 | extern int vdprintf(int d, const char *format, va_list ap) |
1381 | { | 1436 | { |
1382 | char buf[BUF_SIZE]; | 1437 | char buf[BUF_SIZE]; |
@@ -1385,8 +1440,9 @@ extern int vdprintf(int d, const char *format, va_list ap) | |||
1385 | len = vsprintf(buf, format, ap); | 1440 | len = vsprintf(buf, format, ap); |
1386 | return write(d, buf, len); | 1441 | return write(d, buf, len); |
1387 | } | 1442 | } |
1388 | #endif | 1443 | #endif /* BB_SYSLOGD */ |
1389 | 1444 | ||
1445 | #if defined BB_FEATURE_MOUNT_LOOP | ||
1390 | extern int del_loop(const char *device) | 1446 | extern int del_loop(const char *device) |
1391 | { | 1447 | { |
1392 | int fd; | 1448 | int fd; |
@@ -1470,7 +1526,9 @@ extern char *find_unused_loop_device(void) | |||
1470 | } | 1526 | } |
1471 | return NULL; | 1527 | return NULL; |
1472 | } | 1528 | } |
1529 | #endif /* BB_FEATURE_MOUNT_LOOP */ | ||
1473 | 1530 | ||
1531 | #if defined BB_MOUNT || defined BB_DF || ( defined BB_UMOUNT && ! defined BB_MTAB) | ||
1474 | extern int find_real_root_device_name(char* name) | 1532 | extern int find_real_root_device_name(char* name) |
1475 | { | 1533 | { |
1476 | DIR *dir; | 1534 | DIR *dir; |
@@ -1512,6 +1570,7 @@ extern int find_real_root_device_name(char* name) | |||
1512 | 1570 | ||
1513 | return( FALSE); | 1571 | return( FALSE); |
1514 | } | 1572 | } |
1573 | #endif | ||
1515 | 1574 | ||
1516 | const unsigned int CSTRING_BUFFER_LENGTH = 128; | 1575 | const unsigned int CSTRING_BUFFER_LENGTH = 128; |
1517 | /* recursive parser that returns cstrings of arbitrary length | 1576 | /* recursive parser that returns cstrings of arbitrary length |