diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-25 20:30:24 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-25 20:30:24 +0000 |
| commit | 394eebed6656dfc2e56a79500b602023000ac415 (patch) | |
| tree | b5b5858663e7333b9624cb4f329e91ae649f3247 /libbb | |
| parent | 38b8831b3201a9e44cfb156b5b8577e4f5e8d761 (diff) | |
| download | busybox-w32-394eebed6656dfc2e56a79500b602023000ac415.tar.gz busybox-w32-394eebed6656dfc2e56a79500b602023000ac415.tar.bz2 busybox-w32-394eebed6656dfc2e56a79500b602023000ac415.zip | |
lpd: spool mode added by Vladimir
lpr: more robust error reporting
*: introduce and use xchroot
libbb: full_read/write now will report partial data counts prior to error
isdirectory.c: style fixes
lpd_main 249 486 +237
xchroot - 29 +29
get_response_or_say_and_die 110 139 +29
full_write 52 60 +8
full_read 55 63 +8
static.newline 1 - -1
switch_root_main 404 400 -4
chpst_main 1089 1079 -10
getopt32 1370 1359 -11
chroot_main 115 101 -14
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 4/4 up/down: 311/-40) Total: 271 bytes
text data bss dec hex filename
798472 728 7484 806684 c4f1c busybox_old
798775 728 7484 806987 c504b busybox_unstripped
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/full_write.c | 8 | ||||
| -rw-r--r-- | libbb/isdirectory.c | 11 | ||||
| -rw-r--r-- | libbb/read.c | 10 | ||||
| -rw-r--r-- | libbb/xfuncs.c | 6 |
4 files changed, 25 insertions, 10 deletions
diff --git a/libbb/full_write.c b/libbb/full_write.c index 7bbacb8ac..7503c8b42 100644 --- a/libbb/full_write.c +++ b/libbb/full_write.c | |||
| @@ -24,8 +24,14 @@ ssize_t full_write(int fd, const void *buf, size_t len) | |||
| 24 | while (len) { | 24 | while (len) { |
| 25 | cc = safe_write(fd, buf, len); | 25 | cc = safe_write(fd, buf, len); |
| 26 | 26 | ||
| 27 | if (cc < 0) | 27 | if (cc < 0) { |
| 28 | if (total) { | ||
| 29 | /* we already wrote some! */ | ||
| 30 | /* user can do another write to know the error code */ | ||
| 31 | return total; | ||
| 32 | } | ||
| 28 | return cc; /* write() returns -1 on failure. */ | 33 | return cc; /* write() returns -1 on failure. */ |
| 34 | } | ||
| 29 | 35 | ||
| 30 | total += cc; | 36 | total += cc; |
| 31 | buf = ((const char *)buf) + cc; | 37 | buf = ((const char *)buf) + cc; |
diff --git a/libbb/isdirectory.c b/libbb/isdirectory.c index b35919869..1d2477f47 100644 --- a/libbb/isdirectory.c +++ b/libbb/isdirectory.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "libbb.h" | 12 | #include "libbb.h" |
| 13 | 13 | ||
| 14 | /* | 14 | /* |
| 15 | * Return TRUE if a fileName is a directory. | 15 | * Return TRUE if fileName is a directory. |
| 16 | * Nonexistent files return FALSE. | 16 | * Nonexistent files return FALSE. |
| 17 | */ | 17 | */ |
| 18 | int is_directory(const char *fileName, const int followLinks, struct stat *statBuf) | 18 | int is_directory(const char *fileName, const int followLinks, struct stat *statBuf) |
| @@ -21,8 +21,8 @@ int is_directory(const char *fileName, const int followLinks, struct stat *statB | |||
| 21 | struct stat astatBuf; | 21 | struct stat astatBuf; |
| 22 | 22 | ||
| 23 | if (statBuf == NULL) { | 23 | if (statBuf == NULL) { |
| 24 | /* set from auto stack buffer */ | 24 | /* use auto stack buffer */ |
| 25 | statBuf = &astatBuf; | 25 | statBuf = &astatBuf; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | if (followLinks) | 28 | if (followLinks) |
| @@ -30,10 +30,7 @@ int is_directory(const char *fileName, const int followLinks, struct stat *statB | |||
| 30 | else | 30 | else |
| 31 | status = lstat(fileName, statBuf); | 31 | status = lstat(fileName, statBuf); |
| 32 | 32 | ||
| 33 | if (status < 0 || !(S_ISDIR(statBuf->st_mode))) { | 33 | status = (status == 0 && S_ISDIR(statBuf->st_mode)); |
| 34 | status = FALSE; | ||
| 35 | } | ||
| 36 | else status = TRUE; | ||
| 37 | 34 | ||
| 38 | return status; | 35 | return status; |
| 39 | } | 36 | } |
diff --git a/libbb/read.c b/libbb/read.c index 4ad41d589..575446536 100644 --- a/libbb/read.c +++ b/libbb/read.c | |||
| @@ -88,8 +88,14 @@ ssize_t full_read(int fd, void *buf, size_t len) | |||
| 88 | while (len) { | 88 | while (len) { |
| 89 | cc = safe_read(fd, buf, len); | 89 | cc = safe_read(fd, buf, len); |
| 90 | 90 | ||
| 91 | if (cc < 0) | 91 | if (cc < 0) { |
| 92 | return cc; /* read() returns -1 on failure. */ | 92 | if (total) { |
| 93 | /* we already have some! */ | ||
| 94 | /* user can do another read to know the error code */ | ||
| 95 | return total; | ||
| 96 | } | ||
| 97 | return cc; /* read() returns -1 on failure. */ | ||
| 98 | } | ||
| 93 | if (cc == 0) | 99 | if (cc == 0) |
| 94 | break; | 100 | break; |
| 95 | buf = ((char *)buf) + cc; | 101 | buf = ((char *)buf) + cc; |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 17760a3c3..18e696a7a 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
| @@ -577,6 +577,12 @@ void xchdir(const char *path) | |||
| 577 | bb_perror_msg_and_die("chdir(%s)", path); | 577 | bb_perror_msg_and_die("chdir(%s)", path); |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | void xchroot(const char *path) | ||
| 581 | { | ||
| 582 | if (chroot(path)) | ||
| 583 | bb_perror_msg_and_die("can't change root directory to %s", path); | ||
| 584 | } | ||
| 585 | |||
| 580 | // Print a warning message if opendir() fails, but don't die. | 586 | // Print a warning message if opendir() fails, but don't die. |
| 581 | DIR *warn_opendir(const char *path) | 587 | DIR *warn_opendir(const char *path) |
| 582 | { | 588 | { |
