]>
Commit | Line | Data |
---|---|---|
de96d148 DJ |
1 | /* Copyright (C) 1997-2000, 2003, 2004, 2005 Free Software Foundation, Inc. |
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 Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the 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 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
ab84e3ff PE |
15 | License along with the GNU C Library. If not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
de96d148 DJ |
17 | |
18 | #include <sys/types.h> | |
19 | #include <endian.h> | |
20 | #include <errno.h> | |
21 | #include <unistd.h> | |
22 | ||
23 | #include <sysdep.h> | |
24 | #include <sys/syscall.h> | |
25 | #include <bp-checks.h> | |
26 | ||
27 | #include "kernel-features.h" | |
28 | ||
29 | #ifdef __NR_truncate64 | |
30 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
31 | /* The variable is shared between all wrappers around *truncate64 calls. */ | |
32 | int __have_no_truncate64; | |
33 | #endif | |
34 | ||
35 | /* Truncate the file FD refers to to LENGTH bytes. */ | |
36 | int | |
37 | truncate64 (const char *path, off64_t length) | |
38 | { | |
39 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
40 | if (! __have_no_truncate64) | |
41 | #endif | |
42 | { | |
43 | unsigned int low = length & 0xffffffff; | |
44 | unsigned int high = length >> 32; | |
45 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
46 | int saved_errno = errno; | |
47 | #endif | |
48 | int result = INLINE_SYSCALL (truncate64, 4, CHECK_STRING (path), 0, | |
49 | __LONG_LONG_PAIR (high, low)); | |
50 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
51 | if (result != -1 || errno != ENOSYS) | |
52 | #endif | |
53 | return result; | |
54 | ||
55 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
56 | __set_errno (saved_errno); | |
57 | __have_no_truncate64 = 1; | |
58 | #endif | |
59 | } | |
60 | ||
61 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
62 | if ((off_t) length != length) | |
63 | { | |
64 | __set_errno (EINVAL); | |
65 | return -1; | |
66 | } | |
67 | return __truncate (path, (off_t) length); | |
68 | #endif | |
69 | } | |
70 | ||
71 | #else | |
72 | /* Use the generic implementation. */ | |
8e674bfd | 73 | # include <misc/truncate64.c> |
de96d148 | 74 | #endif |