diff options
author | Matt Kraai <kraai@debian.org> | 2001-05-18 14:14:55 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-05-18 14:14:55 +0000 |
commit | d6ef07406d217a728d334ae5e49c4734b4ed26f5 (patch) | |
tree | 61708f6aa1e598e454ff0be88793bf14d7833132 | |
parent | 69438154000344f0fc60b12c0d31b297c698b5f4 (diff) | |
download | busybox-w32-d6ef07406d217a728d334ae5e49c4734b4ed26f5.tar.gz busybox-w32-d6ef07406d217a728d334ae5e49c4734b4ed26f5.tar.bz2 busybox-w32-d6ef07406d217a728d334ae5e49c4734b4ed26f5.zip |
Rewrote copyfd to use library functions, terminate, and copy correct data.
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/copyfd.c | 40 | ||||
-rw-r--r-- | libbb/libbb.h | 2 |
3 files changed, 18 insertions, 26 deletions
diff --git a/include/libbb.h b/include/libbb.h index 29a756b7f..4e324bf86 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -133,7 +133,7 @@ extern pid_t* find_pid_by_name( char* pidName); | |||
133 | extern char *find_real_root_device_name(const char* name); | 133 | extern char *find_real_root_device_name(const char* name); |
134 | extern char *get_line_from_file(FILE *file); | 134 | extern char *get_line_from_file(FILE *file); |
135 | extern void print_file(FILE *file); | 135 | extern void print_file(FILE *file); |
136 | extern size_t copyfd(int fd1, int fd2); | 136 | extern int copyfd(int fd1, int fd2); |
137 | extern int print_file_by_name(char *filename); | 137 | extern int print_file_by_name(char *filename); |
138 | extern char process_escape_sequence(const char **ptr); | 138 | extern char process_escape_sequence(const char **ptr); |
139 | extern char *get_last_path_component(char *path); | 139 | extern char *get_last_path_component(char *path); |
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 | ||
28 | extern size_t copyfd(int fd1, int fd2) | 28 | extern 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); | |||
133 | extern char *find_real_root_device_name(const char* name); | 133 | extern char *find_real_root_device_name(const char* name); |
134 | extern char *get_line_from_file(FILE *file); | 134 | extern char *get_line_from_file(FILE *file); |
135 | extern void print_file(FILE *file); | 135 | extern void print_file(FILE *file); |
136 | extern size_t copyfd(int fd1, int fd2); | 136 | extern int copyfd(int fd1, int fd2); |
137 | extern int print_file_by_name(char *filename); | 137 | extern int print_file_by_name(char *filename); |
138 | extern char process_escape_sequence(const char **ptr); | 138 | extern char process_escape_sequence(const char **ptr); |
139 | extern char *get_last_path_component(char *path); | 139 | extern char *get_last_path_component(char *path); |