diff options
| author | Geoff Voelker | 1996-05-03 18:28:37 +0000 |
|---|---|---|
| committer | Geoff Voelker | 1996-05-03 18:28:37 +0000 |
| commit | 14f29224a0377ecf267326c3d64bf67c6795b378 (patch) | |
| tree | d4a5d70c7749e6fc47804ae5e7d1535c5ed6c49f /lib-src | |
| parent | c81ebaba0abaa1607bbbd291dd4af69463864b7d (diff) | |
| download | emacs-14f29224a0377ecf267326c3d64bf67c6795b378.tar.gz emacs-14f29224a0377ecf267326c3d64bf67c6795b378.zip | |
Include ntlib.h.
(nt_sleep): Rename to sleep.
(getwd): Return directory.
(getlogin, cuserid, getuid, setuid, getpwuid, getpass, fchown,
sys_ctime, sys_fopen): New functions.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/ntlib.c | 123 |
1 files changed, 121 insertions, 2 deletions
diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c index dd294a5a149..5acc8363437 100644 --- a/lib-src/ntlib.c +++ b/lib-src/ntlib.c | |||
| @@ -24,6 +24,10 @@ Boston, MA 02111-1307, USA. | |||
| 24 | #include <windows.h> | 24 | #include <windows.h> |
| 25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> | 26 | #include <stdio.h> |
| 27 | #include <time.h> | ||
| 28 | #include <direct.h> | ||
| 29 | |||
| 30 | #include "ntlib.h" | ||
| 27 | 31 | ||
| 28 | #define MAXPATHLEN _MAX_PATH | 32 | #define MAXPATHLEN _MAX_PATH |
| 29 | 33 | ||
| @@ -31,7 +35,7 @@ Boston, MA 02111-1307, USA. | |||
| 31 | would necessitate including windows.h in the files that used it. | 35 | would necessitate including windows.h in the files that used it. |
| 32 | This is much easier. */ | 36 | This is much easier. */ |
| 33 | void | 37 | void |
| 34 | nt_sleep(int seconds) | 38 | sleep(int seconds) |
| 35 | { | 39 | { |
| 36 | Sleep (seconds * 1000); | 40 | Sleep (seconds * 1000); |
| 37 | } | 41 | } |
| @@ -40,7 +44,9 @@ nt_sleep(int seconds) | |||
| 40 | int | 44 | int |
| 41 | getwd (char *dir) | 45 | getwd (char *dir) |
| 42 | { | 46 | { |
| 43 | return GetCurrentDirectory (MAXPATHLEN, dir); | 47 | if (GetCurrentDirectory (MAXPATHLEN, dir) > 0) |
| 48 | return dir; | ||
| 49 | return NULL; | ||
| 44 | } | 50 | } |
| 45 | 51 | ||
| 46 | int | 52 | int |
| @@ -95,3 +101,116 @@ getppid(void) | |||
| 95 | exit (1); | 101 | exit (1); |
| 96 | } | 102 | } |
| 97 | } | 103 | } |
| 104 | |||
| 105 | char * | ||
| 106 | getlogin () | ||
| 107 | { | ||
| 108 | static char user_name[256]; | ||
| 109 | DWORD length = sizeof (user_name); | ||
| 110 | |||
| 111 | if (GetUserName (user_name, &length)) | ||
| 112 | return user_name; | ||
| 113 | return NULL; | ||
| 114 | } | ||
| 115 | |||
| 116 | char * | ||
| 117 | cuserid (char * s) | ||
| 118 | { | ||
| 119 | char * name = getlogin (); | ||
| 120 | if (s) | ||
| 121 | return strcpy (s, name ? name : ""); | ||
| 122 | return name; | ||
| 123 | } | ||
| 124 | |||
| 125 | int | ||
| 126 | getuid () | ||
| 127 | { | ||
| 128 | return 0; | ||
| 129 | } | ||
| 130 | |||
| 131 | int | ||
| 132 | setuid (int uid) | ||
| 133 | { | ||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | struct passwd * | ||
| 138 | getpwuid (int uid) | ||
| 139 | { | ||
| 140 | return NULL; | ||
| 141 | } | ||
| 142 | |||
| 143 | char * | ||
| 144 | getpass (const char * prompt) | ||
| 145 | { | ||
| 146 | static char input[256]; | ||
| 147 | HANDLE in; | ||
| 148 | HANDLE err; | ||
| 149 | DWORD count; | ||
| 150 | |||
| 151 | in = GetStdHandle (STD_INPUT_HANDLE); | ||
| 152 | err = GetStdHandle (STD_ERROR_HANDLE); | ||
| 153 | |||
| 154 | if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE) | ||
| 155 | return NULL; | ||
| 156 | |||
| 157 | if (WriteFile (err, prompt, strlen (prompt), &count, NULL)) | ||
| 158 | { | ||
| 159 | int istty = (GetFileType (in) == FILE_TYPE_CHAR); | ||
| 160 | DWORD old_flags; | ||
| 161 | int rc; | ||
| 162 | |||
| 163 | if (istty) | ||
| 164 | { | ||
| 165 | if (GetConsoleMode (in, &old_flags)) | ||
| 166 | SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); | ||
| 167 | else | ||
| 168 | istty = 0; | ||
| 169 | } | ||
| 170 | rc = ReadFile (in, input, sizeof (input), &count, NULL); | ||
| 171 | if (count >= 2 && input[count - 2] == '\r') | ||
| 172 | input[count - 2] = '\0'; | ||
| 173 | else | ||
| 174 | { | ||
| 175 | char buf[256]; | ||
| 176 | while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0) | ||
| 177 | if (count >= 2 && buf[count - 2] == '\r') | ||
| 178 | break; | ||
| 179 | } | ||
| 180 | WriteFile (err, "\r\n", 2, &count, NULL); | ||
| 181 | if (istty) | ||
| 182 | SetConsoleMode (in, old_flags); | ||
| 183 | if (rc) | ||
| 184 | return input; | ||
| 185 | } | ||
| 186 | |||
| 187 | return NULL; | ||
| 188 | } | ||
| 189 | |||
| 190 | int | ||
| 191 | fchown (int fd, int uid, int gid) | ||
| 192 | { | ||
| 193 | return 0; | ||
| 194 | } | ||
| 195 | |||
| 196 | /* Place a wrapper around the MSVC version of ctime. It returns NULL | ||
| 197 | on network directories, so we handle that case here. | ||
| 198 | (Ulrich Leodolter, 1/11/95). */ | ||
| 199 | char * | ||
| 200 | sys_ctime (const time_t *t) | ||
| 201 | { | ||
| 202 | char *str = (char *) ctime (t); | ||
| 203 | return (str ? str : "Sun Jan 01 00:00:00 1970"); | ||
| 204 | } | ||
| 205 | |||
| 206 | FILE * | ||
| 207 | sys_fopen(const char * path, const char * mode) | ||
| 208 | { | ||
| 209 | return fopen (path, mode); | ||
| 210 | } | ||
| 211 | |||
| 212 | int | ||
| 213 | sys_chdir (const char * path) | ||
| 214 | { | ||
| 215 | return _chdir (path); | ||
| 216 | } | ||