Mercurial > emacs
annotate lib-src/ntlib.c @ 108958:982e5d7f9b1e
* Makefile.in (install-arch-indep): Gzip the info files too.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 09 Jun 2010 22:34:38 -0700 |
parents | 65405dd90a72 |
children | d12162869c07 376148b31b5e |
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, |
106815 | 3 2008, 2009, 2010 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 |
102670
06ca3efb355b
inc/sys/stat.h (struct stat): Change the types of st_uid and st_gid to unsigned.
Eli Zaretskii <eliz@gnu.org>
parents:
100958
diff
changeset
|
122 unsigned |
15138
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 |
107769
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
128 unsigned |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
129 getgid () |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
130 { |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
131 return 0; |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
132 } |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
133 |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
134 unsigned |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
135 getegid () |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
136 { |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
137 return 0; |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
138 } |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
139 |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
140 int |
102670
06ca3efb355b
inc/sys/stat.h (struct stat): Change the types of st_uid and st_gid to unsigned.
Eli Zaretskii <eliz@gnu.org>
parents:
100958
diff
changeset
|
141 setuid (unsigned uid) |
15138
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 return 0; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
144 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
145 |
107769
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
146 int |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
147 setegid (unsigned gid) |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
148 { |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
149 return 0; |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
150 } |
65405dd90a72
Add stubs for Windows, required after CVE-2010-0825 change.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
151 |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
152 struct passwd * |
102670
06ca3efb355b
inc/sys/stat.h (struct stat): Change the types of st_uid and st_gid to unsigned.
Eli Zaretskii <eliz@gnu.org>
parents:
100958
diff
changeset
|
153 getpwuid (unsigned uid) |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
154 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
155 return NULL; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
156 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
157 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
158 char * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
159 getpass (const char * prompt) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
160 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
161 static char input[256]; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
162 HANDLE in; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
163 HANDLE err; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
164 DWORD count; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
165 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
166 in = GetStdHandle (STD_INPUT_HANDLE); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
167 err = GetStdHandle (STD_ERROR_HANDLE); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
168 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
169 if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
170 return NULL; |
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 if (WriteFile (err, prompt, strlen (prompt), &count, NULL)) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
173 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
174 int istty = (GetFileType (in) == FILE_TYPE_CHAR); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
175 DWORD old_flags; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
176 int rc; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
177 |
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 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
180 if (GetConsoleMode (in, &old_flags)) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
181 SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
182 else |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
183 istty = 0; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
184 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
185 rc = ReadFile (in, input, sizeof (input), &count, NULL); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
186 if (count >= 2 && input[count - 2] == '\r') |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
187 input[count - 2] = '\0'; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
188 else |
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 char buf[256]; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
191 while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
192 if (count >= 2 && buf[count - 2] == '\r') |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
193 break; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
194 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
195 WriteFile (err, "\r\n", 2, &count, NULL); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
196 if (istty) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
197 SetConsoleMode (in, old_flags); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
198 if (rc) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
199 return input; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
200 } |
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 return NULL; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
203 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
204 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
205 int |
102670
06ca3efb355b
inc/sys/stat.h (struct stat): Change the types of st_uid and st_gid to unsigned.
Eli Zaretskii <eliz@gnu.org>
parents:
100958
diff
changeset
|
206 fchown (int fd, unsigned uid, unsigned gid) |
15138
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 return 0; |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
209 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
210 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
211 /* 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
|
212 on network directories, so we handle that case here. |
15138
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
213 (Ulrich Leodolter, 1/11/95). */ |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
214 char * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
215 sys_ctime (const time_t *t) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
216 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
217 char *str = (char *) ctime (t); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
218 return (str ? str : "Sun Jan 01 00:00:00 1970"); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
219 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
220 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
221 FILE * |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
222 sys_fopen(const char * path, const char * mode) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
223 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
224 return fopen (path, mode); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
225 } |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
226 |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
227 int |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
228 sys_chdir (const char * path) |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
229 { |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
230 return _chdir (path); |
92326afec2a6
Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14837
diff
changeset
|
231 } |
52401 | 232 |
94823
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
233 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
|
234 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
|
235 static int init = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
236 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
237 static time_t |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
238 convert_time (FILETIME ft) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
239 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
240 long double ret; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
241 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
242 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
|
243 return 0; |
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 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
|
246 * 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
|
247 ret -= utc_base; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
248 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
|
249 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
250 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
251 static int |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
252 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
|
253 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
254 char * p = strrchr (name, '.'); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
255 return |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
256 (p != NULL |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
257 && (stricmp (p, ".exe") == 0 || |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
258 stricmp (p, ".com") == 0 || |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
259 stricmp (p, ".bat") == 0 || |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
260 stricmp (p, ".cmd") == 0)); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
261 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
262 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
263 #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
|
264 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
265 /* 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
|
266 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
|
267 int |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
268 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
|
269 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
270 WIN32_FIND_DATA wfd; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
271 HANDLE fh; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
272 int permission; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
273 int len; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
274 int rootdir = FALSE; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
275 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
|
276 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
277 if (!init) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
278 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
279 /* 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
|
280 SYSTEMTIME st; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
281 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
282 st.wYear = 1970; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
283 st.wMonth = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
284 st.wDay = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
285 st.wHour = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
286 st.wMinute = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
287 st.wSecond = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
288 st.wMilliseconds = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
289 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
290 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
|
291 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
|
292 * 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
|
293 init = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
294 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
295 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
296 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
|
297 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
298 errno = EFAULT; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
299 return -1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
300 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
301 if (_mbspbrk (path, "*?|<>\"")) |
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 errno = ENOENT; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
304 return -1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
305 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
306 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
307 strcpy (name, path); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
308 /* 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
|
309 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
|
310 separator. */ |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
311 len = strlen (name); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
312 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
|
313 || (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
|
314 if (rootdir) |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
315 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
316 if (GetDriveType (name) < 2) |
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 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 strcpy (wfd.cFileName, name); |
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 else |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
329 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
330 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
|
331 name[len - 1] = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
332 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
333 fh = FindFirstFile (name, &wfd); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
334 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
|
335 { |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
336 errno = ENOENT; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
337 return -1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
338 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
339 FindClose (fh); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
340 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
341 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
|
342 S_IFDIR : S_IFREG; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
343 buf->st_nlink = 1; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
344 buf->st_ino = 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
345 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
346 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
|
347 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
|
348 else |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
349 buf->st_dev = _getdrive (); |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
350 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
|
351 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
352 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
|
353 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
354 /* 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
361 /* determine rwx permissions */ |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
362 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
|
363 permission = S_IREAD; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
364 else |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
365 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
|
366 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
367 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
|
368 permission |= S_IEXEC; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
369 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
|
370 permission |= S_IEXEC; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
371 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
372 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
|
373 |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
374 return 0; |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
375 } |
7f11d589b5ad
Include sys/types.h, sys/stat.h, and errno.h.
Eli Zaretskii <eliz@gnu.org>
parents:
79748
diff
changeset
|
376 |
52401 | 377 /* arch-tag: 7b63fb83-70ee-4124-8822-54e53e5d0773 |
378 (do not change this comment) */ |