aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-18 14:14:55 +0000
committerkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-18 14:14:55 +0000
commitea00fbf6c0a74bb6be70423fbb13beb70dd9faba (patch)
tree61708f6aa1e598e454ff0be88793bf14d7833132 /libbb
parent76e94801a1526aa135b044f9d1a98b8dd4d1e2bd (diff)
downloadbusybox-w32-ea00fbf6c0a74bb6be70423fbb13beb70dd9faba.tar.gz
busybox-w32-ea00fbf6c0a74bb6be70423fbb13beb70dd9faba.tar.bz2
busybox-w32-ea00fbf6c0a74bb6be70423fbb13beb70dd9faba.zip
Rewrote copyfd to use library functions, terminate, and copy correct data.
git-svn-id: svn://busybox.net/trunk/busybox@2672 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/copyfd.c40
-rw-r--r--libbb/libbb.h2
2 files changed, 17 insertions, 25 deletions
diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index 253a8cf6e..aa938d105 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -25,36 +25,28 @@
25#include "libbb.h" 25#include "libbb.h"
26 26
27 27
28extern size_t copyfd(int fd1, int fd2) 28extern int copyfd(int fd1, int fd2)
29{ 29{
30 char buf[32768], *writebuf; 30 char buf[8192];
31 int status = TRUE; 31 ssize_t nread, nwrote;
32 size_t totalread = 0, bytesread, byteswritten;
33 32
34 while(status) { 33 while (1) {
35 bytesread = read(fd1, &buf, sizeof(buf)); 34 nread = safe_read(fd1, buf, sizeof(buf));
36 if(bytesread == -1) { 35 if (nread == 0)
37 error_msg("read: %s", strerror(errno));
38 status = FALSE;
39 break; 36 break;
37 if (nread == -1) {
38 perror_msg("read");
39 return -1;
40 } 40 }
41 byteswritten = 0; 41
42 writebuf = buf; 42 nwrote = full_write(fd2, buf, nread);
43 while(bytesread) { 43 if (nwrote == -1) {
44 byteswritten = write( fd2, &writebuf, bytesread ); 44 perror_msg("write");
45 if(byteswritten == -1) { 45 return -1;
46 error_msg("write: %s", strerror(errno));
47 status = FALSE;
48 break;
49 }
50 bytesread -= byteswritten;
51 writebuf += byteswritten;
52 } 46 }
53 } 47 }
54 if ( status == TRUE ) 48
55 return totalread; 49 return 0;
56 else
57 return -1;
58} 50}
59 51
60/* END CODE */ 52/* END CODE */
diff --git a/libbb/libbb.h b/libbb/libbb.h
index 29a756b7f..4e324bf86 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -133,7 +133,7 @@ extern pid_t* find_pid_by_name( char* pidName);
133extern char *find_real_root_device_name(const char* name); 133extern char *find_real_root_device_name(const char* name);
134extern char *get_line_from_file(FILE *file); 134extern char *get_line_from_file(FILE *file);
135extern void print_file(FILE *file); 135extern void print_file(FILE *file);
136extern size_t copyfd(int fd1, int fd2); 136extern int copyfd(int fd1, int fd2);
137extern int print_file_by_name(char *filename); 137extern int print_file_by_name(char *filename);
138extern char process_escape_sequence(const char **ptr); 138extern char process_escape_sequence(const char **ptr);
139extern char *get_last_path_component(char *path); 139extern char *get_last_path_component(char *path);