Cleaup read() and write() variants, plus a couple of new functions like

xlseek and fdlength() for the new mkswap.
This commit is contained in:
Rob Landley
2006-07-16 08:14:35 +00:00
parent afb94ecf2b
commit 534374755d
39 changed files with 208 additions and 228 deletions

View File

@@ -961,7 +961,7 @@ static int sendHeaders(HttpResponseNum responseNum)
#if DEBUG
fprintf(stderr, "Headers: '%s'", buf);
#endif
return bb_full_write(a_c_w, buf, len);
return full_write(a_c_w, buf, len);
}
/****************************************************************************
@@ -1222,7 +1222,7 @@ static int sendCgi(const char *url,
break;
}
} else if(post_readed_size > 0 && FD_ISSET(outFd, &writeSet)) {
count = bb_full_write(outFd, wbuf + post_readed_idx, post_readed_size);
count = full_write(outFd, wbuf + post_readed_idx, post_readed_size);
if(count > 0) {
post_readed_size -= count;
post_readed_idx += count;
@@ -1263,14 +1263,14 @@ static int sendCgi(const char *url,
rbuf[count] = 0;
/* check to see if the user script added headers */
if(strncmp(rbuf, "HTTP/1.0 200 OK\r\n", 4) != 0) {
bb_full_write(s, "HTTP/1.0 200 OK\r\n", 17);
full_write(s, "HTTP/1.0 200 OK\r\n", 17);
}
if (strstr(rbuf, "ontent-") == 0) {
bb_full_write(s, "Content-type: text/plain\r\n\r\n", 28);
full_write(s, "Content-type: text/plain\r\n\r\n", 28);
}
firstLine = 0;
}
if (bb_full_write(s, rbuf, count) != count)
if (full_write(s, rbuf, count) != count)
break;
#if DEBUG
@@ -1337,8 +1337,8 @@ static int sendFile(const char *url)
char *buf = config->buf;
sendHeaders(HTTP_OK);
while ((count = bb_full_read(f, buf, MAX_MEMORY_BUFF)) > 0) {
if (bb_full_write(a_c_w, buf, count) != count)
while ((count = full_read(f, buf, MAX_MEMORY_BUFF)) > 0) {
if (full_write(a_c_w, buf, count) != count)
break;
}
close(f);
@@ -2000,7 +2000,7 @@ int httpd_main(int argc, char *argv[])
# ifdef CONFIG_FEATURE_HTTPD_SETUID
/* drop privileges */
if(uid > 0)
setuid(uid);
xsetuid(uid);
# endif
#endif

View File

@@ -9,8 +9,6 @@
#include "busybox.h"
#define xread bb_xread
static void timeout(int signum)
{
bb_error_msg_and_die("Timed out");
@@ -151,13 +149,14 @@ repeatyness:
for (fd = 0; fd < FD_SETSIZE; fd++) {
if (FD_ISSET(fd, &testfds)) {
nread = xread(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1));
nread = safe_read(fd, bb_common_bufsiz1,
sizeof(bb_common_bufsiz1));
if (fd == cfd) {
if (!nread) exit(0);
if (nread<1) exit(0);
ofd = STDOUT_FILENO;
} else {
if (!nread) {
if (nread<1) {
// Close outgoing half-connection so they get EOF, but
// leave incoming alone so we can see response.
shutdown(cfd, 1);
@@ -166,8 +165,7 @@ repeatyness:
ofd = cfd;
}
if (bb_full_write(ofd, bb_common_bufsiz1, nread) < 0)
bb_perror_msg_and_die(bb_msg_write_error);
xwrite(ofd, bb_common_bufsiz1, nread);
if (delay > 0) sleep(delay);
}
}

View File

@@ -249,7 +249,7 @@ static int tftp(const int cmd, const struct hostent *host,
block_nr++;
if ((cmd & tftp_cmd_put) && (opcode == TFTP_DATA)) {
len = bb_full_read(localfd, cp, tftp_bufsize - 4);
len = full_read(localfd, cp, tftp_bufsize - 4);
if (len < 0) {
bb_perror_msg(bb_msg_read_error);
@@ -420,7 +420,7 @@ static int tftp(const int cmd, const struct hostent *host,
if (tmp == block_nr) {
len = bb_full_write(localfd, &buf[4], len - 4);
len = full_write(localfd, &buf[4], len - 4);
if (len < 0) {
bb_perror_msg(bb_msg_write_error);