aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-12-22 01:48:07 +0000
committerMatt Kraai <kraai@debian.org>2000-12-22 01:48:07 +0000
commita9819b290848e0a760f3805d5937fa050235d707 (patch)
treeb8cb8d939032c0806d62161b01e5836cb808dc3f /utility.c
parente9f07fb6e83b75a50760599a5d31f494841eddf7 (diff)
downloadbusybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.gz
busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.bz2
busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.zip
Use busybox error handling functions wherever possible.
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/utility.c b/utility.c
index b06abf464..f22251895 100644
--- a/utility.c
+++ b/utility.c
@@ -153,7 +153,7 @@ extern int get_kernel_revision(void)
153 int major = 0, minor = 0, patch = 0; 153 int major = 0, minor = 0, patch = 0;
154 154
155 if (uname(&name) == -1) { 155 if (uname(&name) == -1) {
156 perror("cannot get system information"); 156 perror_msg("cannot get system information");
157 return (0); 157 return (0);
158 } 158 }
159 major = atoi(strtok(name.release, ".")); 159 major = atoi(strtok(name.release, "."));
@@ -341,7 +341,7 @@ copy_file(const char *srcName, const char *destName,
341 status = lstat(srcName, &srcStatBuf); 341 status = lstat(srcName, &srcStatBuf);
342 342
343 if (status < 0) { 343 if (status < 0) {
344 perror(srcName); 344 perror_msg("%s", srcName);
345 return FALSE; 345 return FALSE;
346 } 346 }
347 347
@@ -367,7 +367,7 @@ copy_file(const char *srcName, const char *destName,
367 /* Make sure the directory is writable */ 367 /* Make sure the directory is writable */
368 status = mkdir(destName, 0777777 ^ umask(0)); 368 status = mkdir(destName, 0777777 ^ umask(0));
369 if (status < 0 && errno != EEXIST) { 369 if (status < 0 && errno != EEXIST) {
370 perror(destName); 370 perror_msg("%s", destName);
371 return FALSE; 371 return FALSE;
372 } 372 }
373 } else if (S_ISLNK(srcStatBuf.st_mode)) { 373 } else if (S_ISLNK(srcStatBuf.st_mode)) {
@@ -378,13 +378,13 @@ copy_file(const char *srcName, const char *destName,
378 /* Warning: This could possibly truncate silently, to BUFSIZ chars */ 378 /* Warning: This could possibly truncate silently, to BUFSIZ chars */
379 link_size = readlink(srcName, &link_val[0], BUFSIZ); 379 link_size = readlink(srcName, &link_val[0], BUFSIZ);
380 if (link_size < 0) { 380 if (link_size < 0) {
381 perror(srcName); 381 perror_msg("%s", srcName);
382 return FALSE; 382 return FALSE;
383 } 383 }
384 link_val[link_size] = '\0'; 384 link_val[link_size] = '\0';
385 status = symlink(link_val, destName); 385 status = symlink(link_val, destName);
386 if (status < 0) { 386 if (status < 0) {
387 perror(destName); 387 perror_msg("%s", destName);
388 return FALSE; 388 return FALSE;
389 } 389 }
390#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) 390#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
@@ -397,28 +397,28 @@ copy_file(const char *srcName, const char *destName,
397 } else if (S_ISFIFO(srcStatBuf.st_mode)) { 397 } else if (S_ISFIFO(srcStatBuf.st_mode)) {
398 //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); 398 //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName);
399 if (mkfifo(destName, 0644) < 0) { 399 if (mkfifo(destName, 0644) < 0) {
400 perror(destName); 400 perror_msg("%s", destName);
401 return FALSE; 401 return FALSE;
402 } 402 }
403 } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode) 403 } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode)
404 || S_ISSOCK(srcStatBuf.st_mode)) { 404 || S_ISSOCK(srcStatBuf.st_mode)) {
405 //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName); 405 //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName);
406 if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) { 406 if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) {
407 perror(destName); 407 perror_msg("%s", destName);
408 return FALSE; 408 return FALSE;
409 } 409 }
410 } else if (S_ISREG(srcStatBuf.st_mode)) { 410 } else if (S_ISREG(srcStatBuf.st_mode)) {
411 //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName); 411 //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName);
412 rfd = open(srcName, O_RDONLY); 412 rfd = open(srcName, O_RDONLY);
413 if (rfd < 0) { 413 if (rfd < 0) {
414 perror(srcName); 414 perror_msg("%s", srcName);
415 return FALSE; 415 return FALSE;
416 } 416 }
417 417
418 wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC, 418 wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC,
419 srcStatBuf.st_mode); 419 srcStatBuf.st_mode);
420 if (wfd < 0) { 420 if (wfd < 0) {
421 perror(destName); 421 perror_msg("%s", destName);
422 close(rfd); 422 close(rfd);
423 return FALSE; 423 return FALSE;
424 } 424 }
@@ -434,26 +434,20 @@ copy_file(const char *srcName, const char *destName,
434 434
435 if (setModes == TRUE) { 435 if (setModes == TRUE) {
436 /* This is fine, since symlinks never get here */ 436 /* This is fine, since symlinks never get here */
437 if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) { 437 if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0)
438 perror(destName); 438 perror_msg_and_die("%s", destName);
439 exit(EXIT_FAILURE); 439 if (chmod(destName, srcStatBuf.st_mode) < 0)
440 } 440 perror_msg_and_die("%s", destName);
441 if (chmod(destName, srcStatBuf.st_mode) < 0) {
442 perror(destName);
443 exit(EXIT_FAILURE);
444 }
445 times.actime = srcStatBuf.st_atime; 441 times.actime = srcStatBuf.st_atime;
446 times.modtime = srcStatBuf.st_mtime; 442 times.modtime = srcStatBuf.st_mtime;
447 if (utime(destName, &times) < 0) { 443 if (utime(destName, &times) < 0)
448 perror(destName); 444 perror_msg_and_die("%s", destName);
449 exit(EXIT_FAILURE);
450 }
451 } 445 }
452 446
453 return TRUE; 447 return TRUE;
454 448
455 error_exit: 449 error_exit:
456 perror(destName); 450 perror_msg("%s", destName);
457 close(rfd); 451 close(rfd);
458 close(wfd); 452 close(wfd);
459 453
@@ -745,7 +739,7 @@ extern int create_path(const char *name, int mode)
745 *cpOld = '\0'; 739 *cpOld = '\0';
746 retVal = mkdir(buf, cp ? 0777 : mode); 740 retVal = mkdir(buf, cp ? 0777 : mode);
747 if (retVal != 0 && errno != EEXIST) { 741 if (retVal != 0 && errno != EEXIST) {
748 perror(buf); 742 perror_msg("%s", buf);
749 return FALSE; 743 return FALSE;
750 } 744 }
751 *cpOld = '/'; 745 *cpOld = '/';
@@ -1450,11 +1444,11 @@ extern int del_loop(const char *device)
1450 int fd; 1444 int fd;
1451 1445
1452 if ((fd = open(device, O_RDONLY)) < 0) { 1446 if ((fd = open(device, O_RDONLY)) < 0) {
1453 perror(device); 1447 perror_msg("%s", device);
1454 return (FALSE); 1448 return (FALSE);
1455 } 1449 }
1456 if (ioctl(fd, LOOP_CLR_FD, 0) < 0) { 1450 if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
1457 perror("ioctl: LOOP_CLR_FD"); 1451 perror_msg("ioctl: LOOP_CLR_FD");
1458 return (FALSE); 1452 return (FALSE);
1459 } 1453 }
1460 close(fd); 1454 close(fd);
@@ -1470,12 +1464,12 @@ extern int set_loop(const char *device, const char *file, int offset,
1470 mode = *loopro ? O_RDONLY : O_RDWR; 1464 mode = *loopro ? O_RDONLY : O_RDWR;
1471 if ((ffd = open(file, mode)) < 0 && !*loopro 1465 if ((ffd = open(file, mode)) < 0 && !*loopro
1472 && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) { 1466 && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) {
1473 perror(file); 1467 perror_msg("%s", file);
1474 return 1; 1468 return 1;
1475 } 1469 }
1476 if ((fd = open(device, mode)) < 0) { 1470 if ((fd = open(device, mode)) < 0) {
1477 close(ffd); 1471 close(ffd);
1478 perror(device); 1472 perror_msg("%s", device);
1479 return 1; 1473 return 1;
1480 } 1474 }
1481 *loopro = (mode == O_RDONLY); 1475 *loopro = (mode == O_RDONLY);
@@ -1488,14 +1482,14 @@ extern int set_loop(const char *device, const char *file, int offset,
1488 1482
1489 loopinfo.lo_encrypt_key_size = 0; 1483 loopinfo.lo_encrypt_key_size = 0;
1490 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { 1484 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
1491 perror("ioctl: LOOP_SET_FD"); 1485 perror_msg("ioctl: LOOP_SET_FD");
1492 close(fd); 1486 close(fd);
1493 close(ffd); 1487 close(ffd);
1494 return 1; 1488 return 1;
1495 } 1489 }
1496 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { 1490 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
1497 (void) ioctl(fd, LOOP_CLR_FD, 0); 1491 (void) ioctl(fd, LOOP_CLR_FD, 0);
1498 perror("ioctl: LOOP_SET_STATUS"); 1492 perror_msg("ioctl: LOOP_SET_STATUS");
1499 close(fd); 1493 close(fd);
1500 close(ffd); 1494 close(ffd);
1501 return 1; 1495 return 1;