aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c106
1 files changed, 53 insertions, 53 deletions
diff --git a/utility.c b/utility.c
index 554ad1b88..2f3486c13 100644
--- a/utility.c
+++ b/utility.c
@@ -33,7 +33,7 @@
33 || defined (BB_LS) \ 33 || defined (BB_LS) \
34 || defined (BB_RM) \ 34 || defined (BB_RM) \
35 || defined (BB_TAR) 35 || defined (BB_TAR)
36/* same conditions as recursiveAction */ 36/* same conditions as recursive_action */
37#define bb_need_name_too_long 37#define bb_need_name_too_long
38#endif 38#endif
39#define bb_need_memory_exhausted 39#define bb_need_memory_exhausted
@@ -84,7 +84,7 @@ extern void usage(const char *usage)
84 exit(EXIT_FAILURE); 84 exit(EXIT_FAILURE);
85} 85}
86 86
87static void verrorMsg(const char *s, va_list p) 87static void verror_msg(const char *s, va_list p)
88{ 88{
89 fflush(stdout); 89 fflush(stdout);
90 fprintf(stderr, "%s: ", applet_name); 90 fprintf(stderr, "%s: ", applet_name);
@@ -92,26 +92,26 @@ static void verrorMsg(const char *s, va_list p)
92 fflush(stderr); 92 fflush(stderr);
93} 93}
94 94
95extern void errorMsg(const char *s, ...) 95extern void error_msg(const char *s, ...)
96{ 96{
97 va_list p; 97 va_list p;
98 98
99 va_start(p, s); 99 va_start(p, s);
100 verrorMsg(s, p); 100 verror_msg(s, p);
101 va_end(p); 101 va_end(p);
102} 102}
103 103
104extern void fatalError(const char *s, ...) 104extern void error_msg_and_die(const char *s, ...)
105{ 105{
106 va_list p; 106 va_list p;
107 107
108 va_start(p, s); 108 va_start(p, s);
109 verrorMsg(s, p); 109 verror_msg(s, p);
110 va_end(p); 110 va_end(p);
111 exit(EXIT_FAILURE); 111 exit(EXIT_FAILURE);
112} 112}
113 113
114static void vperrorMsg(const char *s, va_list p) 114static void vperror_msg(const char *s, va_list p)
115{ 115{
116 fflush(stdout); 116 fflush(stdout);
117 fprintf(stderr, "%s: ", applet_name); 117 fprintf(stderr, "%s: ", applet_name);
@@ -123,21 +123,21 @@ static void vperrorMsg(const char *s, va_list p)
123 fflush(stderr); 123 fflush(stderr);
124} 124}
125 125
126extern void perrorMsg(const char *s, ...) 126extern void perror_msg(const char *s, ...)
127{ 127{
128 va_list p; 128 va_list p;
129 129
130 va_start(p, s); 130 va_start(p, s);
131 vperrorMsg(s, p); 131 vperror_msg(s, p);
132 va_end(p); 132 va_end(p);
133} 133}
134 134
135extern void fatalPerror(const char *s, ...) 135extern void perror_msg_and_die(const char *s, ...)
136{ 136{
137 va_list p; 137 va_list p;
138 138
139 va_start(p, s); 139 va_start(p, s);
140 vperrorMsg(s, p); 140 vperror_msg(s, p);
141 va_end(p); 141 va_end(p);
142 exit(EXIT_FAILURE); 142 exit(EXIT_FAILURE);
143} 143}
@@ -266,7 +266,7 @@ void reset_ino_dev_hashtable(void)
266 * Return TRUE if a fileName is a directory. 266 * Return TRUE if a fileName is a directory.
267 * Nonexistant files return FALSE. 267 * Nonexistant files return FALSE.
268 */ 268 */
269int isDirectory(const char *fileName, const int followLinks, struct stat *statBuf) 269int is_directory(const char *fileName, const int followLinks, struct stat *statBuf)
270{ 270{
271 int status; 271 int status;
272 int didMalloc = 0; 272 int didMalloc = 0;
@@ -308,7 +308,7 @@ int copy_file_chunk(int srcfd, int dstfd, size_t chunksize)
308 size = BUFSIZ; 308 size = BUFSIZ;
309 else 309 else
310 size = chunksize; 310 size = chunksize;
311 if (fullWrite(dstfd, buffer, fullRead(srcfd, buffer, size)) < size) 311 if (full_write(dstfd, buffer, full_read(srcfd, buffer, size)) < size)
312 return(FALSE); 312 return(FALSE);
313 chunksize -= size; 313 chunksize -= size;
314 } 314 }
@@ -325,7 +325,7 @@ int copy_file_chunk(int srcfd, int dstfd, size_t chunksize)
325 * -Erik Andersen 325 * -Erik Andersen
326 */ 326 */
327int 327int
328copyFile(const char *srcName, const char *destName, 328copy_file(const char *srcName, const char *destName,
329 int setModes, int followLinks, int forceFlag) 329 int setModes, int followLinks, int forceFlag)
330{ 330{
331 int rfd; 331 int rfd;
@@ -358,7 +358,7 @@ copyFile(const char *srcName, const char *destName,
358 358
359 if ((srcStatBuf.st_dev == dstStatBuf.st_dev) && 359 if ((srcStatBuf.st_dev == dstStatBuf.st_dev) &&
360 (srcStatBuf.st_ino == dstStatBuf.st_ino)) { 360 (srcStatBuf.st_ino == dstStatBuf.st_ino)) {
361 errorMsg("Copying file \"%s\" to itself\n", srcName); 361 error_msg("Copying file \"%s\" to itself\n", srcName);
362 return FALSE; 362 return FALSE;
363 } 363 }
364 364
@@ -491,7 +491,7 @@ static const char SMODE0[] = "..S..S..T";
491 * Return the standard ls-like mode string from a file mode. 491 * Return the standard ls-like mode string from a file mode.
492 * This is static and so is overwritten on each call. 492 * This is static and so is overwritten on each call.
493 */ 493 */
494const char *modeString(int mode) 494const char *mode_string(int mode)
495{ 495{
496 static char buf[12]; 496 static char buf[12];
497 497
@@ -514,7 +514,7 @@ const char *modeString(int mode)
514 * Return the standard ls-like time string from a time_t 514 * Return the standard ls-like time string from a time_t
515 * This is static and so is overwritten on each call. 515 * This is static and so is overwritten on each call.
516 */ 516 */
517const char *timeString(time_t timeVal) 517const char *time_string(time_t timeVal)
518{ 518{
519 time_t now; 519 time_t now;
520 char *str; 520 char *str;
@@ -542,7 +542,7 @@ const char *timeString(time_t timeVal)
542 * This does multiple writes as necessary. 542 * This does multiple writes as necessary.
543 * Returns the amount written, or -1 on an error. 543 * Returns the amount written, or -1 on an error.
544 */ 544 */
545int fullWrite(int fd, const char *buf, int len) 545int full_write(int fd, const char *buf, int len)
546{ 546{
547 int cc; 547 int cc;
548 int total; 548 int total;
@@ -572,7 +572,7 @@ int fullWrite(int fd, const char *buf, int len)
572 * Returns the amount read, or -1 on an error. 572 * Returns the amount read, or -1 on an error.
573 * A short read is returned on an end of file. 573 * A short read is returned on an end of file.
574 */ 574 */
575int fullRead(int fd, char *buf, int len) 575int full_read(int fd, char *buf, int len)
576{ 576{
577 int cc; 577 int cc;
578 int total; 578 int total;
@@ -616,7 +616,7 @@ int fullRead(int fd, char *buf, int len)
616 * and so isn't sufficiently portable to take over since glibc2.1 616 * and so isn't sufficiently portable to take over since glibc2.1
617 * is so stinking huge. 617 * is so stinking huge.
618 */ 618 */
619int recursiveAction(const char *fileName, 619int recursive_action(const char *fileName,
620 int recurse, int followLinks, int depthFirst, 620 int recurse, int followLinks, int depthFirst,
621 int (*fileAction) (const char *fileName, 621 int (*fileAction) (const char *fileName,
622 struct stat * statbuf, 622 struct stat * statbuf,
@@ -641,7 +641,7 @@ int recursiveAction(const char *fileName,
641 "status=%d followLinks=%d TRUE=%d\n", 641 "status=%d followLinks=%d TRUE=%d\n",
642 status, followLinks, TRUE); 642 status, followLinks, TRUE);
643#endif 643#endif
644 perrorMsg("%s", fileName); 644 perror_msg("%s", fileName);
645 return FALSE; 645 return FALSE;
646 } 646 }
647 647
@@ -666,13 +666,13 @@ int recursiveAction(const char *fileName,
666 666
667 dir = opendir(fileName); 667 dir = opendir(fileName);
668 if (!dir) { 668 if (!dir) {
669 perrorMsg("%s", fileName); 669 perror_msg("%s", fileName);
670 return FALSE; 670 return FALSE;
671 } 671 }
672 if (dirAction != NULL && depthFirst == FALSE) { 672 if (dirAction != NULL && depthFirst == FALSE) {
673 status = dirAction(fileName, &statbuf, userData); 673 status = dirAction(fileName, &statbuf, userData);
674 if (status == FALSE) { 674 if (status == FALSE) {
675 perrorMsg("%s", fileName); 675 perror_msg("%s", fileName);
676 return FALSE; 676 return FALSE;
677 } 677 }
678 } 678 }
@@ -684,13 +684,13 @@ int recursiveAction(const char *fileName,
684 continue; 684 continue;
685 } 685 }
686 if (strlen(fileName) + strlen(next->d_name) + 1 > BUFSIZ) { 686 if (strlen(fileName) + strlen(next->d_name) + 1 > BUFSIZ) {
687 errorMsg(name_too_long); 687 error_msg(name_too_long);
688 return FALSE; 688 return FALSE;
689 } 689 }
690 memset(nextFile, 0, sizeof(nextFile)); 690 memset(nextFile, 0, sizeof(nextFile));
691 sprintf(nextFile, "%s/%s", fileName, next->d_name); 691 sprintf(nextFile, "%s/%s", fileName, next->d_name);
692 status = 692 status =
693 recursiveAction(nextFile, TRUE, followLinks, depthFirst, 693 recursive_action(nextFile, TRUE, followLinks, depthFirst,
694 fileAction, dirAction, userData); 694 fileAction, dirAction, userData);
695 if (status == FALSE) { 695 if (status == FALSE) {
696 closedir(dir); 696 closedir(dir);
@@ -699,13 +699,13 @@ int recursiveAction(const char *fileName,
699 } 699 }
700 status = closedir(dir); 700 status = closedir(dir);
701 if (status < 0) { 701 if (status < 0) {
702 perrorMsg("%s", fileName); 702 perror_msg("%s", fileName);
703 return FALSE; 703 return FALSE;
704 } 704 }
705 if (dirAction != NULL && depthFirst == TRUE) { 705 if (dirAction != NULL && depthFirst == TRUE) {
706 status = dirAction(fileName, &statbuf, userData); 706 status = dirAction(fileName, &statbuf, userData);
707 if (status == FALSE) { 707 if (status == FALSE) {
708 perrorMsg("%s", fileName); 708 perror_msg("%s", fileName);
709 return FALSE; 709 return FALSE;
710 } 710 }
711 } 711 }
@@ -729,7 +729,7 @@ int recursiveAction(const char *fileName,
729 * while all previous ones get default protections. Errors are not reported 729 * while all previous ones get default protections. Errors are not reported
730 * here, as failures to restore files can be reported later. 730 * here, as failures to restore files can be reported later.
731 */ 731 */
732extern int createPath(const char *name, int mode) 732extern int create_path(const char *name, int mode)
733{ 733{
734 char *cp; 734 char *cp;
735 char *cpOld; 735 char *cpOld;
@@ -1058,7 +1058,7 @@ int get_console_fd(char *tty_name)
1058 if (is_a_console(fd)) 1058 if (is_a_console(fd))
1059 return fd; 1059 return fd;
1060 1060
1061 errorMsg("Couldnt get a file descriptor referring to the console\n"); 1061 error_msg("Couldnt get a file descriptor referring to the console\n");
1062 return -1; /* total failure */ 1062 return -1; /* total failure */
1063} 1063}
1064 1064
@@ -1179,7 +1179,7 @@ extern int check_wildcard_match(const char *text, const char *pattern)
1179 * Given any other file (or directory), find the mount table entry for its 1179 * Given any other file (or directory), find the mount table entry for its
1180 * filesystem. 1180 * filesystem.
1181 */ 1181 */
1182extern struct mntent *findMountPoint(const char *name, const char *table) 1182extern struct mntent *find_mount_point(const char *name, const char *table)
1183{ 1183{
1184 struct stat s; 1184 struct stat s;
1185 dev_t mountDevice; 1185 dev_t mountDevice;
@@ -1219,16 +1219,16 @@ extern struct mntent *findMountPoint(const char *name, const char *table)
1219 * Read a number with a possible multiplier. 1219 * Read a number with a possible multiplier.
1220 * Returns -1 if the number format is illegal. 1220 * Returns -1 if the number format is illegal.
1221 */ 1221 */
1222extern long getNum(const char *cp) 1222extern long atoi_w_units(const char *cp)
1223{ 1223{
1224 long value; 1224 long value;
1225 1225
1226 if (!isDecimal(*cp)) 1226 if (!is_decimal(*cp))
1227 return -1; 1227 return -1;
1228 1228
1229 value = 0; 1229 value = 0;
1230 1230
1231 while (isDecimal(*cp)) 1231 while (is_decimal(*cp))
1232 value = value * 10 + *cp++ - '0'; 1232 value = value * 10 + *cp++ - '0';
1233 1233
1234 switch (*cp++) { 1234 switch (*cp++) {
@@ -1292,14 +1292,14 @@ extern int device_open(char *device, int mode)
1292#endif 1292#endif
1293 1293
1294#if defined BB_FEATURE_USE_DEVPS_PATCH 1294#if defined BB_FEATURE_USE_DEVPS_PATCH
1295/* findPidByName() 1295/* find_pid_by_name()
1296 * 1296 *
1297 * This finds the pid of the specified process, 1297 * This finds the pid of the specified process,
1298 * by using the /dev/ps device driver. 1298 * by using the /dev/ps device driver.
1299 * 1299 *
1300 * Returns a list of all matching PIDs 1300 * Returns a list of all matching PIDs
1301 */ 1301 */
1302extern pid_t* findPidByName( char* pidName) 1302extern pid_t* find_pid_by_name( char* pidName)
1303{ 1303{
1304 int fd, i, j; 1304 int fd, i, j;
1305 char device[] = "/dev/ps"; 1305 char device[] = "/dev/ps";
@@ -1310,11 +1310,11 @@ extern pid_t* findPidByName( char* pidName)
1310 /* open device */ 1310 /* open device */
1311 fd = open(device, O_RDONLY); 1311 fd = open(device, O_RDONLY);
1312 if (fd < 0) 1312 if (fd < 0)
1313 fatalError( "open failed for `%s': %s\n", device, strerror (errno)); 1313 error_msg_and_die( "open failed for `%s': %s\n", device, strerror (errno));
1314 1314
1315 /* Find out how many processes there are */ 1315 /* Find out how many processes there are */
1316 if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0) 1316 if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0)
1317 fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); 1317 error_msg_and_die( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
1318 1318
1319 /* Allocate some memory -- grab a few extras just in case 1319 /* Allocate some memory -- grab a few extras just in case
1320 * some new processes start up while we wait. The kernel will 1320 * some new processes start up while we wait. The kernel will
@@ -1325,7 +1325,7 @@ extern pid_t* findPidByName( char* pidName)
1325 1325
1326 /* Now grab the pid list */ 1326 /* Now grab the pid list */
1327 if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0) 1327 if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0)
1328 fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); 1328 error_msg_and_die( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno));
1329 1329
1330 /* Now search for a match */ 1330 /* Now search for a match */
1331 for (i=1, j=0; i<pid_array[0] ; i++) { 1331 for (i=1, j=0; i<pid_array[0] ; i++) {
@@ -1334,7 +1334,7 @@ extern pid_t* findPidByName( char* pidName)
1334 1334
1335 info.pid = pid_array[i]; 1335 info.pid = pid_array[i];
1336 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) 1336 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
1337 fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno)); 1337 error_msg_and_die( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
1338 1338
1339 /* Make sure we only match on the process name */ 1339 /* Make sure we only match on the process name */
1340 p=info.command_line+1; 1340 p=info.command_line+1;
@@ -1358,7 +1358,7 @@ extern pid_t* findPidByName( char* pidName)
1358 1358
1359 /* close device */ 1359 /* close device */
1360 if (close (fd) != 0) 1360 if (close (fd) != 0)
1361 fatalError( "close failed for `%s': %s\n",device, strerror (errno)); 1361 error_msg_and_die( "close failed for `%s': %s\n",device, strerror (errno));
1362 1362
1363 return pidList; 1363 return pidList;
1364} 1364}
@@ -1367,7 +1367,7 @@ extern pid_t* findPidByName( char* pidName)
1367#error Sorry, I depend on the /proc filesystem right now. 1367#error Sorry, I depend on the /proc filesystem right now.
1368#endif 1368#endif
1369 1369
1370/* findPidByName() 1370/* find_pid_by_name()
1371 * 1371 *
1372 * This finds the pid of the specified process. 1372 * This finds the pid of the specified process.
1373 * Currently, it's implemented by rummaging through 1373 * Currently, it's implemented by rummaging through
@@ -1375,7 +1375,7 @@ extern pid_t* findPidByName( char* pidName)
1375 * 1375 *
1376 * Returns a list of all matching PIDs 1376 * Returns a list of all matching PIDs
1377 */ 1377 */
1378extern pid_t* findPidByName( char* pidName) 1378extern pid_t* find_pid_by_name( char* pidName)
1379{ 1379{
1380 DIR *dir; 1380 DIR *dir;
1381 struct dirent *next; 1381 struct dirent *next;
@@ -1384,7 +1384,7 @@ extern pid_t* findPidByName( char* pidName)
1384 1384
1385 dir = opendir("/proc"); 1385 dir = opendir("/proc");
1386 if (!dir) 1386 if (!dir)
1387 fatalError( "Cannot open /proc: %s\n", strerror (errno)); 1387 error_msg_and_die( "Cannot open /proc: %s\n", strerror (errno));
1388 1388
1389 while ((next = readdir(dir)) != NULL) { 1389 while ((next = readdir(dir)) != NULL) {
1390 FILE *status; 1390 FILE *status;
@@ -1423,7 +1423,7 @@ extern void *xmalloc(size_t size)
1423 void *ptr = malloc(size); 1423 void *ptr = malloc(size);
1424 1424
1425 if (!ptr) 1425 if (!ptr)
1426 fatalError(memory_exhausted); 1426 error_msg_and_die(memory_exhausted);
1427 return ptr; 1427 return ptr;
1428} 1428}
1429 1429
@@ -1431,7 +1431,7 @@ extern void *xrealloc(void *old, size_t size)
1431{ 1431{
1432 void *ptr = realloc(old, size); 1432 void *ptr = realloc(old, size);
1433 if (!ptr) 1433 if (!ptr)
1434 fatalError(memory_exhausted); 1434 error_msg_and_die(memory_exhausted);
1435 return ptr; 1435 return ptr;
1436} 1436}
1437 1437
@@ -1439,7 +1439,7 @@ extern void *xcalloc(size_t nmemb, size_t size)
1439{ 1439{
1440 void *ptr = calloc(nmemb, size); 1440 void *ptr = calloc(nmemb, size);
1441 if (!ptr) 1441 if (!ptr)
1442 fatalError(memory_exhausted); 1442 error_msg_and_die(memory_exhausted);
1443 return ptr; 1443 return ptr;
1444} 1444}
1445#endif 1445#endif
@@ -1455,7 +1455,7 @@ extern char * xstrdup (const char *s) {
1455 t = strdup (s); 1455 t = strdup (s);
1456 1456
1457 if (t == NULL) 1457 if (t == NULL)
1458 fatalError(memory_exhausted); 1458 error_msg_and_die(memory_exhausted);
1459 1459
1460 return t; 1460 return t;
1461} 1461}
@@ -1467,7 +1467,7 @@ extern char * xstrndup (const char *s, int n) {
1467 char *t; 1467 char *t;
1468 1468
1469 if (s == NULL) 1469 if (s == NULL)
1470 fatalError("xstrndup bug"); 1470 error_msg_and_die("xstrndup bug");
1471 1471
1472 t = xmalloc(n+1); 1472 t = xmalloc(n+1);
1473 strncpy(t,s,n); 1473 strncpy(t,s,n);
@@ -1588,13 +1588,13 @@ extern int find_real_root_device_name(char* name)
1588 char fileName[BUFSIZ]; 1588 char fileName[BUFSIZ];
1589 1589
1590 if (stat("/", &rootStat) != 0) { 1590 if (stat("/", &rootStat) != 0) {
1591 errorMsg("could not stat '/'\n"); 1591 error_msg("could not stat '/'\n");
1592 return( FALSE); 1592 return( FALSE);
1593 } 1593 }
1594 1594
1595 dir = opendir("/dev"); 1595 dir = opendir("/dev");
1596 if (!dir) { 1596 if (!dir) {
1597 errorMsg("could not open '/dev'\n"); 1597 error_msg("could not open '/dev'\n");
1598 return( FALSE); 1598 return( FALSE);
1599 } 1599 }
1600 1600
@@ -1749,7 +1749,7 @@ void xregcomp(regex_t *preg, const char *regex, int cflags)
1749 int errmsgsz = regerror(ret, preg, NULL, 0); 1749 int errmsgsz = regerror(ret, preg, NULL, 0);
1750 char *errmsg = xmalloc(errmsgsz); 1750 char *errmsg = xmalloc(errmsgsz);
1751 regerror(ret, preg, errmsg, errmsgsz); 1751 regerror(ret, preg, errmsg, errmsgsz);
1752 fatalError("xregcomp: %s\n", errmsg); 1752 error_msg_and_die("xregcomp: %s\n", errmsg);
1753 } 1753 }
1754} 1754}
1755#endif 1755#endif
@@ -1759,7 +1759,7 @@ FILE *wfopen(const char *path, const char *mode)
1759{ 1759{
1760 FILE *fp; 1760 FILE *fp;
1761 if ((fp = fopen(path, mode)) == NULL) { 1761 if ((fp = fopen(path, mode)) == NULL) {
1762 errorMsg("%s: %s\n", path, strerror(errno)); 1762 error_msg("%s: %s\n", path, strerror(errno));
1763 errno = 0; 1763 errno = 0;
1764 } 1764 }
1765 return fp; 1765 return fp;
@@ -1773,7 +1773,7 @@ FILE *xfopen(const char *path, const char *mode)
1773{ 1773{
1774 FILE *fp; 1774 FILE *fp;
1775 if ((fp = fopen(path, mode)) == NULL) 1775 if ((fp = fopen(path, mode)) == NULL)
1776 fatalError("%s: %s\n", path, strerror(errno)); 1776 error_msg_and_die("%s: %s\n", path, strerror(errno));
1777 return fp; 1777 return fp;
1778} 1778}
1779#endif 1779#endif