annotate lib-src/ntlib.c @ 19507:a64e4304569b

(xrdb.o): Depend on paths.h.
author Richard M. Stallman <rms@gnu.org>
date Sun, 24 Aug 1997 16:22:56 +0000
parents e5b420bac4e9
children 4a0cf10c12f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* Utility and Unix shadow routines for GNU Emacs support programs on NT.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 Copyright (C) 1994 Free Software Foundation, Inc.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
4 This file is part of GNU Emacs.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
7 it under the terms of the GNU General Public License as published by
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
9 any later version.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
11 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
12 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
13 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
14 GNU General Public License for more details.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
16 You should have received a copy of the GNU General Public License
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
diff changeset
19 Boston, MA 02111-1307, USA.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 Geoff Voelker (voelker@cs.washington.edu) 10-8-94
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 #include <windows.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 #include <stdlib.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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>
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
29
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
30 #include "ntlib.h"
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 #define MAXPATHLEN _MAX_PATH
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 /* Emulate sleep...we could have done this with a define, but that
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 would necessitate including windows.h in the files that used it.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 This is much easier. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 void
15138
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
38 sleep(int seconds)
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 Sleep (seconds * 1000);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 /* Get the current working directory. */
15675
e5b420bac4e9 (getwd): Correct return type.
Karl Heuer <kwzh@gnu.org>
parents: 15138
diff changeset
44 char *
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 getwd (char *dir)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 {
15138
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
47 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
48 return dir;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
49 return NULL;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
14837
730a5bd19776 (getpid): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
52 int
730a5bd19776 (getpid): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
53 getpid ()
730a5bd19776 (getpid): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
54 {
730a5bd19776 (getpid): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
55 return _getpid ();
730a5bd19776 (getpid): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
56 }
730a5bd19776 (getpid): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
57
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 static HANDLE getppid_parent;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 static int getppid_ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 getppid(void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 char *ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 DWORD result;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ppid = getenv ("__PARENT_PROCESS_ID");
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 if (!ppid)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 printf("no pid.\n");
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 else
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 getppid_ppid = atoi (ppid);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 if (!getppid_parent)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid));
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 if (!getppid_parent)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 printf ("Failed to open handle to parent process: %d\n",
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 GetLastError());
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 exit (1);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 result = WaitForSingleObject (getppid_parent, 0);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 switch (result)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 case WAIT_TIMEOUT:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 /* The parent is still alive. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 return getppid_ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 case WAIT_OBJECT_0:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 /* The parent is gone. Return the pid of Unix init (1). */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 return 1;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 case WAIT_FAILED:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 default:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 printf ("Checking parent status failed: %d\n", GetLastError());
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 exit (1);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 }
15138
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 char *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
106 getlogin ()
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 static char user_name[256];
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
109 DWORD length = sizeof (user_name);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
110
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
111 if (GetUserName (user_name, &length))
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
112 return user_name;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
113 return NULL;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
114 }
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 *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
117 cuserid (char * s)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
118 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
119 char * name = getlogin ();
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
120 if (s)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
121 return strcpy (s, name ? name : "");
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
122 return name;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
123 }
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 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
126 getuid ()
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 return 0;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
129 }
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 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
132 setuid (int uid)
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 return 0;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
135 }
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 struct passwd *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
138 getpwuid (int uid)
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 return NULL;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
141 }
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 char *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
144 getpass (const char * prompt)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
145 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
146 static char input[256];
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
147 HANDLE in;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
148 HANDLE err;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
149 DWORD count;
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 in = GetStdHandle (STD_INPUT_HANDLE);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
152 err = GetStdHandle (STD_ERROR_HANDLE);
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 (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
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 if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
158 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
159 int istty = (GetFileType (in) == FILE_TYPE_CHAR);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
160 DWORD old_flags;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
161 int rc;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
162
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
163 if (istty)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
164 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
165 if (GetConsoleMode (in, &old_flags))
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
166 SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
167 else
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
168 istty = 0;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
169 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
170 rc = ReadFile (in, input, sizeof (input), &count, NULL);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
171 if (count >= 2 && input[count - 2] == '\r')
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
172 input[count - 2] = '\0';
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
173 else
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
174 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
175 char buf[256];
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
176 while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
177 if (count >= 2 && buf[count - 2] == '\r')
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
178 break;
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 WriteFile (err, "\r\n", 2, &count, NULL);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
181 if (istty)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
182 SetConsoleMode (in, old_flags);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
183 if (rc)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
184 return input;
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 return NULL;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
188 }
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 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
191 fchown (int fd, int uid, int gid)
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 return 0;
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
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
196 /* Place a wrapper around the MSVC version of ctime. It returns NULL
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
197 on network directories, so we handle that case here.
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
198 (Ulrich Leodolter, 1/11/95). */
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
199 char *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
200 sys_ctime (const time_t *t)
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 char *str = (char *) ctime (t);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
203 return (str ? str : "Sun Jan 01 00:00:00 1970");
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
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
206 FILE *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
207 sys_fopen(const char * path, const char * mode)
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 return fopen (path, mode);
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
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
212 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
213 sys_chdir (const char * path)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
214 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
215 return _chdir (path);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
216 }