xref: /titanic_52/usr/src/lib/libsendfile/common/sendfile.c (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
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 2001-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * sendfilev is the native interface : 32 bit app on 32 bit kernel
31  * and 64 bit app on 64 bit kernel. sendfilev64() is used by
32  * 32 bit apps on a 64 bit kernel or 32 bit kernel for large
33  * file offsets. Similar things apply to sendfile.
34  */
35 
36 #pragma weak sendfilev = _sendfilev
37 #pragma weak sendfile = _sendfile
38 
39 #include <sys/types.h>
40 #include <sys/syscall.h>
41 #include <sys/sendfile.h>
42 #include <errno.h>
43 
44 ssize_t
45 _sendfilev(int sock, const struct sendfilevec *vec, int sfvcnt, size_t *xferred)
46 {
47 	sysret_t rval;
48 	int error;
49 
50 	error = __systemcall(&rval, SYS_sendfilev, SENDFILEV, sock, vec,
51 	    sfvcnt, xferred);
52 	if (error != 0)
53 		(void) __set_errno(error);
54 	return ((ssize_t)rval.sys_rval1);
55 }
56 
57 ssize_t
58 _sendfile(int sock, int fd, off_t *off, size_t len)
59 {
60 	sysret_t rval;
61 	int error;
62 	struct sendfilevec sfv;
63 	size_t xferred;
64 
65 	sfv.sfv_fd = fd;
66 	sfv.sfv_flag = 0;
67 	sfv.sfv_off = *off;
68 	sfv.sfv_len = len;
69 	error = __systemcall(&rval, SYS_sendfilev, SENDFILEV, sock, &sfv,
70 	    1, &xferred);
71 	*off += xferred;
72 	if (error != 0)
73 		(void) __set_errno(error);
74 	return ((ssize_t)rval.sys_rval1);
75 }
76 
77 #if (!defined(_LP64))
78 
79 #pragma weak sendfilev64 = _sendfilev64
80 #pragma weak sendfile64 = _sendfile64
81 
82 ssize_t
83 _sendfilev64(int sock, const struct sendfilevec64 *vec, int sfvcnt,
84     size_t *xferred)
85 {
86 	sysret_t rval;
87 	int error;
88 
89 	error = __systemcall(&rval, SYS_sendfilev, SENDFILEV64, sock, vec,
90 	    sfvcnt, xferred);
91 	if (error != 0)
92 		(void) __set_errno(error);
93 	return ((ssize_t)rval.sys_rval1);
94 }
95 
96 ssize_t
97 _sendfile64(int sock, int fd, off64_t *off, size_t len)
98 {
99 	sysret_t rval;
100 	int error;
101 	struct sendfilevec64 sfv;
102 	size_t xferred;
103 
104 	sfv.sfv_fd = fd;
105 	sfv.sfv_flag = 0;
106 	sfv.sfv_off = *off;
107 	sfv.sfv_len = len;
108 	error = __systemcall(&rval, SYS_sendfilev, SENDFILEV64, sock, &sfv,
109 	    1, &xferred);
110 	*off += xferred;
111 	if (error != 0)
112 		(void) __set_errno(error);
113 	return ((ssize_t)rval.sys_rval1);
114 }
115 #endif
116