xref: /titanic_50/usr/src/lib/libsendfile/common/sendfile.c (revision 0bb073995ac5a95bd35f2dd790df1ea3d8c2d507)
1 
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance 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 2006 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 		if (error == EINTR && *xferred != 0) {
54 			rval.sys_rval1 = *xferred;
55 		} else {
56 			(void) __set_errno(error);
57 		}
58 	}
59 	return ((ssize_t)rval.sys_rval1);
60 }
61 
62 ssize_t
63 _sendfile(int sock, int fd, off_t *off, size_t len)
64 {
65 	sysret_t rval;
66 	int error;
67 	struct sendfilevec sfv;
68 	size_t xferred;
69 
70 	sfv.sfv_fd = fd;
71 	sfv.sfv_flag = 0;
72 	sfv.sfv_off = *off;
73 	sfv.sfv_len = len;
74 	error = __systemcall(&rval, SYS_sendfilev, SENDFILEV, sock, &sfv,
75 	    1, &xferred);
76 	*off += xferred;
77 	if (error != 0) {
78 		if (error == EINTR && xferred != 0) {
79 			rval.sys_rval1 = xferred;
80 		} else {
81 			(void) __set_errno(error);
82 		}
83 	}
84 	return ((ssize_t)rval.sys_rval1);
85 }
86 
87 #if (!defined(_LP64))
88 
89 #pragma weak sendfilev64 = _sendfilev64
90 #pragma weak sendfile64 = _sendfile64
91 
92 ssize_t
93 _sendfilev64(int sock, const struct sendfilevec64 *vec, int sfvcnt,
94     size_t *xferred)
95 {
96 	sysret_t rval;
97 	int error;
98 
99 	error = __systemcall(&rval, SYS_sendfilev, SENDFILEV64, sock, vec,
100 	    sfvcnt, xferred);
101 	if (error != 0) {
102 		if (error == EINTR && *xferred != 0) {
103 			rval.sys_rval1 = *xferred;
104 		} else {
105 			(void) __set_errno(error);
106 		}
107 	}
108 	return ((ssize_t)rval.sys_rval1);
109 }
110 
111 ssize_t
112 _sendfile64(int sock, int fd, off64_t *off, size_t len)
113 {
114 	sysret_t rval;
115 	int error;
116 	struct sendfilevec64 sfv;
117 	size_t xferred;
118 
119 	sfv.sfv_fd = fd;
120 	sfv.sfv_flag = 0;
121 	sfv.sfv_off = *off;
122 	sfv.sfv_len = len;
123 	error = __systemcall(&rval, SYS_sendfilev, SENDFILEV64, sock, &sfv,
124 	    1, &xferred);
125 	*off += xferred;
126 	if (error != 0) {
127 		if (error == EINTR && xferred != 0) {
128 			rval.sys_rval1 = xferred;
129 		} else {
130 			(void) __set_errno(error);
131 		}
132 	}
133 	return ((ssize_t)rval.sys_rval1);
134 }
135 #endif
136