(message-font-lock-keywords): Match a final newline
[emacs.git] / lib-src / ntlib.c
blob3e2caf508656a43c1991914552610486d2181017
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(unsigned long 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 static HANDLE getppid_parent;
53 static int getppid_ppid;
55 int
56 getppid(void)
58 char *ppid;
59 DWORD result;
61 ppid = getenv ("EM_PARENT_PROCESS_ID");
62 if (!ppid)
64 printf("no pid.\n");
65 return 0;
67 else
69 getppid_ppid = atoi (ppid);
72 if (!getppid_parent)
74 getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid));
75 if (!getppid_parent)
77 printf ("Failed to open handle to parent process: %d\n",
78 GetLastError());
79 exit (1);
83 result = WaitForSingleObject (getppid_parent, 0);
84 switch (result)
86 case WAIT_TIMEOUT:
87 /* The parent is still alive. */
88 return getppid_ppid;
89 case WAIT_OBJECT_0:
90 /* The parent is gone. Return the pid of Unix init (1). */
91 return 1;
92 case WAIT_FAILED:
93 default:
94 printf ("Checking parent status failed: %d\n", GetLastError());
95 exit (1);
99 char *
100 getlogin ()
102 static char user_name[256];
103 DWORD length = sizeof (user_name);
105 if (GetUserName (user_name, &length))
106 return user_name;
107 return NULL;
110 char *
111 cuserid (char * s)
113 char * name = getlogin ();
114 if (s)
115 return strcpy (s, name ? name : "");
116 return name;
120 getuid ()
122 return 0;
126 setuid (int uid)
128 return 0;
131 struct passwd *
132 getpwuid (int uid)
134 return NULL;
137 char *
138 getpass (const char * prompt)
140 static char input[256];
141 HANDLE in;
142 HANDLE err;
143 DWORD count;
145 in = GetStdHandle (STD_INPUT_HANDLE);
146 err = GetStdHandle (STD_ERROR_HANDLE);
148 if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
149 return NULL;
151 if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
153 int istty = (GetFileType (in) == FILE_TYPE_CHAR);
154 DWORD old_flags;
155 int rc;
157 if (istty)
159 if (GetConsoleMode (in, &old_flags))
160 SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
161 else
162 istty = 0;
164 rc = ReadFile (in, input, sizeof (input), &count, NULL);
165 if (count >= 2 && input[count - 2] == '\r')
166 input[count - 2] = '\0';
167 else
169 char buf[256];
170 while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0)
171 if (count >= 2 && buf[count - 2] == '\r')
172 break;
174 WriteFile (err, "\r\n", 2, &count, NULL);
175 if (istty)
176 SetConsoleMode (in, old_flags);
177 if (rc)
178 return input;
181 return NULL;
185 fchown (int fd, int uid, int gid)
187 return 0;
190 /* Place a wrapper around the MSVC version of ctime. It returns NULL
191 on network directories, so we handle that case here.
192 (Ulrich Leodolter, 1/11/95). */
193 char *
194 sys_ctime (const time_t *t)
196 char *str = (char *) ctime (t);
197 return (str ? str : "Sun Jan 01 00:00:00 1970");
200 FILE *
201 sys_fopen(const char * path, const char * mode)
203 return fopen (path, mode);
207 sys_chdir (const char * path)
209 return _chdir (path);