summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2000-08-25 03:50:10 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2000-08-25 03:50:10 +0000
commit06aeb6c417dd9d113949714486a6e6337ef70b97 (patch)
tree0f002c36314483775fa2a248ae1c8b5346c70030 /utility.c
parent4d5ac2f346d01e51cde9c44431067138bd586f36 (diff)
downloadbusybox-w32-06aeb6c417dd9d113949714486a6e6337ef70b97.tar.gz
busybox-w32-06aeb6c417dd9d113949714486a6e6337ef70b97.tar.bz2
busybox-w32-06aeb6c417dd9d113949714486a6e6337ef70b97.zip
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.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/utility.c b/utility.c
index de0311d17..2851dd20d 100644
--- a/utility.c
+++ b/utility.c
@@ -231,7 +231,7 @@ void reset_ino_dev_hashtable(void)
231 231
232#endif /* BB_CP_MV || BB_DU */ 232#endif /* BB_CP_MV || BB_DU */
233 233
234#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN) || defined (BB_AR) 234#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN)
235/* 235/*
236 * Return TRUE if a fileName is a directory. 236 * Return TRUE if a fileName is a directory.
237 * Nonexistant files return FALSE. 237 * Nonexistant files return FALSE.
@@ -264,6 +264,29 @@ int isDirectory(const char *fileName, const int followLinks, struct stat *statBu
264} 264}
265#endif 265#endif
266 266
267#if defined (BB_AR)
268/*
269 * Copy readSize bytes between two file descriptors
270 */
271int copySubFile(int srcFd, int dstFd, size_t remaining)
272{
273 size_t size;
274 char buffer[BUFSIZ];
275
276 while (remaining > 0) {
277 if (remaining > BUFSIZ)
278 size = BUFSIZ;
279 else
280 size = remaining;
281 if (fullWrite(dstFd, buffer, fullRead(srcFd, buffer, size)) < size)
282 return(FALSE);
283 remaining -= size;
284 }
285 return (TRUE);
286}
287#endif
288
289
267#if defined (BB_CP_MV) 290#if defined (BB_CP_MV)
268/* 291/*
269 * Copy one file to another, while possibly preserving its modes, times, and 292 * Copy one file to another, while possibly preserving its modes, times, and
@@ -277,9 +300,7 @@ copyFile(const char *srcName, const char *destName,
277{ 300{
278 int rfd; 301 int rfd;
279 int wfd; 302 int wfd;
280 int rcc;
281 int status; 303 int status;
282 char buf[BUF_SIZE];
283 struct stat srcStatBuf; 304 struct stat srcStatBuf;
284 struct stat dstStatBuf; 305 struct stat dstStatBuf;
285 struct utimbuf times; 306 struct utimbuf times;
@@ -364,8 +385,7 @@ copyFile(const char *srcName, const char *destName,
364 return FALSE; 385 return FALSE;
365 } 386 }
366 387
367 wfd = 388 wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC,
368 open(destName, O_WRONLY | O_CREAT | O_TRUNC,
369 srcStatBuf.st_mode); 389 srcStatBuf.st_mode);
370 if (wfd < 0) { 390 if (wfd < 0) {
371 perror(destName); 391 perror(destName);
@@ -373,14 +393,9 @@ copyFile(const char *srcName, const char *destName,
373 return FALSE; 393 return FALSE;
374 } 394 }
375 395
376 while ((rcc = read(rfd, buf, sizeof(buf))) > 0) { 396 if (copySubFile(rfd, wfd, srcStatBuf.st_size)==FALSE)
377 if (fullWrite(wfd, buf, rcc) < 0) 397 goto error_exit;
378 goto error_exit; 398
379 }
380 if (rcc < 0) {
381 goto error_exit;
382 }
383
384 close(rfd); 399 close(rfd);
385 if (close(wfd) < 0) { 400 if (close(wfd) < 0) {
386 return FALSE; 401 return FALSE;
@@ -677,7 +692,7 @@ int recursiveAction(const char *fileName,
677 692
678 693
679 694
680#if defined (BB_TAR) || defined (BB_MKDIR) || defined (BB_AR) 695#if defined (BB_TAR) || defined (BB_MKDIR)
681/* 696/*
682 * Attempt to create the directories along the specified path, except for 697 * Attempt to create the directories along the specified path, except for
683 * the final component. The mode is given for the final directory only, 698 * the final component. The mode is given for the final directory only,
@@ -1292,7 +1307,7 @@ extern long getNum(const char *cp)
1292#endif /* BB_DD || BB_TAIL */ 1307#endif /* BB_DD || BB_TAIL */
1293 1308
1294 1309
1295#if defined BB_INIT || defined BB_SYSLOGD || defined BB_AR 1310#if defined BB_INIT || defined BB_SYSLOGD
1296/* try to open up the specified device */ 1311/* try to open up the specified device */
1297extern int device_open(char *device, int mode) 1312extern int device_open(char *device, int mode)
1298{ 1313{