diff options
| author | Karl Heuer | 1995-04-12 02:10:10 +0000 |
|---|---|---|
| committer | Karl Heuer | 1995-04-12 02:10:10 +0000 |
| commit | 35f0d4826f8ec4a541341b98d3cecb3b40e9eb7f (patch) | |
| tree | b6014b387f56bd6785c9ff0453423ea3785dc769 /src | |
| parent | ee215c7b3757bfdf42dc0a3f1da26ae656150377 (diff) | |
| download | emacs-35f0d4826f8ec4a541341b98d3cecb3b40e9eb7f.tar.gz emacs-35f0d4826f8ec4a541341b98d3cecb3b40e9eb7f.zip | |
(nt_ctime): Defined.
(gettimeofday): Defined.
(nt_stat): Defined.
(random): Defined.
(srandom): Defined.
(readdir): Include "." and "..".
(get_inode_and_device_vals): Handle directories.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 97 |
1 files changed, 86 insertions, 11 deletions
| @@ -1,11 +1,11 @@ | |||
| 1 | /* Utility and Unix shadow routines for GNU Emacs on Windows NT. | 1 | /* Utility and Unix shadow routines for GNU Emacs on Windows NT. |
| 2 | Copyright (C) 1994 Free Software Foundation, Inc. | 2 | Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is part of GNU Emacs. | 4 | This file is part of GNU Emacs. |
| 5 | 5 | ||
| 6 | GNU Emacs is free software; you can redistribute it and/or modify it | 6 | GNU Emacs is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the | 7 | under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; either version 1, or (at your option) any later | 8 | Free Software Foundation; either version 2, or (at your option) any later |
| 9 | version. | 9 | version. |
| 10 | 10 | ||
| 11 | GNU Emacs is distributed in the hope that it will be useful, but WITHOUT | 11 | GNU Emacs is distributed in the hope that it will be useful, but WITHOUT |
| @@ -20,6 +20,42 @@ | |||
| 20 | Geoff Voelker (voelker@cs.washington.edu) 7-29-94 | 20 | Geoff Voelker (voelker@cs.washington.edu) 7-29-94 |
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | /* Define stat before including config.h. */ | ||
| 24 | #include <string.h> | ||
| 25 | #include <sys/stat.h> | ||
| 26 | int | ||
| 27 | nt_stat (char *filename, struct stat *statbuf) | ||
| 28 | { | ||
| 29 | int r, l = strlen (filename); | ||
| 30 | char *str = NULL; | ||
| 31 | extern long *xmalloc (); | ||
| 32 | extern void xfree (); | ||
| 33 | |||
| 34 | /* stat has a bug when passed a name of a directory with a trailing | ||
| 35 | backslash (but a trailing forward slash works fine). */ | ||
| 36 | if (filename[l - 1] == '\\') | ||
| 37 | { | ||
| 38 | str = (char *) xmalloc (l + 1); | ||
| 39 | strcpy (str, filename); | ||
| 40 | str[l - 1] = '/'; | ||
| 41 | r = stat (str, statbuf); | ||
| 42 | xfree (str); | ||
| 43 | return r; | ||
| 44 | } | ||
| 45 | else | ||
| 46 | return stat (filename, statbuf); | ||
| 47 | } | ||
| 48 | |||
| 49 | /* Place a wrapper around the NT version of ctime. It returns NULL | ||
| 50 | on network directories, so we handle that case here. | ||
| 51 | Define it before including config.h. (Ulrich Leodolter, 1/11/95). */ | ||
| 52 | char * | ||
| 53 | nt_ctime (const time_t *t) | ||
| 54 | { | ||
| 55 | char *str = (char *) ctime (t); | ||
| 56 | return (str ? str : "Sun Jan 01 00:00:00 1970"); | ||
| 57 | } | ||
| 58 | |||
| 23 | #include <windows.h> | 59 | #include <windows.h> |
| 24 | #include <stdlib.h> | 60 | #include <stdlib.h> |
| 25 | #include <stdio.h> | 61 | #include <stdio.h> |
| @@ -153,15 +189,6 @@ readdir (DIR *dirp) | |||
| 153 | return NULL; | 189 | return NULL; |
| 154 | } | 190 | } |
| 155 | 191 | ||
| 156 | /* Don't return . or .. since it doesn't look like any of the | ||
| 157 | readdir calling code expects them. */ | ||
| 158 | while (strcmp (find_data.cFileName, ".") == 0 | ||
| 159 | || strcmp (find_data.cFileName, "..") == 0) | ||
| 160 | { | ||
| 161 | if (!FindNextFile (dir_find_handle, &find_data)) | ||
| 162 | return 0; | ||
| 163 | } | ||
| 164 | |||
| 165 | /* NT's unique ID for a file is 64 bits, so we have to fake it here. | 192 | /* NT's unique ID for a file is 64 bits, so we have to fake it here. |
| 166 | This should work as long as we never use 0. */ | 193 | This should work as long as we never use 0. */ |
| 167 | dir_static.d_ino = 1; | 194 | dir_static.d_ino = 1; |
| @@ -290,8 +317,23 @@ get_inode_and_device_vals (Lisp_Object filename, Lisp_Object *p_inode, | |||
| 290 | 317 | ||
| 291 | HANDLE handle; | 318 | HANDLE handle; |
| 292 | BOOL result; | 319 | BOOL result; |
| 320 | DWORD attrs; | ||
| 293 | BY_HANDLE_FILE_INFORMATION info; | 321 | BY_HANDLE_FILE_INFORMATION info; |
| 294 | 322 | ||
| 323 | /* We have to stat files and directories differently, so check | ||
| 324 | to see what filename references. */ | ||
| 325 | attrs = GetFileAttributes (XSTRING (filename)->data); | ||
| 326 | if (attrs == 0xFFFFFFFF) { | ||
| 327 | return 0; | ||
| 328 | } | ||
| 329 | if (attrs & FILE_ATTRIBUTE_DIRECTORY) { | ||
| 330 | /* Conjure up bogus, but unique, values. */ | ||
| 331 | attrs = GetTickCount (); | ||
| 332 | *p_inode = make_number (attrs); | ||
| 333 | *p_device = make_number (attrs); | ||
| 334 | return 1; | ||
| 335 | } | ||
| 336 | |||
| 295 | /* FIXME: It shouldn't be opened without READ access, but NT on x86 | 337 | /* FIXME: It shouldn't be opened without READ access, but NT on x86 |
| 296 | doesn't allow GetFileInfo in that case (NT on mips does). */ | 338 | doesn't allow GetFileInfo in that case (NT on mips does). */ |
| 297 | 339 | ||
| @@ -470,6 +512,19 @@ reset_standard_handles (int in, int out, int err, HANDLE handles[4]) | |||
| 470 | } | 512 | } |
| 471 | } | 513 | } |
| 472 | 514 | ||
| 515 | int | ||
| 516 | random () | ||
| 517 | { | ||
| 518 | /* rand () on NT gives us 15 random bits...hack together 30 bits. */ | ||
| 519 | return ((rand () << 15) | rand ()); | ||
| 520 | } | ||
| 521 | |||
| 522 | void | ||
| 523 | srandom (int seed) | ||
| 524 | { | ||
| 525 | srand (seed); | ||
| 526 | } | ||
| 527 | |||
| 473 | /* Destructively turn backslashes into slashes. */ | 528 | /* Destructively turn backslashes into slashes. */ |
| 474 | void | 529 | void |
| 475 | dostounix_filename (p) | 530 | dostounix_filename (p) |
| @@ -569,6 +624,26 @@ crlf_to_lf (n, buf) | |||
| 569 | return np - startp; | 624 | return np - startp; |
| 570 | } | 625 | } |
| 571 | 626 | ||
| 627 | #ifdef HAVE_TIMEVAL | ||
| 628 | #include <sys/timeb.h> | ||
| 629 | |||
| 630 | /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */ | ||
| 631 | void | ||
| 632 | gettimeofday (struct timeval *tv, struct timezone *tz) | ||
| 633 | { | ||
| 634 | struct _timeb tb; | ||
| 635 | _ftime (&tb); | ||
| 636 | |||
| 637 | tv->tv_sec = tb.time; | ||
| 638 | tv->tv_usec = tb.millitm * 1000L; | ||
| 639 | if (tz) | ||
| 640 | { | ||
| 641 | tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */ | ||
| 642 | tz->tz_dsttime = tb.dstflag; /* type of dst correction */ | ||
| 643 | } | ||
| 644 | } | ||
| 645 | #endif /* HAVE_TIMEVAL */ | ||
| 646 | |||
| 572 | 647 | ||
| 573 | #ifdef PIGSFLY | 648 | #ifdef PIGSFLY |
| 574 | Keep this around...we might need it later. | 649 | Keep this around...we might need it later. |