1*9760e1c4Sblu 27c478bd9Sstevel@tonic-gate /* 37c478bd9Sstevel@tonic-gate * CDDL HEADER START 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 6*9760e1c4Sblu * Common Development and Distribution License (the "License"). 7*9760e1c4Sblu * You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*9760e1c4Sblu * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * sendfilev is the native interface : 32 bit app on 32 bit kernel 317c478bd9Sstevel@tonic-gate * and 64 bit app on 64 bit kernel. sendfilev64() is used by 327c478bd9Sstevel@tonic-gate * 32 bit apps on a 64 bit kernel or 32 bit kernel for large 337c478bd9Sstevel@tonic-gate * file offsets. Similar things apply to sendfile. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #pragma weak sendfilev = _sendfilev 377c478bd9Sstevel@tonic-gate #pragma weak sendfile = _sendfile 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/types.h> 407c478bd9Sstevel@tonic-gate #include <sys/syscall.h> 417c478bd9Sstevel@tonic-gate #include <sys/sendfile.h> 427c478bd9Sstevel@tonic-gate #include <errno.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate ssize_t 457c478bd9Sstevel@tonic-gate _sendfilev(int sock, const struct sendfilevec *vec, int sfvcnt, size_t *xferred) 467c478bd9Sstevel@tonic-gate { 477c478bd9Sstevel@tonic-gate sysret_t rval; 487c478bd9Sstevel@tonic-gate int error; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate error = __systemcall(&rval, SYS_sendfilev, SENDFILEV, sock, vec, 517c478bd9Sstevel@tonic-gate sfvcnt, xferred); 52*9760e1c4Sblu if (error != 0) { 53*9760e1c4Sblu if (error == EINTR && *xferred != 0) { 54*9760e1c4Sblu rval.sys_rval1 = *xferred; 55*9760e1c4Sblu } else { 567c478bd9Sstevel@tonic-gate (void) __set_errno(error); 57*9760e1c4Sblu } 58*9760e1c4Sblu } 597c478bd9Sstevel@tonic-gate return ((ssize_t)rval.sys_rval1); 607c478bd9Sstevel@tonic-gate } 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate ssize_t 637c478bd9Sstevel@tonic-gate _sendfile(int sock, int fd, off_t *off, size_t len) 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate sysret_t rval; 667c478bd9Sstevel@tonic-gate int error; 677c478bd9Sstevel@tonic-gate struct sendfilevec sfv; 687c478bd9Sstevel@tonic-gate size_t xferred; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate sfv.sfv_fd = fd; 717c478bd9Sstevel@tonic-gate sfv.sfv_flag = 0; 727c478bd9Sstevel@tonic-gate sfv.sfv_off = *off; 737c478bd9Sstevel@tonic-gate sfv.sfv_len = len; 747c478bd9Sstevel@tonic-gate error = __systemcall(&rval, SYS_sendfilev, SENDFILEV, sock, &sfv, 757c478bd9Sstevel@tonic-gate 1, &xferred); 767c478bd9Sstevel@tonic-gate *off += xferred; 77*9760e1c4Sblu if (error != 0) { 78*9760e1c4Sblu if (error == EINTR && xferred != 0) { 79*9760e1c4Sblu rval.sys_rval1 = xferred; 80*9760e1c4Sblu } else { 817c478bd9Sstevel@tonic-gate (void) __set_errno(error); 82*9760e1c4Sblu } 83*9760e1c4Sblu } 847c478bd9Sstevel@tonic-gate return ((ssize_t)rval.sys_rval1); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #if (!defined(_LP64)) 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate #pragma weak sendfilev64 = _sendfilev64 907c478bd9Sstevel@tonic-gate #pragma weak sendfile64 = _sendfile64 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate ssize_t 937c478bd9Sstevel@tonic-gate _sendfilev64(int sock, const struct sendfilevec64 *vec, int sfvcnt, 947c478bd9Sstevel@tonic-gate size_t *xferred) 957c478bd9Sstevel@tonic-gate { 967c478bd9Sstevel@tonic-gate sysret_t rval; 977c478bd9Sstevel@tonic-gate int error; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate error = __systemcall(&rval, SYS_sendfilev, SENDFILEV64, sock, vec, 1007c478bd9Sstevel@tonic-gate sfvcnt, xferred); 101*9760e1c4Sblu if (error != 0) { 102*9760e1c4Sblu if (error == EINTR && *xferred != 0) { 103*9760e1c4Sblu rval.sys_rval1 = *xferred; 104*9760e1c4Sblu } else { 1057c478bd9Sstevel@tonic-gate (void) __set_errno(error); 106*9760e1c4Sblu } 107*9760e1c4Sblu } 1087c478bd9Sstevel@tonic-gate return ((ssize_t)rval.sys_rval1); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate ssize_t 1127c478bd9Sstevel@tonic-gate _sendfile64(int sock, int fd, off64_t *off, size_t len) 1137c478bd9Sstevel@tonic-gate { 1147c478bd9Sstevel@tonic-gate sysret_t rval; 1157c478bd9Sstevel@tonic-gate int error; 1167c478bd9Sstevel@tonic-gate struct sendfilevec64 sfv; 1177c478bd9Sstevel@tonic-gate size_t xferred; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate sfv.sfv_fd = fd; 1207c478bd9Sstevel@tonic-gate sfv.sfv_flag = 0; 1217c478bd9Sstevel@tonic-gate sfv.sfv_off = *off; 1227c478bd9Sstevel@tonic-gate sfv.sfv_len = len; 1237c478bd9Sstevel@tonic-gate error = __systemcall(&rval, SYS_sendfilev, SENDFILEV64, sock, &sfv, 1247c478bd9Sstevel@tonic-gate 1, &xferred); 1257c478bd9Sstevel@tonic-gate *off += xferred; 126*9760e1c4Sblu if (error != 0) { 127*9760e1c4Sblu if (error == EINTR && xferred != 0) { 128*9760e1c4Sblu rval.sys_rval1 = xferred; 129*9760e1c4Sblu } else { 1307c478bd9Sstevel@tonic-gate (void) __set_errno(error); 131*9760e1c4Sblu } 132*9760e1c4Sblu } 1337c478bd9Sstevel@tonic-gate return ((ssize_t)rval.sys_rval1); 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate #endif 136