Rewrote copyfd to use library functions, terminate, and copy correct data.
This commit is contained in:
parent
6943815400
commit
d6ef07406d
@ -133,7 +133,7 @@ extern pid_t* find_pid_by_name( char* pidName);
|
|||||||
extern char *find_real_root_device_name(const char* name);
|
extern char *find_real_root_device_name(const char* name);
|
||||||
extern char *get_line_from_file(FILE *file);
|
extern char *get_line_from_file(FILE *file);
|
||||||
extern void print_file(FILE *file);
|
extern void print_file(FILE *file);
|
||||||
extern size_t copyfd(int fd1, int fd2);
|
extern int copyfd(int fd1, int fd2);
|
||||||
extern int print_file_by_name(char *filename);
|
extern int print_file_by_name(char *filename);
|
||||||
extern char process_escape_sequence(const char **ptr);
|
extern char process_escape_sequence(const char **ptr);
|
||||||
extern char *get_last_path_component(char *path);
|
extern char *get_last_path_component(char *path);
|
||||||
|
@ -25,36 +25,28 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
|
||||||
extern size_t copyfd(int fd1, int fd2)
|
extern int copyfd(int fd1, int fd2)
|
||||||
{
|
{
|
||||||
char buf[32768], *writebuf;
|
char buf[8192];
|
||||||
int status = TRUE;
|
ssize_t nread, nwrote;
|
||||||
size_t totalread = 0, bytesread, byteswritten;
|
|
||||||
|
|
||||||
while(status) {
|
while (1) {
|
||||||
bytesread = read(fd1, &buf, sizeof(buf));
|
nread = safe_read(fd1, buf, sizeof(buf));
|
||||||
if(bytesread == -1) {
|
if (nread == 0)
|
||||||
error_msg("read: %s", strerror(errno));
|
|
||||||
status = FALSE;
|
|
||||||
break;
|
break;
|
||||||
|
if (nread == -1) {
|
||||||
|
perror_msg("read");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
byteswritten = 0;
|
|
||||||
writebuf = buf;
|
nwrote = full_write(fd2, buf, nread);
|
||||||
while(bytesread) {
|
if (nwrote == -1) {
|
||||||
byteswritten = write( fd2, &writebuf, bytesread );
|
perror_msg("write");
|
||||||
if(byteswritten == -1) {
|
return -1;
|
||||||
error_msg("write: %s", strerror(errno));
|
|
||||||
status = FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
bytesread -= byteswritten;
|
|
||||||
writebuf += byteswritten;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( status == TRUE )
|
|
||||||
return totalread;
|
return 0;
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
/* END CODE */
|
||||||
|
@ -133,7 +133,7 @@ extern pid_t* find_pid_by_name( char* pidName);
|
|||||||
extern char *find_real_root_device_name(const char* name);
|
extern char *find_real_root_device_name(const char* name);
|
||||||
extern char *get_line_from_file(FILE *file);
|
extern char *get_line_from_file(FILE *file);
|
||||||
extern void print_file(FILE *file);
|
extern void print_file(FILE *file);
|
||||||
extern size_t copyfd(int fd1, int fd2);
|
extern int copyfd(int fd1, int fd2);
|
||||||
extern int print_file_by_name(char *filename);
|
extern int print_file_by_name(char *filename);
|
||||||
extern char process_escape_sequence(const char **ptr);
|
extern char process_escape_sequence(const char **ptr);
|
||||||
extern char *get_last_path_component(char *path);
|
extern char *get_last_path_component(char *path);
|
||||||
|
Loading…
Reference in New Issue
Block a user