annotate lib-src/ntlib.c @ 54341:80dfe07a1d65

New file (image.c) for Image consolidation: (COLOR_TABLE_SUPPORT): New define to control whether color table support is available (X only). (Bitmap_Record): Common name for x_bitmap_record, w32_bitmap_record, and mac_bitmap_record. (XImagePtr): Common name for pointer to XImage or equivalent. (XImagePtr_or_DC): New type to simplify code sharing; equivalent to XImagePtr on X+MAC, and to HDC on W32. (GET_PIXEL): Wrapper for XGetPixel or equivalent. (NO_PIXMAP): Common name for "None" or equivalent. (PNG_BG_COLOR_SHIFT): Bits to shift PNG background colors. (RGB_PIXEL_COLOR): Common type for an integer "pixel color" value. (PIX_MASK_RETAIN, PIX_MASK_DRAW): Portability macros (from macfns.c). (FRAME_X_VISUAL, x_defined_color, DefaultDepthOfScreen): Define with suitable equivalents on W32 and MAC for code sharing. (XDrawLine): Define on MAC for code sharing. (Destroy_Image, Free_Pixmap): Wrappers for code sharing. (IF_LIB_AVAILABLE): Macro to simplify code sharing. (Vx_bitmap_file_path, Vimage_cache_eviction_delay) (x_bitmap_height, x_bitmap_width, x_bitmap_pixmap) (x_reference_bitmap, x_create_bitmap_from_data) (x_create_bitmap_from_file, x_destroy_bitmap) (x_destroy_all_bitmaps, x_create_bitmap_mask) (XGetImage, XPutPixel, XGetPixel, XDestroyImage) (QCascent, QCmargin, QCrelief, QCconversion, QCcolor_symbols) (QCheuristic_mask, QCindex, QCmatrix, QCcolor_adjustment, QCmask) (Qlaplace, Qemboss, Qedge_detection, Qheuristic, Qcenter) (define_image_type, lookup_image_type, valid_image_p) (image_error, enum image_value_type, struct image_keyword) (parse_image_spec, image_spec_value, Fimage_size, Fimage_mask_p) (make_image, free_image, prepare_image_for_display, image_ascent) (four_corners_best, image_background, image_background_transparent) (x_clear_image_1, x_clear_image, x_alloc_image_color) (make_image_cache, free_image_cache, clear_image_cache) (Fclear_image_cache, postprocess_image, lookup_image, cache_image) (forall_images_in_image_cache, x_create_x_image_and_pixmap) (x_destroy_x_image, x_put_x_image, x_find_image_file, slurp_file) (find_image_fsspec, image_load_qt_1, image_load_quicktime) (init_image_func_pointer, image_load_quartz2d) (struct ct_color, init_color_table, free_color_table) (lookup_rgb_color, lookup_pixel_color, colors_in_color_table) (cross_disabled_images, x_to_xcolors, x_from_xcolors) (x_detect_edges, x_emboss, x_laplace, x_edge_detection) (x_disable_image, x_build_heuristic_mask) (XBM support, XPM support, PBM support, PNG support, JPEG support) (TIFF support, GIF support, Ghostscript support): Consolidate image code from xfns.c, w32fns.c, and macfns.c. (syms_of_image): Consolidate image related symbol setup here. (init_image): Consolidate image related initializations here.
author Kim F. Storm <storm@cua.dk>
date Thu, 11 Mar 2004 00:28:24 +0000
parents 695cf19ef79e
children 23a17af379b1 375f2633d815
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* Utility and Unix shadow routines for GNU Emacs support programs on NT.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 Copyright (C) 1994 Free Software Foundation, Inc.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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: 9803
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) 10-8-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
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 #include <windows.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 #include <stdlib.h>
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 #include <stdio.h>
15138
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
27 #include <time.h>
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
28 #include <direct.h>
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
29
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
30 #include "ntlib.h"
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 #define MAXPATHLEN _MAX_PATH
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 /* Emulate sleep...we could have done this with a define, but that
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 would necessitate including windows.h in the files that used it.
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 This is much easier. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 void
31081
1fd32e8a2fad (sleep): Make argument unsigned long.
Andrew Innes <andrewi@gnu.org>
parents: 22296
diff changeset
38 sleep(unsigned long seconds)
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 Sleep (seconds * 1000);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 /* Get the current working directory. */
15675
e5b420bac4e9 (getwd): Correct return type.
Karl Heuer <kwzh@gnu.org>
parents: 15138
diff changeset
44 char *
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 getwd (char *dir)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 {
15138
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
47 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
48 return dir;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
49 return NULL;
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 static HANDLE getppid_parent;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 static int getppid_ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 int
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 getppid(void)
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 char *ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 DWORD result;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
22296
b58a79fe0af2 (getppid): Look for EM_PARENT_PROCESS_ID.
Geoff Voelker <voelker@cs.washington.edu>
parents: 19694
diff changeset
61 ppid = getenv ("EM_PARENT_PROCESS_ID");
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 31081
diff changeset
62 if (!ppid)
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 printf("no pid.\n");
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 return 0;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 31081
diff changeset
66 }
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 31081
diff changeset
67 else
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 getppid_ppid = atoi (ppid);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 31081
diff changeset
72 if (!getppid_parent)
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi(ppid));
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 31081
diff changeset
75 if (!getppid_parent)
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 printf ("Failed to open handle to parent process: %d\n",
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 GetLastError());
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 exit (1);
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 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 result = WaitForSingleObject (getppid_parent, 0);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 31081
diff changeset
84 switch (result)
9803
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 {
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 case WAIT_TIMEOUT:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 /* The parent is still alive. */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 return getppid_ppid;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 case WAIT_OBJECT_0:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 /* The parent is gone. Return the pid of Unix init (1). */
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 return 1;
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 case WAIT_FAILED:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 default:
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 printf ("Checking parent status failed: %d\n", GetLastError());
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 exit (1);
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 }
fa698fd10c05 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 }
15138
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
98
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
99 char *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
100 getlogin ()
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
101 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
102 static char user_name[256];
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
103 DWORD length = sizeof (user_name);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
104
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
105 if (GetUserName (user_name, &length))
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
106 return user_name;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
107 return NULL;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
108 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
109
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
110 char *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
111 cuserid (char * s)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
112 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
113 char * name = getlogin ();
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
114 if (s)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
115 return strcpy (s, name ? name : "");
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
116 return name;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
117 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
118
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
119 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
120 getuid ()
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
121 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
122 return 0;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
123 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
124
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
125 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
126 setuid (int uid)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
127 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
128 return 0;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
129 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
130
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
131 struct passwd *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
132 getpwuid (int uid)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
133 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
134 return NULL;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
135 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
136
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
137 char *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
138 getpass (const char * prompt)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
139 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
140 static char input[256];
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
141 HANDLE in;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
142 HANDLE err;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
143 DWORD count;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
144
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
145 in = GetStdHandle (STD_INPUT_HANDLE);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
146 err = GetStdHandle (STD_ERROR_HANDLE);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
147
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
148 if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
149 return NULL;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
150
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
151 if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
152 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
153 int istty = (GetFileType (in) == FILE_TYPE_CHAR);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
154 DWORD old_flags;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
155 int rc;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
156
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
157 if (istty)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
158 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
159 if (GetConsoleMode (in, &old_flags))
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
160 SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
161 else
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
162 istty = 0;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
163 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
164 rc = ReadFile (in, input, sizeof (input), &count, NULL);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
165 if (count >= 2 && input[count - 2] == '\r')
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
166 input[count - 2] = '\0';
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
167 else
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
168 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
169 char buf[256];
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
170 while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
171 if (count >= 2 && buf[count - 2] == '\r')
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
172 break;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
173 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
174 WriteFile (err, "\r\n", 2, &count, NULL);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
175 if (istty)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
176 SetConsoleMode (in, old_flags);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
177 if (rc)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
178 return input;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
179 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
180
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
181 return NULL;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
182 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
183
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
184 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
185 fchown (int fd, int uid, int gid)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
186 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
187 return 0;
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
188 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
189
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
190 /* Place a wrapper around the MSVC version of ctime. It returns NULL
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 31081
diff changeset
191 on network directories, so we handle that case here.
15138
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
192 (Ulrich Leodolter, 1/11/95). */
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
193 char *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
194 sys_ctime (const time_t *t)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
195 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
196 char *str = (char *) ctime (t);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
197 return (str ? str : "Sun Jan 01 00:00:00 1970");
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
198 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
199
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
200 FILE *
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
201 sys_fopen(const char * path, const char * mode)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
202 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
203 return fopen (path, mode);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
204 }
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
205
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
206 int
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
207 sys_chdir (const char * path)
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
208 {
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
209 return _chdir (path);
92326afec2a6 Include ntlib.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14837
diff changeset
210 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
211
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
212 /* arch-tag: 7b63fb83-70ee-4124-8822-54e53e5d0773
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
213 (do not change this comment) */