]>
Commit | Line | Data |
---|---|---|
d587d83b UD |
1 | /* Copyright (C) 1997, 1998, 1999 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 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 | |
29 | static int have_no_ftruncate64; | |
30 | ||
31 | extern int __syscall_ftruncate64 (int fd, int high_length, int low_length); | |
32 | ||
33 | ||
34 | /* Truncate the file FD refers to to LENGTH bytes. */ | |
35 | int | |
36 | ftruncate64 (fd, length) | |
37 | int fd; | |
38 | off64_t length; | |
39 | { | |
40 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
41 | if (! have_no_ftruncate64) | |
42 | #endif | |
43 | { | |
44 | int result = INLINE_SYSCALL (ftruncate64, 3, fd, length >> 32, | |
45 | length & 0xffffffff); | |
46 | ||
47 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
48 | if (result != -1 || errno != ENOSYS) | |
49 | #endif | |
50 | return result; | |
51 | ||
52 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
53 | have_no_ftruncate64 = 1; | |
54 | #endif | |
55 | } | |
56 | ||
57 | #ifndef __ASSUME_TRUNCATE64_SYSCALL | |
58 | if ((off_t) length != length) | |
59 | { | |
60 | __set_errno (EINVAL); | |
61 | return -1; | |
62 | } | |
63 | return __ftruncate (fd, (off_t) length); | |
64 | #endif | |
65 | } | |
66 | ||
67 | #else | |
68 | /* Use the generic implementation. */ | |
69 | # include <sysdeps/generic/ftruncate64.c> | |
70 | #endif |