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. */
38 sleep(unsigned long seconds
)
40 Sleep (seconds
* 1000);
43 /* Get the current working directory. */
47 if (GetCurrentDirectory (MAXPATHLEN
, dir
) > 0)
52 static HANDLE getppid_parent
;
53 static int getppid_ppid
;
61 ppid
= getenv ("EM_PARENT_PROCESS_ID");
69 getppid_ppid
= atoi (ppid
);
74 getppid_parent
= OpenProcess (SYNCHRONIZE
, FALSE
, atoi(ppid
));
77 printf ("Failed to open handle to parent process: %d\n",
83 result
= WaitForSingleObject (getppid_parent
, 0);
87 /* The parent is still alive. */
90 /* The parent is gone. Return the pid of Unix init (1). */
94 printf ("Checking parent status failed: %d\n", GetLastError());
102 static char user_name
[256];
103 DWORD length
= sizeof (user_name
);
105 if (GetUserName (user_name
, &length
))
113 char * name
= getlogin ();
115 return strcpy (s
, name
? name
: "");
138 getpass (const char * prompt
)
140 static char input
[256];
145 in
= GetStdHandle (STD_INPUT_HANDLE
);
146 err
= GetStdHandle (STD_ERROR_HANDLE
);
148 if (in
== INVALID_HANDLE_VALUE
|| err
== INVALID_HANDLE_VALUE
)
151 if (WriteFile (err
, prompt
, strlen (prompt
), &count
, NULL
))
153 int istty
= (GetFileType (in
) == FILE_TYPE_CHAR
);
159 if (GetConsoleMode (in
, &old_flags
))
160 SetConsoleMode (in
, ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
);
164 rc
= ReadFile (in
, input
, sizeof (input
), &count
, NULL
);
165 if (count
>= 2 && input
[count
- 2] == '\r')
166 input
[count
- 2] = '\0';
170 while (ReadFile (in
, buf
, sizeof (buf
), &count
, NULL
) > 0)
171 if (count
>= 2 && buf
[count
- 2] == '\r')
174 WriteFile (err
, "\r\n", 2, &count
, NULL
);
176 SetConsoleMode (in
, old_flags
);
185 fchown (int fd
, int uid
, int gid
)
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). */
194 sys_ctime (const time_t *t
)
196 char *str
= (char *) ctime (t
);
197 return (str
? str
: "Sun Jan 01 00:00:00 1970");
201 sys_fopen(const char * path
, const char * mode
)
203 return fopen (path
, mode
);
207 sys_chdir (const char * path
)
209 return _chdir (path
);