1 /* Utility and Unix shadow routines for GNU Emacs support programs on NT.
2 Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
22 Geoff Voelker (voelker@cs.washington.edu) 10-8-94
33 #define MAXPATHLEN _MAX_PATH
35 /* Emulate sleep...we could have done this with a define, but that
36 would necessitate including windows.h in the files that used it.
37 This is much easier. */
39 sleep(unsigned long seconds
)
41 Sleep (seconds
* 1000);
44 /* Get the current working directory. */
48 if (GetCurrentDirectory (MAXPATHLEN
, dir
) > 0)
53 static HANDLE getppid_parent
;
54 static int getppid_ppid
;
62 ppid
= getenv ("EM_PARENT_PROCESS_ID");
70 getppid_ppid
= atoi (ppid
);
75 getppid_parent
= OpenProcess (SYNCHRONIZE
, FALSE
, atoi(ppid
));
78 printf ("Failed to open handle to parent process: %d\n",
84 result
= WaitForSingleObject (getppid_parent
, 0);
88 /* The parent is still alive. */
91 /* The parent is gone. Return the pid of Unix init (1). */
95 printf ("Checking parent status failed: %d\n", GetLastError());
103 static char user_name
[256];
104 DWORD length
= sizeof (user_name
);
106 if (GetUserName (user_name
, &length
))
114 char * name
= getlogin ();
116 return strcpy (s
, name
? name
: "");
139 getpass (const char * prompt
)
141 static char input
[256];
146 in
= GetStdHandle (STD_INPUT_HANDLE
);
147 err
= GetStdHandle (STD_ERROR_HANDLE
);
149 if (in
== INVALID_HANDLE_VALUE
|| err
== INVALID_HANDLE_VALUE
)
152 if (WriteFile (err
, prompt
, strlen (prompt
), &count
, NULL
))
154 int istty
= (GetFileType (in
) == FILE_TYPE_CHAR
);
160 if (GetConsoleMode (in
, &old_flags
))
161 SetConsoleMode (in
, ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
);
165 rc
= ReadFile (in
, input
, sizeof (input
), &count
, NULL
);
166 if (count
>= 2 && input
[count
- 2] == '\r')
167 input
[count
- 2] = '\0';
171 while (ReadFile (in
, buf
, sizeof (buf
), &count
, NULL
) > 0)
172 if (count
>= 2 && buf
[count
- 2] == '\r')
175 WriteFile (err
, "\r\n", 2, &count
, NULL
);
177 SetConsoleMode (in
, old_flags
);
186 fchown (int fd
, int uid
, int gid
)
191 /* Place a wrapper around the MSVC version of ctime. It returns NULL
192 on network directories, so we handle that case here.
193 (Ulrich Leodolter, 1/11/95). */
195 sys_ctime (const time_t *t
)
197 char *str
= (char *) ctime (t
);
198 return (str
? str
: "Sun Jan 01 00:00:00 1970");
202 sys_fopen(const char * path
, const char * mode
)
204 return fopen (path
, mode
);
208 sys_chdir (const char * path
)
210 return _chdir (path
);
213 /* arch-tag: 7b63fb83-70ee-4124-8822-54e53e5d0773
214 (do not change this comment) */