]>
Commit | Line | Data |
---|---|---|
313fed01 | 1 | /* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
d587d83b UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Library General Public License as | |
6 | published by the Free Software Foundation; either version 2 of the | |
7 | License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Library General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Library General Public | |
15 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
16 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 | Boston, MA 02111-1307, USA. */ | |
18 | ||
19 | #include <sys/types.h> | |
20 | #include <errno.h> | |
21 | #include <unistd.h> | |
22 | ||
23 | #include <sysdep.h> | |
24 | #include <sys/syscall.h> | |
25 | ||
26 | #include "kernel-features.h" | |
27 | ||
28 | #ifdef __NR_ftruncate64 | |
29332175 UD |
29 | #ifndef __ASSUME_TRUNCATE64_SYSCALL |
30 | /* The variable is shared between all wrappers around *truncate64 calls. */ | |
313fed01 | 31 | extern int __have_no_truncate64; |
29332175 | 32 | #endif |
d587d83b UD |
33 | |
34 | extern int __syscall_ftruncate64 (int fd, int high_length, int low_length); | |
35 | ||
36 | ||
37 | /* Truncate the file FD refers to to LENGTH bytes. */ | |
38 | int | |
39 | ftruncate64 (fd, length) | |
40 | int fd; | |
41 | off64_t length; | |
42 | { | |
43 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
313fed01 | 44 | if (! __have_no_truncate64) |
d587d83b UD |
45 | #endif |
46 | { | |
af1680f1 UD |
47 | unsigned int low = length & 0xffffffff; |
48 | unsigned int high = length >> 32; | |
63a34b0f UD |
49 | #ifndef __ASSUME_TRUNCATE64_SYSCALL |
50 | int saved_errno = errno; | |
51 | #endif | |
af1680f1 | 52 | int result = INLINE_SYSCALL (ftruncate64, 3, fd, low, high); |
d587d83b UD |
53 | |
54 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
55 | if (result != -1 || errno != ENOSYS) | |
56 | #endif | |
57 | return result; | |
58 | ||
59 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
63a34b0f | 60 | __set_errno (saved_errno); |
313fed01 | 61 | __have_no_truncate64 = 1; |
d587d83b UD |
62 | #endif |
63 | } | |
64 | ||
65 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
66 | if ((off_t) length != length) | |
67 | { | |
68 | __set_errno (EINVAL); | |
69 | return -1; | |
70 | } | |
71 | return __ftruncate (fd, (off_t) length); | |
72 | #endif | |
73 | } | |
74 | ||
75 | #else | |
76 | /* Use the generic implementation. */ | |
77 | # include <sysdeps/generic/ftruncate64.c> | |
78 | #endif |