annotate lib/ftruncate.c @ 17255:d81be792518a

update from texinfo
author Karl Berry <karl@freefriends.org>
date Tue, 01 Jan 2013 15:51:49 -0800
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15739
9f82d16d3139 ftruncate: Un-deprecate, concentrate on Win32 support.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
1 /* ftruncate emulations for native Windows.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 17188
diff changeset
2 Copyright (C) 1992-2013 Free Software Foundation, Inc.
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
3
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
4 This program is free software; you can redistribute it and/or modify
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
5 it under the terms of the GNU General Public License as published by
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
6 the Free Software Foundation; either version 3, or (at your option)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
7 any later version.
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
8
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
9 This program is distributed in the hope that it will be useful,
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
12 GNU General Public License for more details.
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
13
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
14 You should have received a copy of the GNU General Public License along
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
15 with this program; if not, see <http://www.gnu.org/licenses/>. */
291
Jim Meyering <jim@meyering.net>
parents: 5
diff changeset
16
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
17 #include <config.h>
5
41c9d08b09d7 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
18
8199
51d32a83a7df Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
19 /* Specification. */
51d32a83a7df Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
20 #include <unistd.h>
51d32a83a7df Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
21
15739
9f82d16d3139 ftruncate: Un-deprecate, concentrate on Win32 support.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
22 #if HAVE_CHSIZE
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
23 /* A native Windows platform. */
5
41c9d08b09d7 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
24
15782
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
25 # include <errno.h>
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
26
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
27 # if _GL_WINDOWS_64_BIT_OFF_T
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
28
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
29 /* Large File Support: off_t is 64-bit, but chsize() takes only a 32-bit
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
30 argument. So, define a 64-bit safe SetFileSize function ourselves. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
31
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
32 /* Ensure that <windows.h> declares GetFileSizeEx. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
33 # undef _WIN32_WINNT
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
34 # define _WIN32_WINNT 0x500
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
35
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
36 /* Get declarations of the native Windows API functions. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
37 # define WIN32_LEAN_AND_MEAN
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
38 # include <windows.h>
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
39
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
40 /* Get _get_osfhandle. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
41 # include "msvc-nothrow.h"
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
42
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
43 static BOOL
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
44 SetFileSize (HANDLE h, LONGLONG size)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
45 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
46 LARGE_INTEGER old_size;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
47
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
48 if (!GetFileSizeEx (h, &old_size))
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
49 return FALSE;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
50
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
51 if (size != old_size.QuadPart)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
52 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
53 /* Duplicate the handle, so we are free to modify its file position. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
54 HANDLE curr_process = GetCurrentProcess ();
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
55 HANDLE tmph;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
56
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
57 if (!DuplicateHandle (curr_process, /* SourceProcessHandle */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
58 h, /* SourceHandle */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
59 curr_process, /* TargetProcessHandle */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
60 (PHANDLE) &tmph, /* TargetHandle */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
61 (DWORD) 0, /* DesiredAccess */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
62 FALSE, /* InheritHandle */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
63 DUPLICATE_SAME_ACCESS)) /* Options */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
64 return FALSE;
291
Jim Meyering <jim@meyering.net>
parents: 5
diff changeset
65
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
66 if (size < old_size.QuadPart)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
67 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
68 /* Reduce the size. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
69 LONG size_hi = (LONG) (size >> 32);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
70 if (SetFilePointer (tmph, (LONG) size, &size_hi, FILE_BEGIN)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
71 == INVALID_SET_FILE_POINTER
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
72 && GetLastError() != NO_ERROR)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
73 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
74 CloseHandle (tmph);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
75 return FALSE;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
76 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
77 if (!SetEndOfFile (tmph))
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
78 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
79 CloseHandle (tmph);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
80 return FALSE;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
81 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
82 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
83 else
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
84 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
85 /* Increase the size by adding zero bytes at the end. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
86 static char zero_bytes[1024];
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
87 LONG pos_hi = 0;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
88 LONG pos_lo = SetFilePointer (tmph, (LONG) 0, &pos_hi, FILE_END);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
89 LONGLONG pos;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
90 if (pos_lo == INVALID_SET_FILE_POINTER
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
91 && GetLastError() != NO_ERROR)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
92 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
93 CloseHandle (tmph);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
94 return FALSE;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
95 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
96 pos = ((LONGLONG) pos_hi << 32) | (ULONGLONG) (ULONG) pos_lo;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
97 while (pos < size)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
98 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
99 DWORD written;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
100 LONGLONG count = size - pos;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
101 if (count > sizeof (zero_bytes))
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
102 count = sizeof (zero_bytes);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
103 if (!WriteFile (tmph, zero_bytes, (DWORD) count, &written, NULL)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
104 || written == 0)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
105 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
106 CloseHandle (tmph);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
107 return FALSE;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
108 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
109 pos += (ULONGLONG) (ULONG) written;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
110 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
111 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
112 /* Close the handle. */
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
113 CloseHandle (tmph);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
114 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
115 return TRUE;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
116 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
117
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
118 int
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
119 ftruncate (int fd, off_t length)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
120 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
121 HANDLE handle = (HANDLE) _get_osfhandle (fd);
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
122
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
123 if (handle == INVALID_HANDLE_VALUE)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
124 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
125 errno = EBADF;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
126 return -1;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
127 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
128 if (length < 0)
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
129 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
130 errno = EINVAL;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
131 return -1;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
132 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
133 if (!SetFileSize (handle, length))
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
134 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
135 switch (GetLastError ())
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
136 {
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
137 case ERROR_ACCESS_DENIED:
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
138 errno = EACCES;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
139 break;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
140 case ERROR_HANDLE_DISK_FULL:
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
141 case ERROR_DISK_FULL:
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
142 case ERROR_DISK_TOO_FRAGMENTED:
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
143 errno = ENOSPC;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
144 break;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
145 default:
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
146 errno = EIO;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
147 break;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
148 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
149 return -1;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
150 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
151 return 0;
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
152 }
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
153
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
154 # else
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
155
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
156 # include <io.h>
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
157
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
158 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
159 # include "msvc-inval.h"
17188
d7a44f0f7a15 ftruncate, fts, lstat, openat, raise: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 16795
diff changeset
160 static int
15782
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
161 chsize_nothrow (int fd, long length)
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
162 {
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
163 int result;
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
164
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
165 TRY_MSVC_INVAL
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
166 {
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
167 result = chsize (fd, length);
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
168 }
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
169 CATCH_MSVC_INVAL
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
170 {
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
171 result = -1;
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
172 errno = EBADF;
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
173 }
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
174 DONE_MSVC_INVAL;
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
175
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
176 return result;
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
177 }
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
178 # define chsize chsize_nothrow
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
179 # endif
15782
402bb52d5f11 ftruncate: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15739
diff changeset
180
5
41c9d08b09d7 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
181 int
1557
38fd8f5d359d ansideclify
Jim Meyering <jim@meyering.net>
parents: 1278
diff changeset
182 ftruncate (int fd, off_t length)
5
41c9d08b09d7 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
183 {
41c9d08b09d7 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
184 return chsize (fd, length);
41c9d08b09d7 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
185 }
291
Jim Meyering <jim@meyering.net>
parents: 5
diff changeset
186
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 15782
diff changeset
187 # endif
15739
9f82d16d3139 ftruncate: Un-deprecate, concentrate on Win32 support.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
188 #endif