1 | /* Copyright (C) 2002 Free Software Foundation, Inc.
|
---|
2 |
|
---|
3 | This file is part of GNU Bash, the Bourne Again SHell.
|
---|
4 |
|
---|
5 | Bash is free software; you can redistribute it and/or modify it under
|
---|
6 | the terms of the GNU General Public License as published by the Free
|
---|
7 | Software Foundation; either version 2, or (at your option) any later
|
---|
8 | version.
|
---|
9 |
|
---|
10 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
---|
13 | for more details.
|
---|
14 |
|
---|
15 | You should have received a copy of the GNU General Public License along
|
---|
16 | with Bash; see the file COPYING. If not, write to the Free Software
|
---|
17 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
---|
18 |
|
---|
19 | #include <config.h>
|
---|
20 |
|
---|
21 | #include <sys/types.h>
|
---|
22 |
|
---|
23 | #if defined (HAVE_UNISTD_H)
|
---|
24 | # include <unistd.h>
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | #include <errno.h>
|
---|
28 |
|
---|
29 | #include <stdc.h>
|
---|
30 |
|
---|
31 | #if !defined (errno)
|
---|
32 | extern int errno;
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | extern ssize_t zread __P((int, char *, size_t));
|
---|
36 | extern int zwrite __P((int, char *, ssize_t));
|
---|
37 |
|
---|
38 | /* Dump contents of file descriptor FD to OFD. FN is the filename for
|
---|
39 | error messages (not used right now). */
|
---|
40 | int
|
---|
41 | zcatfd (fd, ofd, fn)
|
---|
42 | int fd, ofd;
|
---|
43 | char *fn;
|
---|
44 | {
|
---|
45 | ssize_t nr;
|
---|
46 | int rval;
|
---|
47 | char lbuf[128];
|
---|
48 |
|
---|
49 | rval = 0;
|
---|
50 | while (1)
|
---|
51 | {
|
---|
52 | nr = zread (fd, lbuf, sizeof (lbuf));
|
---|
53 | if (nr == 0)
|
---|
54 | break;
|
---|
55 | else if (nr < 0)
|
---|
56 | {
|
---|
57 | rval = -1;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | else if (zwrite (ofd, lbuf, nr) < 0)
|
---|
61 | {
|
---|
62 | rval = -1;
|
---|
63 | break;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | return rval;
|
---|
68 | }
|
---|