diff options
author | Glenn L McGrath | 2000-08-25 03:50:10 +0000 |
---|---|---|
committer | Glenn L McGrath | 2000-08-25 03:50:10 +0000 |
commit | 06aeb6c417dd9d113949714486a6e6337ef70b97 (patch) | |
tree | 0f002c36314483775fa2a248ae1c8b5346c70030 /utility.c | |
parent | 4d5ac2f346d01e51cde9c44431067138bd586f36 (diff) | |
download | busybox-06aeb6c417dd9d113949714486a6e6337ef70b97.zip busybox-06aeb6c417dd9d113949714486a6e6337ef70b97.tar.gz |
ar.c now uses a linked list to process headers, uses getopt, new internal function extractAr(srcFD, dstFd, filename) to make it easily accessable to other busybox functions.
moved copySubFile from ar.c to utilities.c
modified dd.c to use fullWrite
modified copyFile in utilities.c to use copySubFile
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 45 |
1 files changed, 30 insertions, 15 deletions
@@ -231,7 +231,7 @@ void reset_ino_dev_hashtable(void) #endif /* BB_CP_MV || BB_DU */ -#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN) || defined (BB_AR) +#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN) /* * Return TRUE if a fileName is a directory. * Nonexistant files return FALSE. @@ -264,6 +264,29 @@ int isDirectory(const char *fileName, const int followLinks, struct stat *statBu } #endif +#if defined (BB_AR) +/* + * Copy readSize bytes between two file descriptors + */ +int copySubFile(int srcFd, int dstFd, size_t remaining) +{ + size_t size; + char buffer[BUFSIZ]; + + while (remaining > 0) { + if (remaining > BUFSIZ) + size = BUFSIZ; + else + size = remaining; + if (fullWrite(dstFd, buffer, fullRead(srcFd, buffer, size)) < size) + return(FALSE); + remaining -= size; + } + return (TRUE); +} +#endif + + #if defined (BB_CP_MV) /* * Copy one file to another, while possibly preserving its modes, times, and @@ -277,9 +300,7 @@ copyFile(const char *srcName, const char *destName, { int rfd; int wfd; - int rcc; int status; - char buf[BUF_SIZE]; struct stat srcStatBuf; struct stat dstStatBuf; struct utimbuf times; @@ -364,8 +385,7 @@ copyFile(const char *srcName, const char *destName, return FALSE; } - wfd = - open(destName, O_WRONLY | O_CREAT | O_TRUNC, + wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC, srcStatBuf.st_mode); if (wfd < 0) { perror(destName); @@ -373,14 +393,9 @@ copyFile(const char *srcName, const char *destName, return FALSE; } - while ((rcc = read(rfd, buf, sizeof(buf))) > 0) { - if (fullWrite(wfd, buf, rcc) < 0) - goto error_exit; - } - if (rcc < 0) { - goto error_exit; - } - + if (copySubFile(rfd, wfd, srcStatBuf.st_size)==FALSE) + goto error_exit; + close(rfd); if (close(wfd) < 0) { return FALSE; @@ -677,7 +692,7 @@ int recursiveAction(const char *fileName, -#if defined (BB_TAR) || defined (BB_MKDIR) || defined (BB_AR) +#if defined (BB_TAR) || defined (BB_MKDIR) /* * Attempt to create the directories along the specified path, except for * the final component. The mode is given for the final directory only, @@ -1292,7 +1307,7 @@ extern long getNum(const char *cp) #endif /* BB_DD || BB_TAIL */ -#if defined BB_INIT || defined BB_SYSLOGD || defined BB_AR +#if defined BB_INIT || defined BB_SYSLOGD /* try to open up the specified device */ extern int device_open(char *device, int mode) { |