diff options
author | 2007-06-05 18:11:48 +0000 | |
---|---|---|
committer | 2007-06-05 18:11:48 +0000 | |
commit | 45e14c381361430fbd1edeac8cedeeb0decb1480 (patch) | |
tree | a5ed83726574726f3efb97709ca2097c63d5a220 /lib/libpthread/uthread/uthread_ftruncate.c | |
parent | remove ipx-related stuff. objections nobody. major bump by kurt in a few (diff) | |
download | wireguard-openbsd-45e14c381361430fbd1edeac8cedeeb0decb1480.tar.xz wireguard-openbsd-45e14c381361430fbd1edeac8cedeeb0decb1480.zip |
_FD_LOCK/UNLOCK() is libpthread specific and not needed for librthread, so
isolate its usage to libpthread only and replace with generic non-static
mutex support in the one place it is needed:
- remove _FD_LOCK/UNLOCK from lseek and ftruncate in libc and make the
functions weak so that libpthread can override with its own new
versions that do the locking.
- remove _thread_fd_lock/unlock() weak functions from libc and adjust
libpthread for the change.
- add generic _thread_mutex_lock/unlock/destroy() weak functions in libc
to support non-static mutexes in libc and add libpthread and librthread
implementations for them. libc can utilize non-static mutexes via the
new _MUTEX_LOCK/UNLOCK/DESTROY() macros. Actually these new macros can
support both static and non-static mutexes but currently only using
them for non-static.
- make opendir/closedir/readdir/readdir_r/seekdir/telldir() thread-safe
for both thread libraries by using a non-static mutex in the struct
_dirdesc (typedef DIR), utilizing it in the *dir functions and remove
remaining and incorrect _FD_LOCK/UNLOCK() use in libc.
- add comments to both thread libraries to indicate libc depends on the
current implementation of static mutex initialization. suggested by
marc@
- major bump libc and libpthread due to function removal, structure
change and weak symbol conversions.
okay marc@, tedu@
Diffstat (limited to 'lib/libpthread/uthread/uthread_ftruncate.c')
-rw-r--r-- | lib/libpthread/uthread/uthread_ftruncate.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/libpthread/uthread/uthread_ftruncate.c b/lib/libpthread/uthread/uthread_ftruncate.c new file mode 100644 index 00000000000..c29e2f090dc --- /dev/null +++ b/lib/libpthread/uthread/uthread_ftruncate.c @@ -0,0 +1,57 @@ +/* $OpenBSD: uthread_ftruncate.c,v 1.1 2007/06/05 18:11:49 kurt Exp $ */ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +register_t __syscall(quad_t, ...); + +/* + * This function provides 64-bit offset padding that + * is not supplied by GCC 1.X but is supplied by GCC 2.X. + */ +int +ftruncate(int fd, off_t length) +{ + int retval; + + if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { + retval = -1; + } else { + retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length); + _FD_UNLOCK(fd, FD_RDWR); + } + return retval; +} +#endif |