(quail-keyboard-layout-alist): Add an
[emacs.git] / lib-src / ntlib.c
blobd5f6177f4a269855c355100a8426c2666435de3f
1 /* Utility and Unix shadow routines for GNU Emacs support programs on NT.
2 Copyright (C) 1994 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Geoff Voelker (voelker@cs.washington.edu) 10-8-94
24 #include <windows.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <time.h>
28 #include <direct.h>
30 #include "ntlib.h"
32 #define MAXPATHLEN _MAX_PATH
34 /* Emulate sleep...we could have done this with a define, but that
35 would necessitate including windows.h in the files that used it.
36 This is much easier. */
37 void
38 sleep(int seconds)
40 Sleep (seconds * 1000);
43 /* Get the current working directory. */
44 char *
45 getwd (char *dir)
47 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0)
48 return dir;
49 return NULL;
52 int
53 getpid ()
55 return _getpid ();
58 static HANDLE getppid_parent;
59 static int getppid_ppid;
61 int
62 getppid(void)
64 char *ppid;
65 DWORD result;
67 ppid = getenv ("__PARENT_PROCESS_ID");
68 if (!ppid)
70 printf("no pid.\n");
71 return 0;
73 else
75 getppid_ppid = atoi (ppid);
78 if (!getppid_parent)
80 getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid));
81 if (!getppid_parent)
83 printf ("Failed to open handle to parent process: %d\n",
84 GetLastError());
85 exit (1);
89 result = WaitForSingleObject (getppid_parent, 0);
90 switch (result)
92 case WAIT_TIMEOUT:
93 /* The parent is still alive. */
94 return getppid_ppid;
95 case WAIT_OBJECT_0:
96 /* The parent is gone. Return the pid of Unix init (1). */
97 return 1;
98 case WAIT_FAILED:
99 default:
100 printf ("Checking parent status failed: %d\n", GetLastError());
101 exit (1);
105 char *
106 getlogin ()
108 static char user_name[256];
109 DWORD length = sizeof (user_name);
111 if (GetUserName (user_name, &length))
112 return user_name;
113 return NULL;
116 char *
117 cuserid (char * s)
119 char * name = getlogin ();
120 if (s)
121 return strcpy (s, name ? name : "");
122 return name;
126 getuid ()
128 return 0;
132 setuid (int uid)
134 return 0;
137 struct passwd *
138 getpwuid (int uid)
140 return NULL;
143 char *
144 getpass (const char * prompt)
146 static char input[256];
147 HANDLE in;
148 HANDLE err;
149 DWORD count;
151 in = GetStdHandle (STD_INPUT_HANDLE);
152 err = GetStdHandle (STD_ERROR_HANDLE);
154 if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
155 return NULL;
157 if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
159 int istty = (GetFileType (in) == FILE_TYPE_CHAR);
160 DWORD old_flags;
161 int rc;
163 if (istty)
165 if (GetConsoleMode (in, &old_flags))
166 SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
167 else
168 istty = 0;
170 rc = ReadFile (in, input, sizeof (input), &count, NULL);
171 if (count >= 2 && input[count - 2] == '\r')
172 input[count - 2] = '\0';
173 else
175 char buf[256];
176 while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0)
177 if (count >= 2 && buf[count - 2] == '\r')
178 break;
180 WriteFile (err, "\r\n", 2, &count, NULL);
181 if (istty)
182 SetConsoleMode (in, old_flags);
183 if (rc)
184 return input;
187 return NULL;
191 fchown (int fd, int uid, int gid)
193 return 0;
196 /* Place a wrapper around the MSVC version of ctime. It returns NULL
197 on network directories, so we handle that case here.
198 (Ulrich Leodolter, 1/11/95). */
199 char *
200 sys_ctime (const time_t *t)
202 char *str = (char *) ctime (t);
203 return (str ? str : "Sun Jan 01 00:00:00 1970");
206 FILE *
207 sys_fopen(const char * path, const char * mode)
209 return fopen (path, mode);
213 sys_chdir (const char * path)
215 return _chdir (path);