annotate src/w32.c @ 15131:1cc4d788d272

Check if INSTALL_DIR is passed as an argument. ,
author Geoff Voelker <voelker@cs.washington.edu>
date Fri, 03 May 1996 18:19:57 +0000
parents 8d25697cc14b
children 6565b268b12a
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 on Windows NT.
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
4 This file is part of GNU Emacs.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
7 it under the terms of the GNU General Public License as published by
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
9 any later version.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
14 GNU General Public License for more details.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
16 You should have received a copy of the GNU General Public License
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13932
diff changeset
19 Boston, MA 02111-1307, USA.
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 Geoff Voelker (voelker@cs.washington.edu) 7-29-94
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
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
24
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
25 /* Define stat before including config.h. */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
26 #include <string.h>
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
27 #include <sys/stat.h>
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
28 #include <malloc.h>
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
29
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
30 static int is_toplevel_share_name (char *);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
31 static int stat_toplevel_share (char *, void *);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
32
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
33 int
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
34 nt_stat (char *filename, struct stat *statbuf)
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
35 {
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
36 int l = strlen (filename);
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
37 char *str = NULL;
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
38
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
39 /* stat has a bug when passed a name of a directory with a trailing
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
40 backslash (but a trailing forward slash works fine). */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
41 if (filename[l - 1] == '\\')
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
42 {
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
43 str = (char *) alloca (l + 1);
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
44 strcpy (str, filename);
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
45 str[l - 1] = '/';
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
46 return stat (str, statbuf);
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
47 }
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
48
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
49 if (stat (filename, statbuf) == 0)
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
50 return 0;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
51 else if (is_toplevel_share_name (filename))
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
52 return stat_toplevel_share (filename, statbuf);
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
53 else
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
54 return -1;
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
55 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
56
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
57 /* Place a wrapper around the NT version of ctime. It returns NULL
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
58 on network directories, so we handle that case here.
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
59 Define it before including config.h. (Ulrich Leodolter, 1/11/95). */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
60 char *
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
61 nt_ctime (const time_t *t)
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
62 {
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
63 char *str = (char *) ctime (t);
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
64 return (str ? str : "Sun Jan 01 00:00:00 1970");
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
65 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
66
12183
47685fb0fbd1 Include config.h before stdio.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12025
diff changeset
67 #include <config.h>
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 #include <windows.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 #include <stdlib.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 #include <stdio.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 #include <io.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 #include <fcntl.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 #include <ctype.h>
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 #define getwd _getwd
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 #include "lisp.h"
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 #undef getwd
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 #include <pwd.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 #include "ndir.h"
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 #include "ntheap.h"
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 extern int report_file_error (char *, Lisp_Object);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
86 /* Routines for extending stat above. */
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
87 static int
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
88 get_unassigned_drive_letter ()
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
89 {
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
90 int i;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
91 unsigned int mask;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
92
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
93 mask = GetLogicalDrives ();
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
94 for (i = 0; i < 26; i++)
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
95 {
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
96 if (mask & (1 << i))
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
97 continue;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
98 break;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
99 }
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
100 return (i == 26 ? -1 : 'A' + i);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
101 }
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
102
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
103 void dostounix_filename (char *);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
104
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
105 /* Return nonzero if NAME is of the form \\host\share (forward slashes
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
106 also valid), otherwise return 0. */
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
107 static int
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
108 is_toplevel_share_name (char *filename)
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
109 {
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
110 int len;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
111 char *name;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
112 char *host;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
113 char *share;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
114 char *suffix;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
115
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
116 len = strlen (filename);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
117 name = alloca (len + 1);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
118 strcpy (name, filename);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
119
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
120 dostounix_filename (name);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
121 if (name[0] != '/' || name[1] != '/')
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
122 return 0;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
123
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
124 host = strtok (&name[2], "/");
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
125 share = strtok (NULL, "/");
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
126 suffix = strtok (NULL, "/");
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
127 if (!host || !share || suffix)
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
128 return 0;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
129
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
130 return 1;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
131 }
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
132
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
133
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
134 /* FILENAME is of the form \\host\share, and stat can't handle names
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
135 of this form. But stat can handle \\host\share if it's been
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
136 assigned a drive letter. So we create a network connection to this
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
137 share, assign it a drive letter, stat the drive letter, and
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
138 disconnect from the share. Hassle... */
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
139 static int
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
140 stat_toplevel_share (char *filename, void *statbuf)
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
141 {
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
142 NETRESOURCE net;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
143 int drive_letter;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
144 char drive[4];
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
145 int result;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
146
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
147 drive_letter = get_unassigned_drive_letter ();
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
148 if (drive_letter < 0)
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
149 return -1;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
150
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
151 drive[0] = drive_letter;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
152 drive[1] = ':';
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
153 drive[2] = '\0';
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
154 net.dwType = RESOURCETYPE_DISK;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
155 net.lpLocalName = drive;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
156 net.lpRemoteName = filename;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
157 net.lpProvider = NULL;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
158
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
159 switch (WNetAddConnection2 (&net, NULL, NULL, 0))
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
160 {
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
161 case NO_ERROR:
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
162 break;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
163 case ERROR_ALREADY_ASSIGNED:
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
164 default:
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
165 return -1;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
166 }
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
167
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
168 /* Name the toplevel directory on the drive letter. */
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
169 drive[2] = '/';
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
170 drive[3] = '\0';
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
171 result = stat (drive, (void *) statbuf);
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
172
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
173 /* Strip the slash so we can disconnect. */
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
174 drive[2] = '\0';
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
175 if (WNetCancelConnection2 (drive, 0, TRUE) != NO_ERROR)
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
176 result = -1;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
177
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
178 return result;
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
179 }
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
180
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
181
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 /* Get the current working directory. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 getwd (char *dir)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 return GetCurrentDirectory (MAXPATHLEN, dir);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 /* Emulate gethostname. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 gethostname (char *buffer, int size)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 /* NT only allows small host names, so the buffer is
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 certainly large enough. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 return !GetComputerName (buffer, &size);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 /* Emulate getloadavg. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 getloadavg (double loadavg[], int nelem)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 int i;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 /* A faithful emulation is going to have to be saved for a rainy day. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 for (i = 0; i < nelem; i++)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 loadavg[i] = 0.0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 return i;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 /* Emulate sleep...we could have done this with a define, but that
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 would necessitate including windows.h in the files that used it.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 This is much easier. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 nt_sleep (int seconds)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 Sleep (seconds * 1000);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
14912
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
221 /* Emulate rename. */
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
222
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
223 #ifndef ENOENT
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
224 #define ENOENT 2
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
225 #endif
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
226 #ifndef EXDEV
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
227 #define EXDEV 18
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
228 #endif
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
229 #ifndef EINVAL
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
230 #define EINVAL 22
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
231 #endif
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
232
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
233 int
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
234 rename (const char *oldname, const char *newname)
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
235 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
236 #ifdef WINDOWS95
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
237 int i, len, len0, len1;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
238 char *dirs[2], *names[2], *ptr;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
239
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
240 /* A bug in MoveFile under Windows 95 incorrectly renames files in
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
241 some cases. If the old name is of the form FILENAME or
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
242 FILENAME.SUF, and the new name is of the form FILENAME~ or
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
243 FILENAME.SUF~, and both the source and target are in the same
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
244 directory, then MoveFile renames the long form of the filename to
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
245 FILENAME~ (FILENAME.SUF~) but leaves the DOS short form as
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
246 FILENAME (FILENAME.SUF). The result is that the two different
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
247 filenames refer to the same file. In this case, rename the
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
248 source to a temporary name that can then successfully be renamed
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
249 to the target. */
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
250
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
251 dirs[0] = names[0] = oldname;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
252 dirs[1] = names[1] = newname;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
253 for (i = 0; i < 2; i++)
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
254 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
255 /* Canonicalize and remove prefix. */
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
256 len = strlen (names[i]);
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
257 for (ptr = names[i] + len - 1; ptr > names[i]; ptr--)
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
258 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
259 if (IS_ANY_SEP (ptr[0]) && ptr[1] != '\0')
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
260 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
261 names[i] = ptr + 1;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
262 break;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
263 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
264 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
265 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
266
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
267 len0 = strlen (names[0]);
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
268 len1 = strlen (names[1]);
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
269
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
270 /* The predicate is whether the file is being renamed to a filename
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
271 with ~ appended. This is conservative, but should be correct. */
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
272 if ((len0 == len1 - 1)
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
273 && (names[1][len0] == '~')
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
274 && (!strnicmp (names[0], names[1], len0)))
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
275 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
276 /* Rename the source to a temporary name that can succesfully be
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
277 renamed to the target. The temporary name is in the directory
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
278 of the target. */
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
279 char *tmp, *fulltmp;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
280
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
281 tmp = "eXXXXXX";
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
282 fulltmp = alloca (strlen (dirs[1]) + strlen (tmp) + 1);
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
283 fulltmp[0] = '\0';
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
284 if (dirs[1] != names[1])
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
285 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
286 len = names[1] - dirs[1];
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
287 strncpy (fulltmp, dirs[1], len);
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
288 fulltmp[len] = '\0';
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
289 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
290 strcat (fulltmp, tmp);
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
291 mktemp (fulltmp);
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
292
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
293 if (rename (oldname, fulltmp) < 0)
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
294 return -1;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
295
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
296 oldname = fulltmp;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
297 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
298 #endif
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
299
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
300 if (!MoveFile (oldname, newname))
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
301 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
302 switch (GetLastError ())
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
303 {
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
304 case ERROR_FILE_NOT_FOUND:
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
305 errno = ENOENT;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
306 break;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
307 case ERROR_ACCESS_DENIED:
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
308 /* This gets returned when going across devices. */
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
309 errno = EXDEV;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
310 break;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
311 case ERROR_FILE_EXISTS:
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
312 case ERROR_ALREADY_EXISTS:
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
313 default:
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
314 errno = EINVAL;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
315 break;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
316 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
317 return -1;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
318 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
319 errno = 0;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
320 return 0;
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
321 }
8d25697cc14b (rename): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14246
diff changeset
322
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 /* Emulate the Unix directory procedures opendir, closedir,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 and readdir. We can't use the procedures supplied in sysdep.c,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 so we provide them here. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 struct direct dir_static; /* simulated directory contents */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 static int dir_finding;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 static HANDLE dir_find_handle;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 DIR *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 opendir (char *filename)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 DIR *dirp;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 /* Opening is done by FindFirstFile. However, a read is inherent to
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 this operation, so we have a flag to handle the open at read
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 time. This flag essentially means "there is a find-handle open and
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 it needs to be closed." */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 if (!(dirp = (DIR *) malloc (sizeof (DIR))))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 dirp->dd_fd = 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 dirp->dd_loc = 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 dirp->dd_size = 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 /* This is tacky, but we need the directory name for our
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 implementation of readdir. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 strncpy (dirp->dd_buf, filename, DIRBLKSIZ);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 return dirp;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 closedir (DIR *dirp)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 /* If we have a find-handle open, close it. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 if (dir_finding)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 FindClose (dir_find_handle);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 dir_finding = 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 xfree ((char *) dirp);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 struct direct *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 readdir (DIR *dirp)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 WIN32_FIND_DATA find_data;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 if (!dir_finding)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 char filename[MAXNAMLEN + 3];
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 int ln;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 strncpy (filename, dirp->dd_buf, MAXNAMLEN);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 ln = strlen (filename)-1;
14246
ebdd1b50daba (nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
381 if (!IS_ANY_SEP (filename[ln]))
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 strcat (filename, "\\");
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 strcat (filename, "*.*");
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 dir_find_handle = FindFirstFile (filename, &find_data);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 if (dir_find_handle == INVALID_HANDLE_VALUE)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 return NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 dir_finding = 1;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 else
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 if (!FindNextFile (dir_find_handle, &find_data))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 return NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 /* NT's unique ID for a file is 64 bits, so we have to fake it here.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 This should work as long as we never use 0. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 dir_static.d_ino = 1;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 dir_static.d_namlen - dir_static.d_namlen % 4;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 dir_static.d_namlen = strlen (find_data.cFileName);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 strncpy (dir_static.d_name, find_data.cFileName, MAXNAMLEN);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 return &dir_static;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 /* Emulate getpwuid and getpwnam. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 int getuid (); /* forward declaration */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
12451
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
415 #define PASSWD_FIELD_SIZE 256
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
416
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
417 static char the_passwd_name[PASSWD_FIELD_SIZE];
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
418 static char the_passwd_passwd[PASSWD_FIELD_SIZE];
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
419 static char the_passwd_gecos[PASSWD_FIELD_SIZE];
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
420 static char the_passwd_dir[PASSWD_FIELD_SIZE];
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
421 static char the_passwd_shell[PASSWD_FIELD_SIZE];
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 static struct passwd the_passwd =
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 the_passwd_name,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 the_passwd_passwd,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 0,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 0,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 0,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 the_passwd_gecos,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 the_passwd_dir,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 the_passwd_shell,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 };
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 struct passwd *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 getpwuid (int uid)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 {
12451
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
438 int size = PASSWD_FIELD_SIZE;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 if (!GetUserName (the_passwd.pw_name, &size))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 return NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 the_passwd.pw_passwd[0] = '\0';
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 the_passwd.pw_uid = 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 the_passwd.pw_gid = 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 strcpy (the_passwd.pw_gecos, the_passwd.pw_name);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 the_passwd.pw_dir[0] = '\0';
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 the_passwd.pw_shell[0] = '\0';
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 return &the_passwd;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 struct passwd *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 getpwnam (char *name)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 struct passwd *pw;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 pw = getpwuid (getuid ());
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 if (!pw)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 return pw;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 if (strcmp (name, pw->pw_name))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 return NULL;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 return pw;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 /* We don't have scripts to automatically determine the system configuration
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 for Emacs before it's compiled, and we don't want to have to make the
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 user enter it, so we define EMACS_CONFIGURATION to invoke this runtime
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 routine. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
474 static char configuration_buffer[32];
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 char *
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 get_emacs_configuration (void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 {
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
479 char *arch, *oem, *os;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
481 /* Determine the processor type. */
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
482 switch (get_processor_type ())
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
483 {
12451
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
484
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
485 #ifdef PROCESSOR_INTEL_386
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
486 case PROCESSOR_INTEL_386:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
487 case PROCESSOR_INTEL_486:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
488 case PROCESSOR_INTEL_PENTIUM:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
489 arch = "i386";
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
490 break;
12451
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
491 #endif
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
492
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
493 #ifdef PROCESSOR_INTEL_860
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
494 case PROCESSOR_INTEL_860:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
495 arch = "i860";
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
496 break;
12451
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
497 #endif
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
498
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
499 #ifdef PROCESSOR_MIPS_R2000
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
500 case PROCESSOR_MIPS_R2000:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
501 case PROCESSOR_MIPS_R3000:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
502 case PROCESSOR_MIPS_R4000:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
503 arch = "mips";
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
504 break;
12451
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
505 #endif
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
506
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
507 #ifdef PROCESSOR_ALPHA_21064
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
508 case PROCESSOR_ALPHA_21064:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
509 arch = "alpha";
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
510 break;
12451
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
511 #endif
4439dcb1496a (PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12183
diff changeset
512
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
513 default:
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
514 arch = "unknown";
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
515 break;
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
516 }
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
518 /* Let oem be "*" until we figure out how to decode the OEM field. */
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
519 oem = "*";
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
521 #ifdef WINDOWS95
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
522 os = "win";
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
523 #else
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
524 os = "nt";
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
525 #endif
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
526
13156
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
527 sprintf (configuration_buffer, "%s-%s-%s%d.%d", arch, oem, os,
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
528 get_nt_major_version (), get_nt_minor_version ());
a398dbd2b945 Indentation change.
Richard M. Stallman <rms@gnu.org>
parents: 12451
diff changeset
529 return configuration_buffer;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 /* Conjure up inode and device numbers that will serve the purpose
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 of Emacs. Return 1 upon success, 0 upon failure. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 get_inode_and_device_vals (Lisp_Object filename, Lisp_Object *p_inode,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 Lisp_Object *p_device)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 /* File uids on NT are found using a handle to a file, which
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 implies that it has been opened. Since we want to be able
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 to stat an arbitrary file, we must open it, get the info,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 and then close it.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 Also, NT file uids are 64-bits. This is a problem. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 HANDLE handle;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 BOOL result;
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
547 DWORD attrs;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 BY_HANDLE_FILE_INFORMATION info;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
550 /* We have to stat files and directories differently, so check
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
551 to see what filename references. */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
552 attrs = GetFileAttributes (XSTRING (filename)->data);
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
553 if (attrs == 0xFFFFFFFF) {
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
554 return 0;
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
555 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
556 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
557 /* Conjure up bogus, but unique, values. */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
558 attrs = GetTickCount ();
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
559 *p_inode = make_number (attrs);
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
560 *p_device = make_number (attrs);
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
561 return 1;
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
562 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
563
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 /* FIXME: It shouldn't be opened without READ access, but NT on x86
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 doesn't allow GetFileInfo in that case (NT on mips does). */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 handle = CreateFile (XSTRING (filename)->data,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 GENERIC_READ,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 FILE_SHARE_READ | FILE_SHARE_WRITE,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 NULL,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 OPEN_EXISTING,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 FILE_ATTRIBUTE_NORMAL,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 NULL);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 if (handle == INVALID_HANDLE_VALUE)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 result = GetFileInformationByHandle (handle, &info);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 CloseHandle (handle);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 if (!result)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 *p_inode = make_number (info.nFileIndexLow); /* use the low value */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 *p_device = make_number (info.dwVolumeSerialNumber);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 return 1;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 /* The following pipe routines are used to support our fork emulation.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 Since NT's crt dup always creates inherited handles, we
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 must be careful in setting up pipes. First create
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 non-inherited pipe handles, then create an inherited handle
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 to the write end by dup-ing it, and then close the non-inherited
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 end that was just duped. This gives us one non-inherited handle
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 on the read end and one inherited handle to the write end. As
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 the parent, we close the inherited handle to the write end after
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 spawning the child. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 /* From callproc.c */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 extern Lisp_Object Vbinary_process_input;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 extern Lisp_Object Vbinary_process_output;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 pipe_with_inherited_out (int fds[2])
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 int inherit_out;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 unsigned int flags = _O_NOINHERIT;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 if (!NILP (Vbinary_process_output))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 flags |= _O_BINARY;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 _pipe (fds, 0, flags);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 inherit_out = dup (fds[1]);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 close (fds[1]);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 fds[1] = inherit_out;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 pipe_with_inherited_in (int fds[2])
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 int inherit_in;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 unsigned int flags = _O_NOINHERIT;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 if (!NILP (Vbinary_process_input))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 flags |= _O_BINARY;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 _pipe (fds, 0, flags);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 inherit_in = dup (fds[0]);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 close (fds[0]);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 fds[0] = inherit_in;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 /* The following two routines are used to manipulate stdin, stdout, and
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 stderr of our child processes.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 Assuming that in, out, and err are inherited, we make them stdin,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 stdout, and stderr of the child as follows:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 - Save the parent's current standard handles.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 - Set the parent's standard handles to the handles being passed in.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (Note that _get_osfhandle is an io.h procedure that
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 maps crt file descriptors to NT file handles.)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 - Spawn the child, which inherits in, out, and err as stdin,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 stdout, and stderr. (see Spawnve)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 - Reset the parent's standard handles to the saved handles.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 (see reset_standard_handles)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 We assume that the caller closes in, out, and err after calling us. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 prepare_standard_handles (int in, int out, int err, HANDLE handles[4])
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 HANDLE parent, stdin_save, stdout_save, stderr_save, err_handle;
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
652
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
653 #ifdef WINDOWS95
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
654 /* The Win95 beta doesn't set the standard handles correctly.
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
655 Handicap subprocesses until we get a version that works correctly.
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
656 Undefining the subprocesses macro reveals other incompatibilities,
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
657 so, since we're expecting subprocs to work in the near future,
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
658 disable them here. */
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
659 report_file_error ("Subprocesses currently disabled on Win95", Qnil);
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
660 #endif
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
661
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 parent = GetCurrentProcess ();
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
663 stdin_save = GetStdHandle (STD_INPUT_HANDLE);
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
664 stdout_save = GetStdHandle (STD_OUTPUT_HANDLE);
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
665 stderr_save = GetStdHandle (STD_ERROR_HANDLE);
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
666
13427
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
667 #ifndef HAVE_NTGUI
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 if (!DuplicateHandle (parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 GetStdHandle (STD_INPUT_HANDLE),
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 &stdin_save,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 0,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 FALSE,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 DUPLICATE_SAME_ACCESS))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 report_file_error ("Duplicating parent's input handle", Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 if (!DuplicateHandle (parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 GetStdHandle (STD_OUTPUT_HANDLE),
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 &stdout_save,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 0,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 FALSE,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 DUPLICATE_SAME_ACCESS))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 report_file_error ("Duplicating parent's output handle", Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 if (!DuplicateHandle (parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 GetStdHandle (STD_ERROR_HANDLE),
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 &stderr_save,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 0,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 FALSE,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 DUPLICATE_SAME_ACCESS))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 report_file_error ("Duplicating parent's error handle", Qnil);
13427
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
694 #endif /* !HAVE_NTGUI */
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 if (!SetStdHandle (STD_INPUT_HANDLE, (HANDLE) _get_osfhandle (in)))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 report_file_error ("Changing stdin handle", Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 if (!SetStdHandle (STD_OUTPUT_HANDLE, (HANDLE) _get_osfhandle (out)))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 report_file_error ("Changing stdout handle", Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 /* We lose data if we use the same handle to the pipe for stdout and
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 stderr, so make a duplicate. This took a while to find. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 if (out == err)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 if (!DuplicateHandle (parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (HANDLE) _get_osfhandle (err),
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 parent,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 &err_handle,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 0,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 TRUE,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 DUPLICATE_SAME_ACCESS))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 report_file_error ("Duplicating out handle to make err handle.",
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 else
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 err_handle = (HANDLE) _get_osfhandle (err);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 if (!SetStdHandle (STD_ERROR_HANDLE, err_handle))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 report_file_error ("Changing stderr handle", Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 handles[0] = stdin_save;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 handles[1] = stdout_save;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 handles[2] = stderr_save;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 handles[3] = err_handle;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 reset_standard_handles (int in, int out, int err, HANDLE handles[4])
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 HANDLE stdin_save = handles[0];
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 HANDLE stdout_save = handles[1];
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 HANDLE stderr_save = handles[2];
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 HANDLE err_handle = handles[3];
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
737 int i;
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
738
13427
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
739 #ifndef HAVE_NTGUI
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 if (!SetStdHandle (STD_INPUT_HANDLE, stdin_save))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 report_file_error ("Resetting input handle", Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 if (!SetStdHandle (STD_OUTPUT_HANDLE, stdout_save))
11941
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
744 {
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
745 i = GetLastError ();
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
746 report_file_error ("Resetting output handle", Qnil);
cb26a4ca0e10 (configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents: 11384
diff changeset
747 }
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 if (!SetStdHandle (STD_ERROR_HANDLE, stderr_save))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 report_file_error ("Resetting error handle", Qnil);
13427
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
751 #endif /* !HAVE_NTGUI */
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 if (out == err)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 /* If out and err are the same handle, then we duplicated out
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 and stuck it in err_handle. Close the duplicate to clean up. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 if (!CloseHandle (err_handle))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 report_file_error ("Closing error handle duplicated from out.",
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 Qnil);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
763 int
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
764 random ()
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
765 {
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
766 /* rand () on NT gives us 15 random bits...hack together 30 bits. */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
767 return ((rand () << 15) | rand ());
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
768 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
769
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
770 void
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
771 srandom (int seed)
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
772 {
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
773 srand (seed);
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
774 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
775
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 /* Destructively turn backslashes into slashes. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 void
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 dostounix_filename (p)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 register char *p;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 while (*p)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 if (*p == '\\')
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 *p = '/';
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 p++;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 /* Routines that are no-ops on NT but are defined to get Emacs to compile. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 sigsetmask (int signal_mask)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 sigblock (int sig)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 kill (int pid, int signal)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 setpgrp (int pid, int gid)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 alarm (int seconds)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 unrequest_sigio (void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 request_sigio (void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 return 0;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 getuid ()
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 {
13932
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
837 char buffer[256];
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
838 int size = 256;
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
839
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
840 if (!GetUserName (buffer, &size))
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
841 /* Assume all powers upon failure. */
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
842 return 0;
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
843
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
844 if (!stricmp ("administrator", buffer))
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
845 return 0;
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
846 else
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
847 /* A complete fabrication...is there anything to base it on? */
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
848 return 123;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
851 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 geteuid ()
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853 {
13932
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
854 /* I could imagine arguing for checking to see whether the user is
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
855 in the Administrators group and returning a UID of 0 for that
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
856 case, but I don't know how wise that would be in the long run. */
de7851688890 (getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13427
diff changeset
857 return getuid ();
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
858 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 /* Remove all CR's that are followed by a LF.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 (From msdos.c...probably should figure out a way to share it,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862 although this code isn't going to ever change.) */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
864 crlf_to_lf (n, buf)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865 register int n;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866 register unsigned char *buf;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
867 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868 unsigned char *np = buf;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 unsigned char *startp = buf;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870 unsigned char *endp = buf + n;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 if (n == 0)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 return n;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 while (buf < endp - 1)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 if (*buf == 0x0d)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
878 if (*(++buf) != 0x0a)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879 *np++ = 0x0d;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 else
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 *np++ = *buf++;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 if (buf < endp)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885 *np++ = *buf++;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 return np - startp;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888
13427
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
889 #define REG_ROOT "SOFTWARE\\GNU\\Emacs\\"
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
890
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
891 LPBYTE
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
892 nt_get_resource (key, lpdwtype)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
893 char *key;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
894 LPDWORD lpdwtype;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
895 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
896 LPBYTE lpvalue;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
897 HKEY hrootkey = NULL;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
898 DWORD cbData;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
899 BOOL ok = FALSE;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
900
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
901 /* Check both the current user and the local machine to see if
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
902 we have any resources. */
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
903
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
904 if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
905 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
906 lpvalue = NULL;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
907
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
908 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
909 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
910 && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
911 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
912 return (lpvalue);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
913 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
914
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
915 if (lpvalue) xfree (lpvalue);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
916
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
917 RegCloseKey (hrootkey);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
918 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
919
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
920 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
921 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
922 lpvalue = NULL;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
923
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
924 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS &&
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
925 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
926 RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
927 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
928 return (lpvalue);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
929 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
930
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
931 if (lpvalue) xfree (lpvalue);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
932
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
933 RegCloseKey (hrootkey);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
934 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
935
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
936 return (NULL);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
937 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
938
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
939 void
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
940 init_environment ()
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
941 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
942 /* Open a console window to display messages during dumping. */
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
943 if (!initialized)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
944 AllocConsole ();
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
945
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
946 /* Check for environment variables and use registry if they don't exist */
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
947 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
948 int i;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
949 LPBYTE lpval;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
950 DWORD dwType;
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
951
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
952 static char * env_vars[] =
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
953 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
954 "emacs_path",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
955 "EMACSLOADPATH",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
956 "SHELL",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
957 "EMACSDATA",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
958 "EMACSPATH",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
959 "EMACSLOCKDIR",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
960 "INFOPATH",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
961 "EMACSDOC",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
962 "TERM",
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
963 };
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
964
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
965 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
966 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
967 if (!getenv (env_vars[i]) &&
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
968 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
969 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
970 if (dwType == REG_EXPAND_SZ)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
971 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
972 char buf1[500], buf2[500];
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
973
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
974 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, 500);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
975 _snprintf (buf2, 499, "%s=%s", env_vars[i], buf1);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
976 putenv (strdup (buf2));
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
977 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
978 else if (dwType == REG_SZ)
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
979 {
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
980 char buf[500];
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
981
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
982 _snprintf (buf, 499, "%s=%s", env_vars[i], lpval);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
983 putenv (strdup (buf));
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
984 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
985
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
986 xfree (lpval);
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
987 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
988 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
989 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
990 }
71d734525d2c (nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13156
diff changeset
991
11384
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
992 #ifdef HAVE_TIMEVAL
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
993 #include <sys/timeb.h>
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
994
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
995 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
996 void
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
997 gettimeofday (struct timeval *tv, struct timezone *tz)
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
998 {
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
999 struct _timeb tb;
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1000 _ftime (&tb);
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1001
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1002 tv->tv_sec = tb.time;
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1003 tv->tv_usec = tb.millitm * 1000L;
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1004 if (tz)
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1005 {
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1006 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1007 tz->tz_dsttime = tb.dstflag; /* type of dst correction */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1008 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1009 }
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1010 #endif /* HAVE_TIMEVAL */
1b01db213663 (nt_ctime): Defined.
Karl Heuer <kwzh@gnu.org>
parents: 9803
diff changeset
1011
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 #ifdef PIGSFLY
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 Keep this around...we might need it later.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 #ifdef WINDOWSNT
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 /*
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018 * Find the user's real name by opening the process token and looking
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 * up the name associated with the user-sid in that token.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 char b[256], Name[256], RefD[256];
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 DWORD length = 256, rlength = 256, trash;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 HANDLE Token;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 SID_NAME_USE User;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 if (1)
12025
e804b43418f6 Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents: 11941
diff changeset
1028 Vuser_real_login_name = build_string ("foo");
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 else if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &Token))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 {
12025
e804b43418f6 Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents: 11941
diff changeset
1031 Vuser_real_login_name = build_string ("unknown");
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 else if (!GetTokenInformation (Token, TokenUser, (PVOID)b, 256,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 &trash))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036 CloseHandle (Token);
12025
e804b43418f6 Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents: 11941
diff changeset
1037 Vuser_real_login_name = build_string ("unknown");
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039 else if (!LookupAccountSid ((void *)0, (PSID)b, Name, &length, RefD,
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040 &rlength, &User))
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 CloseHandle (Token);
12025
e804b43418f6 Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents: 11941
diff changeset
1043 Vuser_real_login_name = build_string ("unknown");
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 else
12025
e804b43418f6 Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents: 11941
diff changeset
1046 Vuser_real_login_name = build_string (Name);
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 #else /* not WINDOWSNT */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 #endif /* not WINDOWSNT */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 #endif /* PIGSFLY */