aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/full_write.c8
-rw-r--r--libbb/isdirectory.c11
-rw-r--r--libbb/read.c10
-rw-r--r--libbb/xfuncs.c6
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)
while (len) {
cc = safe_write(fd, buf, len);
- if (cc < 0)
+ if (cc < 0) {
+ if (total) {
+ /* we already wrote some! */
+ /* user can do another write to know the error code */
+ return total;
+ }
return cc; /* write() returns -1 on failure. */
+ }
total += cc;
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 @@
#include "libbb.h"
/*
- * Return TRUE if a fileName is a directory.
+ * Return TRUE if fileName is a directory.
* Nonexistent files return FALSE.
*/
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
struct stat astatBuf;
if (statBuf == NULL) {
- /* set from auto stack buffer */
- statBuf = &astatBuf;
+ /* use auto stack buffer */
+ statBuf = &astatBuf;
}
if (followLinks)
@@ -30,10 +30,7 @@ int is_directory(const char *fileName, const int followLinks, struct stat *statB
else
status = lstat(fileName, statBuf);
- if (status < 0 || !(S_ISDIR(statBuf->st_mode))) {
- status = FALSE;
- }
- else status = TRUE;
+ status = (status == 0 && S_ISDIR(statBuf->st_mode));
return status;
}
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)
while (len) {
cc = safe_read(fd, buf, len);
- if (cc < 0)
- return cc; /* read() returns -1 on failure. */
+ if (cc < 0) {
+ if (total) {
+ /* we already have some! */
+ /* user can do another read to know the error code */
+ return total;
+ }
+ return cc; /* read() returns -1 on failure. */
+ }
if (cc == 0)
break;
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)
bb_perror_msg_and_die("chdir(%s)", path);
}
+void xchroot(const char *path)
+{
+ if (chroot(path))
+ bb_perror_msg_and_die("can't change root directory to %s", path);
+}
+
// Print a warning message if opendir() fails, but don't die.
DIR *warn_opendir(const char *path)
{