Last change
on this file since 2571 was 821, checked in by Bruno Cornec, 18 years ago |
Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)
|
File size:
1.4 KB
|
Line | |
---|
1 | /* vi: set sw=4 ts=4: */
|
---|
2 | /*
|
---|
3 | * Utility routines.
|
---|
4 | *
|
---|
5 | * Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
---|
6 | *
|
---|
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include <errno.h>
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include <string.h>
|
---|
13 | #include <unistd.h>
|
---|
14 |
|
---|
15 | #include "libbb.h"
|
---|
16 |
|
---|
17 |
|
---|
18 | #if BUFSIZ < 4096
|
---|
19 | #undef BUFSIZ
|
---|
20 | #define BUFSIZ 4096
|
---|
21 | #endif
|
---|
22 |
|
---|
23 |
|
---|
24 | static ssize_t bb_full_fd_action(int src_fd, int dst_fd, size_t size)
|
---|
25 | {
|
---|
26 | int status = -1;
|
---|
27 | size_t total = 0;
|
---|
28 | RESERVE_CONFIG_BUFFER(buffer,BUFSIZ);
|
---|
29 |
|
---|
30 | if (src_fd < 0) goto out;
|
---|
31 | while (!size || total < size)
|
---|
32 | {
|
---|
33 | ssize_t wrote, xread;
|
---|
34 |
|
---|
35 | xread = safe_read(src_fd, buffer,
|
---|
36 | (!size || size - total > BUFSIZ) ? BUFSIZ : size - total);
|
---|
37 |
|
---|
38 | if (xread > 0) {
|
---|
39 | /* A -1 dst_fd means we need to fake it... */
|
---|
40 | wrote = (dst_fd < 0) ? xread : bb_full_write(dst_fd, buffer, xread);
|
---|
41 | if (wrote < xread) {
|
---|
42 | bb_perror_msg(bb_msg_write_error);
|
---|
43 | break;
|
---|
44 | }
|
---|
45 | total += wrote;
|
---|
46 | if (total == size) status = 0;
|
---|
47 | } else if (xread < 0) {
|
---|
48 | bb_perror_msg(bb_msg_read_error);
|
---|
49 | break;
|
---|
50 | } else if (xread == 0) {
|
---|
51 | /* All done. */
|
---|
52 | status = 0;
|
---|
53 | break;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | out:
|
---|
58 | RELEASE_CONFIG_BUFFER(buffer);
|
---|
59 |
|
---|
60 | return status ? status : (ssize_t)total;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | int bb_copyfd_size(int fd1, int fd2, const off_t size)
|
---|
65 | {
|
---|
66 | if (size) {
|
---|
67 | return(bb_full_fd_action(fd1, fd2, size));
|
---|
68 | }
|
---|
69 | return(0);
|
---|
70 | }
|
---|
71 |
|
---|
72 | int bb_copyfd_eof(int fd1, int fd2)
|
---|
73 | {
|
---|
74 | return(bb_full_fd_action(fd1, fd2, 0));
|
---|
75 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.