Mercurial > gnulib
annotate lib/stat-w32.c @ 40235:5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
* lib/stat-w32.c et al.: Update URLs after most of msdn.microsoft.com
was moved to docs.microsoft.com.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 14 Mar 2019 09:49:24 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Core of implementation of fstat and stat for native Windows. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
39795
diff
changeset
|
2 Copyright (C) 2017-2019 Free Software Foundation, Inc. |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include <config.h> |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
21 #if defined _WIN32 && ! defined __CYGWIN__ |
18894
e57c3cc7ec27
stat, fstat: Complete removal of old native Windows code.
Bruno Haible <bruno@clisp.org>
parents:
18825
diff
changeset
|
22 |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
23 /* Ensure that <windows.h> defines FILE_ID_INFO. */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
24 #undef _WIN32_WINNT |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
25 #define _WIN32_WINNT _WIN32_WINNT_WIN8 |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
26 |
18970
4813afd31c1e
stat: Improve last change.
Bruno Haible <bruno@clisp.org>
parents:
18969
diff
changeset
|
27 #include <sys/types.h> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 #include <sys/stat.h> |
18894
e57c3cc7ec27
stat, fstat: Complete removal of old native Windows code.
Bruno Haible <bruno@clisp.org>
parents:
18825
diff
changeset
|
29 #include <errno.h> |
e57c3cc7ec27
stat, fstat: Complete removal of old native Windows code.
Bruno Haible <bruno@clisp.org>
parents:
18825
diff
changeset
|
30 #include <limits.h> |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
31 #include <string.h> |
18894
e57c3cc7ec27
stat, fstat: Complete removal of old native Windows code.
Bruno Haible <bruno@clisp.org>
parents:
18825
diff
changeset
|
32 #include <unistd.h> |
e57c3cc7ec27
stat, fstat: Complete removal of old native Windows code.
Bruno Haible <bruno@clisp.org>
parents:
18825
diff
changeset
|
33 #include <windows.h> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 /* Specification. */ |
18894
e57c3cc7ec27
stat, fstat: Complete removal of old native Windows code.
Bruno Haible <bruno@clisp.org>
parents:
18825
diff
changeset
|
36 #include "stat-w32.h" |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 |
18894
e57c3cc7ec27
stat, fstat: Complete removal of old native Windows code.
Bruno Haible <bruno@clisp.org>
parents:
18825
diff
changeset
|
38 #include "pathmax.h" |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
39 #include "verify.h" |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
39795
ecc02d9772ef
Avoid -Wcast-function-type warnings from casts after GetProcAddress.
Bruno Haible <bruno@clisp.org>
parents:
19595
diff
changeset
|
41 /* Avoid warnings from gcc -Wcast-function-type. */ |
ecc02d9772ef
Avoid -Wcast-function-type warnings from casts after GetProcAddress.
Bruno Haible <bruno@clisp.org>
parents:
19595
diff
changeset
|
42 #define GetProcAddress \ |
ecc02d9772ef
Avoid -Wcast-function-type warnings from casts after GetProcAddress.
Bruno Haible <bruno@clisp.org>
parents:
19595
diff
changeset
|
43 (void *) GetProcAddress |
ecc02d9772ef
Avoid -Wcast-function-type warnings from casts after GetProcAddress.
Bruno Haible <bruno@clisp.org>
parents:
19595
diff
changeset
|
44 |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
45 #if _GL_WINDOWS_STAT_INODES == 2 |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
46 /* GetFileInformationByHandleEx was introduced only in Windows Vista. */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
47 typedef DWORD (WINAPI * GetFileInformationByHandleExFuncType) (HANDLE hFile, |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
48 FILE_INFO_BY_HANDLE_CLASS fiClass, |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
49 LPVOID lpBuffer, |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
50 DWORD dwBufferSize); |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
51 static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = NULL; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
52 #endif |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 /* GetFinalPathNameByHandle was introduced only in Windows Vista. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile, |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 LPTSTR lpFilePath, |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 DWORD lenFilePath, |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 DWORD dwFlags); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 static BOOL initialized = FALSE; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 static void |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 initialize (void) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 HMODULE kernel32 = LoadLibrary ("kernel32.dll"); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 if (kernel32 != NULL) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 { |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
67 #if _GL_WINDOWS_STAT_INODES == 2 |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
68 GetFileInformationByHandleExFunc = |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
69 (GetFileInformationByHandleExFuncType) GetProcAddress (kernel32, "GetFileInformationByHandleEx"); |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
70 #endif |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 GetFinalPathNameByHandleFunc = |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
72 (GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA"); |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 initialized = TRUE; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 /* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */ |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
78 #if _GL_WINDOWS_STAT_TIMESPEC |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
79 struct timespec |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
80 _gl_convert_FILETIME_to_timespec (const FILETIME *ft) |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
81 { |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
82 struct timespec result; |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
83 /* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */ |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
84 unsigned long long since_1601 = |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
85 ((unsigned long long) ft->dwHighDateTime << 32) |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
86 | (unsigned long long) ft->dwLowDateTime; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
87 if (since_1601 == 0) |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
88 { |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
89 result.tv_sec = 0; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
90 result.tv_nsec = 0; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
91 } |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
92 else |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
93 { |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
94 /* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89 |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
95 leap years, in total 134774 days. */ |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
96 unsigned long long since_1970 = |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
97 since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
98 result.tv_sec = since_1970 / (unsigned long long) 10000000; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
99 result.tv_nsec = (unsigned long) (since_1970 % (unsigned long long) 10000000) * 100; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
100 } |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
101 return result; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
102 } |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
103 #else |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 time_t |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 _gl_convert_FILETIME_to_POSIX (const FILETIME *ft) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 { |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
107 /* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */ |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 unsigned long long since_1601 = |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 ((unsigned long long) ft->dwHighDateTime << 32) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 | (unsigned long long) ft->dwLowDateTime; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 if (since_1601 == 0) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 return 0; |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
113 else |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
114 { |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
115 /* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89 |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
116 leap years, in total 134774 days. */ |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
117 unsigned long long since_1970 = |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
118 since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
119 return since_1970 / (unsigned long long) 10000000; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
120 } |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 } |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
122 #endif |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 /* Fill *BUF with information about the file designated by H. |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 PATH is the file name, if known, otherwise NULL. |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 Return 0 if successful, or -1 with errno set upon failure. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 int |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 /* GetFileType |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
131 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletype> */ |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 DWORD type = GetFileType (h); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 if (type == FILE_TYPE_DISK) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 if (!initialized) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 initialize (); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 /* st_mode can be determined through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 GetFileAttributesEx |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
140 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
141 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 GetFileInformationByHandle |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
144 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
145 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 GetFileInformationByHandleEx with argument FileBasicInfo |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
148 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
149 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 BY_HANDLE_FILE_INFORMATION info; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 if (! GetFileInformationByHandle (h, &info)) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 goto failed; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 /* Test for error conditions before starting to fill *buf. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 errno = EOVERFLOW; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 return -1; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
162 #if _GL_WINDOWS_STAT_INODES |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
163 /* st_ino can be determined through |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
164 GetFileInformationByHandle |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
165 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
166 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information> |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
167 as 64 bits, or through |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
168 GetFileInformationByHandleEx with argument FileIdInfo |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
169 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
170 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_id_info> |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
171 as 128 bits. |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
172 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_WIN8 or higher. */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
173 /* Experiments show that GetFileInformationByHandleEx does not provide |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
174 much more information than GetFileInformationByHandle: |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
175 * The dwVolumeSerialNumber from GetFileInformationByHandle is equal |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
176 to the low 32 bits of the 64-bit VolumeSerialNumber from |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
177 GetFileInformationByHandleEx, and is apparently sufficient for |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
178 identifying the device. |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
179 * The nFileIndex from GetFileInformationByHandle is equal to the low |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
180 64 bits of the 128-bit FileId from GetFileInformationByHandleEx, |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
181 and the high 64 bits of this 128-bit FileId are zero. |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
182 * On a FAT file system, GetFileInformationByHandleEx fails with error |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
183 ERROR_INVALID_PARAMETER, whereas GetFileInformationByHandle |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
184 succeeds. |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
185 * On a CIFS/SMB file system, GetFileInformationByHandleEx fails with |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
186 error ERROR_INVALID_LEVEL, whereas GetFileInformationByHandle |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
187 succeeds. */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
188 # if _GL_WINDOWS_STAT_INODES == 2 |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
189 if (GetFileInformationByHandleExFunc != NULL) |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
190 { |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
191 FILE_ID_INFO id; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
192 if (GetFileInformationByHandleExFunc (h, FileIdInfo, &id, sizeof (id))) |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
193 { |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
194 buf->st_dev = id.VolumeSerialNumber; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
195 verify (sizeof (ino_t) == sizeof (id.FileId)); |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
196 memcpy (&buf->st_ino, &id.FileId, sizeof (ino_t)); |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
197 goto ino_done; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
198 } |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
199 else |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
200 { |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
201 switch (GetLastError ()) |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
202 { |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
203 case ERROR_INVALID_PARAMETER: /* older Windows version, or FAT */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
204 case ERROR_INVALID_LEVEL: /* CIFS/SMB file system */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
205 goto fallback; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
206 default: |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
207 goto failed; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
208 } |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
209 } |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
210 } |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
211 fallback: ; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
212 /* Fallback for older Windows versions. */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
213 buf->st_dev = info.dwVolumeSerialNumber; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
214 buf->st_ino._gl_ino[0] = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
215 buf->st_ino._gl_ino[1] = 0; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
216 ino_done: ; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
217 # else /* _GL_WINDOWS_STAT_INODES == 1 */ |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
218 buf->st_dev = info.dwVolumeSerialNumber; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
219 buf->st_ino = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
220 # endif |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
221 #else |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
222 /* st_ino is not wide enough for identifying a file on a device. |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 Without st_ino, st_dev is pointless. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
224 buf->st_dev = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
225 buf->st_ino = 0; |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
226 #endif |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
227 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
228 /* st_mode. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
229 unsigned int mode = |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
230 /* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
231 ((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
232 | S_IREAD_UGO |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
233 | ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
234 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
235 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
236 /* Determine whether the file is executable by looking at the file |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
237 name suffix. |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
238 If the file name is already known, use it. Otherwise, for |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
239 non-empty files, it can be determined through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
240 GetFinalPathNameByHandle |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
241 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
242 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
243 GetFileInformationByHandleEx with argument FileNameInfo |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
244 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
245 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_name_info> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
246 Both require -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
247 if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
248 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
249 char fpath[PATH_MAX]; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
250 if (path != NULL |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
251 || (GetFinalPathNameByHandleFunc != NULL |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
252 && GetFinalPathNameByHandleFunc (h, fpath, sizeof (fpath), VOLUME_NAME_NONE) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
253 < sizeof (fpath) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
254 && (path = fpath, 1))) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
255 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
256 const char *last_dot = NULL; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
257 const char *p; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
258 for (p = path; *p != '\0'; p++) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
259 if (*p == '.') |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
260 last_dot = p; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
261 if (last_dot != NULL) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
262 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
263 const char *suffix = last_dot + 1; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
264 if (_stricmp (suffix, "exe") == 0 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
265 || _stricmp (suffix, "bat") == 0 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
266 || _stricmp (suffix, "cmd") == 0 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
267 || _stricmp (suffix, "com") == 0) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
268 mode |= S_IEXEC_UGO; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
269 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
270 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
271 else |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
272 /* Cannot determine file name. Pretend that it is executable. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
273 mode |= S_IEXEC_UGO; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
274 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
275 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
276 buf->st_mode = mode; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
277 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
278 /* st_nlink can be determined through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
279 GetFileInformationByHandle |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
280 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
281 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
282 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
283 GetFileInformationByHandleEx with argument FileStandardInfo |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
284 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
285 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
286 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
287 buf->st_nlink = (info.nNumberOfLinks > SHRT_MAX ? SHRT_MAX : info.nNumberOfLinks); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
288 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
289 /* There's no easy way to map the Windows SID concept to an integer. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
290 buf->st_uid = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
291 buf->st_gid = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
292 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
293 /* st_rdev is irrelevant for normal files and directories. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
294 buf->st_rdev = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
295 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
296 /* st_size can be determined through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
297 GetFileSizeEx |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
298 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfilesizeex> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
299 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
300 GetFileAttributesEx |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
301 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
302 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
303 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
304 GetFileInformationByHandle |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
305 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
306 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
307 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
308 GetFileInformationByHandleEx with argument FileStandardInfo |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
309 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
310 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
311 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
312 if (sizeof (buf->st_size) <= 4) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
313 /* Range check already done above. */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
314 buf->st_size = info.nFileSizeLow; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
315 else |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
316 buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
317 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
318 /* st_atime, st_mtime, st_ctime can be determined through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
319 GetFileTime |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
320 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletime> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
321 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
322 GetFileAttributesEx |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
323 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
324 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
325 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
326 GetFileInformationByHandle |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
327 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
328 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
329 or through |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
330 GetFileInformationByHandleEx with argument FileBasicInfo |
40235
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
331 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex> |
5a52ef2d4772
all: Update URLs to msdn.microsoft.com.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
332 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info> |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
333 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */ |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
334 #if _GL_WINDOWS_STAT_TIMESPEC |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
335 buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime); |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
336 buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime); |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
337 buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime); |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
338 #else |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
339 buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
340 buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
341 buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime); |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
342 #endif |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
343 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
344 return 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
345 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
346 else if (type == FILE_TYPE_CHAR || type == FILE_TYPE_PIPE) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
347 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
348 buf->st_dev = 0; |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
349 #if _GL_WINDOWS_STAT_INODES == 2 |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
350 buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0; |
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
351 #else |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
352 buf->st_ino = 0; |
18907
c82a2191d535
windows-stat-inodes: New module.
Bruno Haible <bruno@clisp.org>
parents:
18897
diff
changeset
|
353 #endif |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
354 buf->st_mode = (type == FILE_TYPE_PIPE ? _S_IFIFO : _S_IFCHR); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
355 buf->st_nlink = 1; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
356 buf->st_uid = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
357 buf->st_gid = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
358 buf->st_rdev = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
359 if (type == FILE_TYPE_PIPE) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
360 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
361 /* PeekNamedPipe |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
362 <https://msdn.microsoft.com/en-us/library/aa365779.aspx> */ |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
363 DWORD bytes_available; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
364 if (PeekNamedPipe (h, NULL, 0, NULL, &bytes_available, NULL)) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
365 buf->st_size = bytes_available; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
366 else |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
367 buf->st_size = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
368 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
369 else |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
370 buf->st_size = 0; |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
371 #if _GL_WINDOWS_STAT_TIMESPEC |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
372 buf->st_atim.tv_sec = 0; buf->st_atim.tv_nsec = 0; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
373 buf->st_mtim.tv_sec = 0; buf->st_mtim.tv_nsec = 0; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
374 buf->st_ctim.tv_sec = 0; buf->st_ctim.tv_nsec = 0; |
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
375 #else |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
376 buf->st_atime = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
377 buf->st_mtime = 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
378 buf->st_ctime = 0; |
18897
ce759095c7b0
windows-stat-timespec: New module.
Bruno Haible <bruno@clisp.org>
parents:
18894
diff
changeset
|
379 #endif |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
380 return 0; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
381 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
382 else |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
383 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
384 errno = ENOENT; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
385 return -1; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
386 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
387 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
388 failed: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
389 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
390 DWORD error = GetLastError (); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
391 #if 0 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
392 fprintf (stderr, "_gl_fstat_by_handle error 0x%x\n", (unsigned int) error); |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
393 #endif |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
394 switch (error) |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
395 { |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
396 case ERROR_ACCESS_DENIED: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
397 case ERROR_SHARING_VIOLATION: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
398 errno = EACCES; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
399 break; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
400 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
401 case ERROR_OUTOFMEMORY: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
402 errno = ENOMEM; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
403 break; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
404 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
405 case ERROR_WRITE_FAULT: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
406 case ERROR_READ_FAULT: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
407 case ERROR_GEN_FAILURE: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
408 errno = EIO; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
409 break; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
410 |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
411 default: |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
412 errno = EINVAL; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
413 break; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
414 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
415 return -1; |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
416 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
417 } |
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
418 |
18970
4813afd31c1e
stat: Improve last change.
Bruno Haible <bruno@clisp.org>
parents:
18969
diff
changeset
|
419 #else |
4813afd31c1e
stat: Improve last change.
Bruno Haible <bruno@clisp.org>
parents:
18969
diff
changeset
|
420 |
4813afd31c1e
stat: Improve last change.
Bruno Haible <bruno@clisp.org>
parents:
18969
diff
changeset
|
421 /* This declaration is solely to ensure that after preprocessing |
4813afd31c1e
stat: Improve last change.
Bruno Haible <bruno@clisp.org>
parents:
18969
diff
changeset
|
422 this file is never empty. */ |
4813afd31c1e
stat: Improve last change.
Bruno Haible <bruno@clisp.org>
parents:
18969
diff
changeset
|
423 typedef int dummy; |
4813afd31c1e
stat: Improve last change.
Bruno Haible <bruno@clisp.org>
parents:
18969
diff
changeset
|
424 |
18825
285a56d46e71
fstat: Fix time_t values on native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
425 #endif |