Update FSF's address in the preamble.
[bpt/emacs.git] / lib-src / ntlib.c
1 /* Utility and Unix shadow routines for GNU Emacs support programs on NT.
2 Copyright (C) 1994 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
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.
10
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.
15
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.
20
21 Geoff Voelker (voelker@cs.washington.edu) 10-8-94
22 */
23
24 #include <windows.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27
28 #define MAXPATHLEN _MAX_PATH
29
30 /* Emulate sleep...we could have done this with a define, but that
31 would necessitate including windows.h in the files that used it.
32 This is much easier. */
33 void
34 nt_sleep(int seconds)
35 {
36 Sleep (seconds * 1000);
37 }
38
39 /* Get the current working directory. */
40 int
41 getwd (char *dir)
42 {
43 return GetCurrentDirectory (MAXPATHLEN, dir);
44 }
45
46 static HANDLE getppid_parent;
47 static int getppid_ppid;
48
49 int
50 getppid(void)
51 {
52 char *ppid;
53 DWORD result;
54
55 ppid = getenv ("__PARENT_PROCESS_ID");
56 if (!ppid)
57 {
58 printf("no pid.\n");
59 return 0;
60 }
61 else
62 {
63 getppid_ppid = atoi (ppid);
64 }
65
66 if (!getppid_parent)
67 {
68 getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid));
69 if (!getppid_parent)
70 {
71 printf ("Failed to open handle to parent process: %d\n",
72 GetLastError());
73 exit (1);
74 }
75 }
76
77 result = WaitForSingleObject (getppid_parent, 0);
78 switch (result)
79 {
80 case WAIT_TIMEOUT:
81 /* The parent is still alive. */
82 return getppid_ppid;
83 case WAIT_OBJECT_0:
84 /* The parent is gone. Return the pid of Unix init (1). */
85 return 1;
86 case WAIT_FAILED:
87 default:
88 printf ("Checking parent status failed: %d\n", GetLastError());
89 exit (1);
90 }
91 }