xref: /titanic_41/usr/src/lib/libmail/common/copystream.c (revision 6be356c5780a1ccb886bba08d6eb56b61f021564)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
24 /*	  All Rights Reserved  	*/
25 
26 /*
27  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 /*LINTLIBRARY*/
33 
34 /*
35     NAME
36 	copystream - copy one FILE stream to another
37 
38     SYNOPSIS
39 	int copystream(FILE *infp, FILE *outfp)
40 
41     DESCRIPTION
42 	copystream() copies one stream to another. The stream
43 	infp must be opened for reading and the stream outfp
44 	must be opened for writing.
45 
46 	It returns true if the stream is successively copied;
47 	false if any writes fail.
48 */
49 
50 #include "c_synonyms.h"
51 #include "libmail.h"
52 #include <sys/types.h>
53 
54 int
55 copystream(FILE *infp, FILE *outfp)
56 {
57 	char buffer[BUFSIZ];
58 	size_t nread;
59 
60 	while ((nread = fread(buffer, sizeof (char), sizeof (buffer),
61 	    infp)) > 0)
62 		if (fwrite(buffer, sizeof (char), nread, outfp) != nread)
63 			return (0);
64 	return (1);
65 }
66