Rework to fix http://bugs.uclibc.org/view.php?id=107
This commit is contained in:
parent
3cd1986195
commit
451c0d2828
@ -2,7 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
* Utility routines.
|
* Utility routines.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
* Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
#include "libbb.h"
|
||||||
|
|
||||||
|
|
||||||
#if BUFSIZ < 4096
|
#if BUFSIZ < 4096
|
||||||
@ -33,46 +34,54 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* If size is 0 copy until EOF */
|
static size_t bb_full_fd_action(int src_fd, int dst_fd, const size_t size2)
|
||||||
static size_t bb_full_fd_action(int src_fd, int dst_fd, const size_t size)
|
|
||||||
{
|
{
|
||||||
size_t read_total = 0;
|
int status;
|
||||||
RESERVE_CONFIG_BUFFER(buffer,BUFSIZ);
|
size_t xread, wrote, total, size = size2;
|
||||||
|
|
||||||
while ((size == 0) || (read_total < size)) {
|
if ((dst_fd < 0) || (src_fd < 0)) {
|
||||||
size_t read_try;
|
return -1;
|
||||||
ssize_t read_actual;
|
}
|
||||||
|
|
||||||
if ((size == 0) || (size - read_total > BUFSIZ)) {
|
if (size == 0) {
|
||||||
read_try = BUFSIZ;
|
/* If size is 0 copy until EOF */
|
||||||
} else {
|
size = ULONG_MAX;
|
||||||
read_try = size - read_total;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
read_actual = safe_read(src_fd, buffer, read_try);
|
{
|
||||||
if (read_actual > 0) {
|
RESERVE_CONFIG_BUFFER(buffer,BUFSIZ);
|
||||||
if ((dst_fd >= 0) && (bb_full_write(dst_fd, buffer, (size_t) read_actual) != read_actual)) {
|
total = 0;
|
||||||
bb_perror_msg(bb_msg_write_error); /* match Read error below */
|
wrote = 0;
|
||||||
|
status = -1;
|
||||||
|
while (total < size)
|
||||||
|
{
|
||||||
|
xread = BUFSIZ;
|
||||||
|
if (size < (wrote + BUFSIZ))
|
||||||
|
xread = size - wrote;
|
||||||
|
xread = bb_full_read(src_fd, buffer, xread);
|
||||||
|
if (xread > 0) {
|
||||||
|
wrote = bb_full_write(dst_fd, buffer, xread);
|
||||||
|
if (wrote < xread) {
|
||||||
|
bb_perror_msg(bb_msg_write_error);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
total += wrote;
|
||||||
|
} else if (xread < 0) {
|
||||||
|
bb_perror_msg(bb_msg_read_error);
|
||||||
|
break;
|
||||||
|
} else if (xread == 0) {
|
||||||
|
/* All done. */
|
||||||
|
status = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (read_actual == 0) {
|
RELEASE_CONFIG_BUFFER(buffer);
|
||||||
if (size) {
|
|
||||||
bb_error_msg("Unable to read all data");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
/* read_actual < 0 */
|
|
||||||
bb_perror_msg("Read error");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
read_total += read_actual;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RELEASE_CONFIG_BUFFER(buffer);
|
if (status == 0 || wrote)
|
||||||
|
return wrote;
|
||||||
return(read_total);
|
/* Some sortof error occured */
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user