thr_write.c revision 165967
1325322Sgordon/* 2325322Sgordon * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> 3325322Sgordon * All rights reserved. 4325322Sgordon * 5325322Sgordon * Redistribution and use in source and binary forms, with or without 6325322Sgordon * modification, are permitted provided that the following conditions 7325322Sgordon * are met: 8325322Sgordon * 1. Redistributions of source code must retain the above copyright 9325322Sgordon * notice, this list of conditions and the following disclaimer. 10325322Sgordon * 2. Redistributions in binary form must reproduce the above copyright 11325322Sgordon * notice, this list of conditions and the following disclaimer in the 12325322Sgordon * documentation and/or other materials provided with the distribution. 13325322Sgordon * 3. Neither the name of the author nor the names of any co-contributors 14325322Sgordon * may be used to endorse or promote products derived from this software 15325322Sgordon * without specific prior written permission. 16325322Sgordon * 17325322Sgordon * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 18325322Sgordon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19325322Sgordon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20325322Sgordon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21325322Sgordon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22325322Sgordon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23325322Sgordon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24325322Sgordon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25325322Sgordon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26325322Sgordon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27325322Sgordon * SUCH DAMAGE. 28325322Sgordon * 29325322Sgordon * $FreeBSD: head/lib/libkse/thread/thr_write.c 165967 2007-01-12 07:26:21Z imp $ 30325322Sgordon * 31325322Sgordon */ 32325322Sgordon#include <sys/types.h> 33325322Sgordon#include <sys/fcntl.h> 34325322Sgordon#include <sys/uio.h> 35325322Sgordon#include <errno.h> 36325322Sgordon#include <unistd.h> 37325322Sgordon#include <pthread.h> 38325322Sgordon#include "thr_private.h" 39325322Sgordon 40325322SgordonLT10_COMPAT_PRIVATE(__write); 41325322SgordonLT10_COMPAT_DEFAULT(write); 42325322Sgordon 43325322Sgordon__weak_reference(__write, write); 44325322Sgordon 45325322Sgordonssize_t 46325322Sgordon__write(int fd, const void *buf, size_t nbytes) 47325322Sgordon{ 48325322Sgordon struct pthread *curthread = _get_curthread(); 49325322Sgordon ssize_t ret; 50325322Sgordon 51325322Sgordon _thr_cancel_enter(curthread); 52325322Sgordon ret = __sys_write(fd, buf, nbytes); 53325322Sgordon _thr_cancel_leave(curthread, 1); 54325322Sgordon 55325322Sgordon return ret; 56325322Sgordon} 57325322Sgordon