annotate lib-src/ntlib.c @ 13020:a656ccd43989

(gettimeofday): Don't bother setting time zone, since nobody uses it, and our hacks to get it get in the way of the above fix. Use simpler method for getting time stamp. (init_gettimeofday, daylight, gmtoffset): Remove.
author Richard M. Stallman <rms@gnu.org>
date Sun, 10 Sep 1995 04:37:51 +0000
parents fa698fd10c05
children ee40177f6c68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* Utility and Unix shadow routines for GNU Emacs support programs on NT.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 Copyright (C) 1994 Free Software Foundation, Inc.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 This file is part of GNU Emacs.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify it
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any later
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 version.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful, but WITHOUT
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 more details.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License along
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 with GNU Emacs; see the file COPYING. If not, write to the Free Software
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 Geoff Voelker (voelker@cs.washington.edu) 10-8-94
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 #include <windows.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 #include <stdlib.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 #include <stdio.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 #define MAXPATHLEN _MAX_PATH
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 /* Emulate sleep...we could have done this with a define, but that
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 would necessitate including windows.h in the files that used it.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 This is much easier. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 nt_sleep(int seconds)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 Sleep (seconds * 1000);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 /* Get the current working directory. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 getwd (char *dir)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 return GetCurrentDirectory (MAXPATHLEN, dir);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 static HANDLE getppid_parent;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 static int getppid_ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 getppid(void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 char *ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 DWORD result;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ppid = getenv ("__PARENT_PROCESS_ID");
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 if (!ppid)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 printf("no pid.\n");
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 else
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 getppid_ppid = atoi (ppid);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 if (!getppid_parent)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid));
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 if (!getppid_parent)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 printf ("Failed to open handle to parent process: %d\n",
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 GetLastError());
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 exit (1);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 result = WaitForSingleObject (getppid_parent, 0);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 switch (result)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 case WAIT_TIMEOUT:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 /* The parent is still alive. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 return getppid_ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 case WAIT_OBJECT_0:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 /* The parent is gone. Return the pid of Unix init (1). */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 return 1;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 case WAIT_FAILED:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 default:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 printf ("Checking parent status failed: %d\n", GetLastError());
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 exit (1);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 }