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)
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
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. */
40 Sleep (seconds
* 1000);
43 /* Get the current working directory. */
47 if (GetCurrentDirectory (MAXPATHLEN
, dir
) > 0)
58 static HANDLE getppid_parent
;
59 static int getppid_ppid
;
67 ppid
= getenv ("__PARENT_PROCESS_ID");
75 getppid_ppid
= atoi (ppid
);
80 getppid_parent
= OpenProcess (SYNCHRONIZE
, FALSE
, atoi(ppid
));
83 printf ("Failed to open handle to parent process: %d\n",
89 result
= WaitForSingleObject (getppid_parent
, 0);
93 /* The parent is still alive. */
96 /* The parent is gone. Return the pid of Unix init (1). */
100 printf ("Checking parent status failed: %d\n", GetLastError());
108 static char user_name
[256];
109 DWORD length
= sizeof (user_name
);
111 if (GetUserName (user_name
, &length
))
119 char * name
= getlogin ();
121 return strcpy (s
, name
? name
: "");
144 getpass (const char * prompt
)
146 static char input
[256];
151 in
= GetStdHandle (STD_INPUT_HANDLE
);
152 err
= GetStdHandle (STD_ERROR_HANDLE
);
154 if (in
== INVALID_HANDLE_VALUE
|| err
== INVALID_HANDLE_VALUE
)
157 if (WriteFile (err
, prompt
, strlen (prompt
), &count
, NULL
))
159 int istty
= (GetFileType (in
) == FILE_TYPE_CHAR
);
165 if (GetConsoleMode (in
, &old_flags
))
166 SetConsoleMode (in
, ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
);
170 rc
= ReadFile (in
, input
, sizeof (input
), &count
, NULL
);
171 if (count
>= 2 && input
[count
- 2] == '\r')
172 input
[count
- 2] = '\0';
176 while (ReadFile (in
, buf
, sizeof (buf
), &count
, NULL
) > 0)
177 if (count
>= 2 && buf
[count
- 2] == '\r')
180 WriteFile (err
, "\r\n", 2, &count
, NULL
);
182 SetConsoleMode (in
, old_flags
);
191 fchown (int fd
, int uid
, int gid
)
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). */
200 sys_ctime (const time_t *t
)
202 char *str
= (char *) ctime (t
);
203 return (str
? str
: "Sun Jan 01 00:00:00 1970");
207 sys_fopen(const char * path
, const char * mode
)
209 return fopen (path
, mode
);
213 sys_chdir (const char * path
)
215 return _chdir (path
);