Mercurial > emacs
annotate lib-src/ntlib.c @ 101562:a3fdbe2837e3
(mh-pack-folder-hook): Bump package-version to 8.2.
author | Bill Wohler <wohler@newt.com> |
---|---|
date | Tue, 27 Jan 2009 06:42:19 +0000 |
parents | a9f7e446141d |
children | 06ca3efb355b |
rev | line source |
---|---|
9803 | 1 /* Utility and Unix shadow routines for GNU Emacs support programs on NT. |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94823
diff
changeset
|
2 Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
100958 | 3 2008, 2009 Free Software Foundation, Inc. |
9803 | 4 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
9803
diff
changeset
|
5 This file is part of GNU Emacs. |
9803 | 6 |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94823
diff
changeset
|
7 GNU Emacs is free software: you can redistribute it and/or modify |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
9803
diff
changeset
|
8 it under the terms of the GNU General Public License as published by |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94823
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94823
diff
changeset
|
10 (at your option) any later version. |
9803 | 11 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
9803
diff
changeset
|
12 GNU Emacs is distributed in the hope that it will be useful, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
9803
diff
changeset
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
9803
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
9803
diff
changeset
|
15 GNU General Public License for more details. |
9803 | 16 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
9803
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
94828
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94823
diff
changeset
|
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
3a4bc081639c
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94823
diff
changeset
|
19 |
9803 | 20 |
21 Geoff Voelker (voelker@cs.washington.edu) 10-8-94 | |
22 */ | |
23 | |
24 #include <windows.h> | |
25 #include <stdlib.h> | |
26 #include <stdio.h> | |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
27 #include <time.h> |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
28 #include <direct.h> |
94823
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
29 #include <sys/types.h> |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
30 #include <sys/stat.h> |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
31 #include <errno.h> |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
32 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
33 #include "ntlib.h" |
9803 | 34 |
35 #define MAXPATHLEN _MAX_PATH | |
36 | |
37 /* Emulate sleep...we could have done this with a define, but that | |
38 would necessitate including windows.h in the files that used it. | |
39 This is much easier. */ | |
40 void | |
31081
1fd32e8a2fad
(sleep): Make argument unsigned long.
Andrew Innes <andrewi@gnu.org>
parents:
22296
diff
changeset
|
41 sleep(unsigned long seconds) |
9803 | 42 { |
43 Sleep (seconds * 1000); | |
44 } | |
45 | |
46 /* Get the current working directory. */ | |
15675 | 47 char * |
9803 | 48 getwd (char *dir) |
49 { | |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
50 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
51 return dir; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
52 return NULL; |
9803 | 53 } |
54 | |
55 static HANDLE getppid_parent; | |
56 static int getppid_ppid; | |
57 | |
58 int | |
59 getppid(void) | |
60 { | |
61 char *ppid; | |
62 DWORD result; | |
63 | |
22296
b58a79fe0af2
(getppid): Look for EM_PARENT_PROCESS_ID.
Geoff Voelker <voelker@cs.washington.edu>
parents:
19694
diff
changeset
|
64 ppid = getenv ("EM_PARENT_PROCESS_ID"); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
31081
diff
changeset
|
65 if (!ppid) |
9803 | 66 { |
67 printf("no pid.\n"); | |
68 return 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
31081
diff
changeset
|
69 } |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
31081
diff
changeset
|
70 else |
9803 | 71 { |
72 getppid_ppid = atoi (ppid); | |
73 } | |
74 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
31081
diff
changeset
|
75 if (!getppid_parent) |
9803 | 76 { |
77 getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid)); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
31081
diff
changeset
|
78 if (!getppid_parent) |
9803 | 79 { |
80 printf ("Failed to open handle to parent process: %d\n", | |
81 GetLastError()); | |
82 exit (1); | |
83 } | |
84 } | |
85 | |
86 result = WaitForSingleObject (getppid_parent, 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
31081
diff
changeset
|
87 switch (result) |
9803 | 88 { |
89 case WAIT_TIMEOUT: | |
90 /* The parent is still alive. */ | |
91 return getppid_ppid; | |
92 case WAIT_OBJECT_0: | |
93 /* The parent is gone. Return the pid of Unix init (1). */ | |
94 return 1; | |
95 case WAIT_FAILED: | |
96 default: | |
97 printf ("Checking parent status failed: %d\n", GetLastError()); | |
98 exit (1); | |
99 } | |
100 } | |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
101 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
102 char * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
103 getlogin () |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
104 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
105 static char user_name[256]; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
106 DWORD length = sizeof (user_name); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
107 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
108 if (GetUserName (user_name, &length)) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
109 return user_name; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
110 return NULL; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
111 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
112 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
113 char * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
114 cuserid (char * s) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
115 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
116 char * name = getlogin (); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
117 if (s) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
118 return strcpy (s, name ? name : ""); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
119 return name; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
120 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
121 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
122 int |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
123 getuid () |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
124 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
125 return 0; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
126 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
127 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
128 int |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
129 setuid (int uid) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
130 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
131 return 0; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
132 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
133 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
134 struct passwd * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
135 getpwuid (int uid) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
136 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
137 return NULL; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
138 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
139 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
140 char * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
141 getpass (const char * prompt) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
142 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
143 static char input[256]; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
144 HANDLE in; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
145 HANDLE err; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
146 DWORD count; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
147 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
148 in = GetStdHandle (STD_INPUT_HANDLE); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
149 err = GetStdHandle (STD_ERROR_HANDLE); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
150 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
151 if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
152 return NULL; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
153 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
154 if (WriteFile (err, prompt, strlen (prompt), &count, NULL)) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
155 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
156 int istty = (GetFileType (in) == FILE_TYPE_CHAR); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
157 DWORD old_flags; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
158 int rc; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
159 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
160 if (istty) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
161 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
162 if (GetConsoleMode (in, &old_flags)) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
163 SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
164 else |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
165 istty = 0; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
166 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
167 rc = ReadFile (in, input, sizeof (input), &count, NULL); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
168 if (count >= 2 && input[count - 2] == '\r') |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
169 input[count - 2] = '\0'; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
170 else |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
171 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
172 char buf[256]; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
173 while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
174 if (count >= 2 && buf[count - 2] == '\r') |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
175 break; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
176 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
177 WriteFile (err, "\r\n", 2, &count, NULL); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
178 if (istty) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
179 SetConsoleMode (in, old_flags); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
180 if (rc) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
181 return input; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
182 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
183 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
184 return NULL; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
185 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
186 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
187 int |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
188 fchown (int fd, int uid, int gid) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
189 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
190 return 0; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
191 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
192 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
193 /* Place a wrapper around the MSVC version of ctime. It returns NULL |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
31081
diff
changeset
|
194 on network directories, so we handle that case here. |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
195 (Ulrich Leodolter, 1/11/95). */ |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
196 char * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
197 sys_ctime (const time_t *t) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
198 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
199 char *str = (char *) ctime (t); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
200 return (str ? str : "Sun Jan 01 00:00:00 1970"); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
201 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
202 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
203 FILE * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
204 sys_fopen(const char * path, const char * mode) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
205 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
206 return fopen (path, mode); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
207 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
208 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
209 int |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
210 sys_chdir (const char * path) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
211 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
212 return _chdir (path); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
213 } |
52401 | 214 |
94823
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
215 static FILETIME utc_base_ft; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
216 static long double utc_base; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
217 static int init = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
218 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
219 static time_t |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
220 convert_time (FILETIME ft) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
221 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
222 long double ret; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
223 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
224 if (CompareFileTime (&ft, &utc_base_ft) < 0) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
225 return 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
226 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
227 ret = (long double) ft.dwHighDateTime |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
228 * 4096.0L * 1024.0L * 1024.0L + ft.dwLowDateTime; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
229 ret -= utc_base; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
230 return (time_t) (ret * 1e-7L); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
231 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
232 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
233 static int |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
234 is_exec (const char * name) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
235 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
236 char * p = strrchr (name, '.'); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
237 return |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
238 (p != NULL |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
239 && (stricmp (p, ".exe") == 0 || |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
240 stricmp (p, ".com") == 0 || |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
241 stricmp (p, ".bat") == 0 || |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
242 stricmp (p, ".cmd") == 0)); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
243 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
244 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
245 #define IS_DIRECTORY_SEP(x) ((x) == '/' || (x) == '\\') |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
246 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
247 /* We need this because nt/inc/sys/stat.h defines struct stat that is |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
248 incompatible with the MS run-time libraries. */ |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
249 int |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
250 stat (const char * path, struct stat * buf) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
251 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
252 WIN32_FIND_DATA wfd; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
253 HANDLE fh; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
254 int permission; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
255 int len; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
256 int rootdir = FALSE; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
257 char *name = alloca (FILENAME_MAX); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
258 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
259 if (!init) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
260 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
261 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */ |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
262 SYSTEMTIME st; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
263 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
264 st.wYear = 1970; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
265 st.wMonth = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
266 st.wDay = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
267 st.wHour = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
268 st.wMinute = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
269 st.wSecond = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
270 st.wMilliseconds = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
271 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
272 SystemTimeToFileTime (&st, &utc_base_ft); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
273 utc_base = (long double) utc_base_ft.dwHighDateTime |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
274 * 4096.0L * 1024.0L * 1024.0L + utc_base_ft.dwLowDateTime; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
275 init = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
276 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
277 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
278 if (path == NULL || buf == NULL || *path == '\0') |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
279 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
280 errno = EFAULT; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
281 return -1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
282 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
283 if (_mbspbrk (path, "*?|<>\"")) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
284 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
285 errno = ENOENT; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
286 return -1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
287 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
288 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
289 strcpy (name, path); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
290 /* Remove trailing directory separator, unless name is the root |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
291 directory of a drive in which case ensure there is a trailing |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
292 separator. */ |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
293 len = strlen (name); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
294 rootdir = IS_DIRECTORY_SEP (name[0]) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
295 || (len == 3 && name[1] == ':' && IS_DIRECTORY_SEP (name[2])); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
296 if (rootdir) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
297 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
298 if (GetDriveType (name) < 2) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
299 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
300 errno = ENOENT; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
301 return -1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
302 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
303 memset (&wfd, 0, sizeof (wfd)); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
304 wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
305 wfd.ftCreationTime = utc_base_ft; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
306 wfd.ftLastAccessTime = utc_base_ft; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
307 wfd.ftLastWriteTime = utc_base_ft; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
308 strcpy (wfd.cFileName, name); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
309 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
310 else |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
311 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
312 if (IS_DIRECTORY_SEP (name[len-1])) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
313 name[len - 1] = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
314 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
315 fh = FindFirstFile (name, &wfd); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
316 if (fh == INVALID_HANDLE_VALUE) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
317 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
318 errno = ENOENT; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
319 return -1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
320 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
321 FindClose (fh); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
322 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
323 buf->st_mode = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
324 S_IFDIR : S_IFREG; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
325 buf->st_nlink = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
326 buf->st_ino = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
327 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
328 if (name[0] && name[1] == ':') |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
329 buf->st_dev = tolower (name[0]) - 'a' + 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
330 else |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
331 buf->st_dev = _getdrive (); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
332 buf->st_rdev = buf->st_dev; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
333 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
334 buf->st_size = wfd.nFileSizeLow; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
335 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
336 /* Convert timestamps to Unix format. */ |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
337 buf->st_mtime = convert_time (wfd.ftLastWriteTime); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
338 buf->st_atime = convert_time (wfd.ftLastAccessTime); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
339 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
340 buf->st_ctime = convert_time (wfd.ftCreationTime); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
341 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
342 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
343 /* determine rwx permissions */ |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
344 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
345 permission = S_IREAD; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
346 else |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
347 permission = S_IREAD | S_IWRITE; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
348 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
349 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
350 permission |= S_IEXEC; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
351 else if (is_exec (name)) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
352 permission |= S_IEXEC; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
353 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
354 buf->st_mode |= permission | (permission >> 3) | (permission >> 6); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
355 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
356 return 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
357 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
358 |
52401 | 359 /* arch-tag: 7b63fb83-70ee-4124-8822-54e53e5d0773 |
360 (do not change this comment) */ |