1994-11-01 10:27:02 +00:00
|
|
|
/* Utility and Unix shadow routines for GNU Emacs support programs on NT.
|
2012-08-09 23:59:38 +00:00
|
|
|
|
2016-01-01 09:16:19 +00:00
|
|
|
Copyright (C) 1994, 2001-2016 Free Software Foundation, Inc.
|
2012-08-09 23:59:38 +00:00
|
|
|
|
|
|
|
Author: Geoff Voelker (voelker@cs.washington.edu)
|
|
|
|
Created: 10-8-94
|
1994-11-01 10:27:02 +00:00
|
|
|
|
1996-01-15 09:18:04 +00:00
|
|
|
This file is part of GNU Emacs.
|
|
|
|
|
2008-05-09 23:19:13 +00:00
|
|
|
GNU Emacs is free software: you can redistribute it and/or modify
|
1996-01-15 09:18:04 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2008-05-09 23:19:13 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
1996-01-15 09:18:04 +00:00
|
|
|
|
|
|
|
GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2012-08-09 23:59:38 +00:00
|
|
|
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
|
1994-11-01 10:27:02 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
1996-05-03 18:28:37 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <direct.h>
|
2008-05-09 20:37:32 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
2011-03-23 16:25:38 +00:00
|
|
|
#include <ctype.h>
|
Support x64 build on MS-Windows with MSVC.
src/w32term.h (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK): Define for x64.
(SET_SCROLL_BAR_W32_WINDOW): Cast ID to intptr_t, for
compatibility with x64.
src/w32term.c (w32_draw_underwave): Don't use GCC extensions for
defining an XRectangle structure.
src/w32proc.c (RVA_TO_PTR, w32_executable_type): Fix pointer
arithmetics for compatibility with x64.
src/w32menu.c (add_menu_item): Use UINT_PTR instead of UINT, for
compatibility with x64.
src/w32heap.h: Adjust prototypes and declarations.
src/w32heap.c (RVA_TO_PTR, allocate_heap, sbrk, init_heap)
(round_heap): Use DWORD_PTR, ptrdiff_t and size_t instead of
DWORD, long, and unsigned long, for compatibility with x64.
(allocate_heap) [_WIN64]: Reserve 32GB of memory.
(sbrk): Argument is now of type ptrdiff_t.
src/w32fns.c (HMONITOR): Condition declaration on _WIN32_WINNT being
less than 0x0500.
(w32_msg_pump): Use WPARAM type for 'result'.
src/w32.c (init_environment, get_emacs_configuration): Support AMD64
architecture.
(init_ntproc): Cast arguments of _open_osfhandle to intptr_t, for
compatibility with x64.
src/vm-limit.c (lim_data): Now size_t.
(check_memory_limits): Adjust prototypes of real_morecore and
__morecore to receive argument of type ptrdiff_t. Use size_t for
five_percent and data_size.
src/unexw32.c: Use DWORD_PTR instead of DWORD for file-scope
variables, for compatibility with x64.
(rva_to_section, offset_to_section, relocate_offset)
(OFFSET_TO_RVA, RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET)
(PTR_TO_RVA, RVA_TO_PTR, OFFSET_TO_PTR, get_section_info)
(copy_executable_and_dump_data): Use DWORD_PTR instead of DWORD
for compatibility with x64.
src/sysdep.c (STDERR_FILENO): Define if not already defined.
src/ralloc.c (real_morecore): Argument type is now ptrdiff_t.
(__morecore): Argument type is now ptrdiff_t.
(ROUNDUP, MEM_ROUNDUP): Use size_t instead of 'unsigned long'.
(relinquish): Use ptrdiff_t type for 'excess'.
(r_alloc_sbrk): Argument type is now ptrdiff_t.
src/makefile.w32-in (HEAPSIZE): Get value from EMACS_HEAPSIZE.
(bootstrap-temacs-CMD, bootstrap-temacs-SH): Use $(EMACS_PURESIZE)
instead of a literal number.
src/gmalloc.c [WINDOWSNT]: Include w32heap.h.
(min): Define only if not already defined.
src/frame.c (x_report_frame_params): Use EMACS_UINT for the return
value of FRAME_X_WINDOW, to fit a 64-bit pointer on 64-bit Windows
hosts.
src/image.c (x_bitmap_pixmap): Return ptrdiff_t, not int, since
'bitmaps' is a pointer.
src/dispextern.h (x_bitmap_pixmap): Adjust prototype.
src/alloc.c (gdb_make_enums_visible): Now conditional on __GNUC__.
nt/makefile.w32-in ($(TRES)): Use $(EMACS_MANIFEST).
nt/inc/sys/socket.h: Don't map Winsock error codes to standard ones
that are already defined.
nt/inc/ms-w32.h (EMACS_INT, EMACS_UINT, EMACS_INT_MAX, PRIuMAX)
(pI, _INTPTR) [_MSC_VER]: Fix definitions for MSVC.
[_MSC_VER]: Add pragmas to suppress some MSVC warnings.
nt/preprep.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_move_sections, ADJUST_IMPORT_RVA, main): Use
DWORD_PTR instead of DWORD for compatibility with x64.
nt/nmake.defs: Support AMD64.
(EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST): New macros.
nt/gmake.defs: (EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST):
New macros.
nt/addsection.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_add_section, main): Use DWORD_PTR instead of
DWORD, for compatibility with x64.
nt/emacs-x64.manifest: New file.
nt/emacs-x86.manifest: Renamed from emacs.manifest.
lib-src/ntlib.c (gettimeofday): Copy from src/w32.c. lib/gettime.
needs this function.
2012-09-30 21:36:42 +00:00
|
|
|
#include <sys/timeb.h>
|
2012-10-17 21:13:20 +00:00
|
|
|
#include <mbstring.h>
|
1996-05-03 18:28:37 +00:00
|
|
|
|
|
|
|
#include "ntlib.h"
|
1994-11-01 10:27:02 +00:00
|
|
|
|
2013-03-26 08:21:27 +00:00
|
|
|
/* MinGW64 defines _TIMEZONE_DEFINED and defines 'struct timespec' in
|
|
|
|
its system headers. */
|
|
|
|
#ifndef _TIMEZONE_DEFINED
|
Support x64 build on MS-Windows with MSVC.
src/w32term.h (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK): Define for x64.
(SET_SCROLL_BAR_W32_WINDOW): Cast ID to intptr_t, for
compatibility with x64.
src/w32term.c (w32_draw_underwave): Don't use GCC extensions for
defining an XRectangle structure.
src/w32proc.c (RVA_TO_PTR, w32_executable_type): Fix pointer
arithmetics for compatibility with x64.
src/w32menu.c (add_menu_item): Use UINT_PTR instead of UINT, for
compatibility with x64.
src/w32heap.h: Adjust prototypes and declarations.
src/w32heap.c (RVA_TO_PTR, allocate_heap, sbrk, init_heap)
(round_heap): Use DWORD_PTR, ptrdiff_t and size_t instead of
DWORD, long, and unsigned long, for compatibility with x64.
(allocate_heap) [_WIN64]: Reserve 32GB of memory.
(sbrk): Argument is now of type ptrdiff_t.
src/w32fns.c (HMONITOR): Condition declaration on _WIN32_WINNT being
less than 0x0500.
(w32_msg_pump): Use WPARAM type for 'result'.
src/w32.c (init_environment, get_emacs_configuration): Support AMD64
architecture.
(init_ntproc): Cast arguments of _open_osfhandle to intptr_t, for
compatibility with x64.
src/vm-limit.c (lim_data): Now size_t.
(check_memory_limits): Adjust prototypes of real_morecore and
__morecore to receive argument of type ptrdiff_t. Use size_t for
five_percent and data_size.
src/unexw32.c: Use DWORD_PTR instead of DWORD for file-scope
variables, for compatibility with x64.
(rva_to_section, offset_to_section, relocate_offset)
(OFFSET_TO_RVA, RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET)
(PTR_TO_RVA, RVA_TO_PTR, OFFSET_TO_PTR, get_section_info)
(copy_executable_and_dump_data): Use DWORD_PTR instead of DWORD
for compatibility with x64.
src/sysdep.c (STDERR_FILENO): Define if not already defined.
src/ralloc.c (real_morecore): Argument type is now ptrdiff_t.
(__morecore): Argument type is now ptrdiff_t.
(ROUNDUP, MEM_ROUNDUP): Use size_t instead of 'unsigned long'.
(relinquish): Use ptrdiff_t type for 'excess'.
(r_alloc_sbrk): Argument type is now ptrdiff_t.
src/makefile.w32-in (HEAPSIZE): Get value from EMACS_HEAPSIZE.
(bootstrap-temacs-CMD, bootstrap-temacs-SH): Use $(EMACS_PURESIZE)
instead of a literal number.
src/gmalloc.c [WINDOWSNT]: Include w32heap.h.
(min): Define only if not already defined.
src/frame.c (x_report_frame_params): Use EMACS_UINT for the return
value of FRAME_X_WINDOW, to fit a 64-bit pointer on 64-bit Windows
hosts.
src/image.c (x_bitmap_pixmap): Return ptrdiff_t, not int, since
'bitmaps' is a pointer.
src/dispextern.h (x_bitmap_pixmap): Adjust prototype.
src/alloc.c (gdb_make_enums_visible): Now conditional on __GNUC__.
nt/makefile.w32-in ($(TRES)): Use $(EMACS_MANIFEST).
nt/inc/sys/socket.h: Don't map Winsock error codes to standard ones
that are already defined.
nt/inc/ms-w32.h (EMACS_INT, EMACS_UINT, EMACS_INT_MAX, PRIuMAX)
(pI, _INTPTR) [_MSC_VER]: Fix definitions for MSVC.
[_MSC_VER]: Add pragmas to suppress some MSVC warnings.
nt/preprep.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_move_sections, ADJUST_IMPORT_RVA, main): Use
DWORD_PTR instead of DWORD for compatibility with x64.
nt/nmake.defs: Support AMD64.
(EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST): New macros.
nt/gmake.defs: (EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST):
New macros.
nt/addsection.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_add_section, main): Use DWORD_PTR instead of
DWORD, for compatibility with x64.
nt/emacs-x64.manifest: New file.
nt/emacs-x86.manifest: Renamed from emacs.manifest.
lib-src/ntlib.c (gettimeofday): Copy from src/w32.c. lib/gettime.
needs this function.
2012-09-30 21:36:42 +00:00
|
|
|
struct timezone
|
|
|
|
{
|
|
|
|
int tz_minuteswest; /* minutes west of Greenwich */
|
|
|
|
int tz_dsttime; /* type of dst correction */
|
|
|
|
};
|
2013-03-26 08:21:27 +00:00
|
|
|
#endif
|
Support x64 build on MS-Windows with MSVC.
src/w32term.h (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK): Define for x64.
(SET_SCROLL_BAR_W32_WINDOW): Cast ID to intptr_t, for
compatibility with x64.
src/w32term.c (w32_draw_underwave): Don't use GCC extensions for
defining an XRectangle structure.
src/w32proc.c (RVA_TO_PTR, w32_executable_type): Fix pointer
arithmetics for compatibility with x64.
src/w32menu.c (add_menu_item): Use UINT_PTR instead of UINT, for
compatibility with x64.
src/w32heap.h: Adjust prototypes and declarations.
src/w32heap.c (RVA_TO_PTR, allocate_heap, sbrk, init_heap)
(round_heap): Use DWORD_PTR, ptrdiff_t and size_t instead of
DWORD, long, and unsigned long, for compatibility with x64.
(allocate_heap) [_WIN64]: Reserve 32GB of memory.
(sbrk): Argument is now of type ptrdiff_t.
src/w32fns.c (HMONITOR): Condition declaration on _WIN32_WINNT being
less than 0x0500.
(w32_msg_pump): Use WPARAM type for 'result'.
src/w32.c (init_environment, get_emacs_configuration): Support AMD64
architecture.
(init_ntproc): Cast arguments of _open_osfhandle to intptr_t, for
compatibility with x64.
src/vm-limit.c (lim_data): Now size_t.
(check_memory_limits): Adjust prototypes of real_morecore and
__morecore to receive argument of type ptrdiff_t. Use size_t for
five_percent and data_size.
src/unexw32.c: Use DWORD_PTR instead of DWORD for file-scope
variables, for compatibility with x64.
(rva_to_section, offset_to_section, relocate_offset)
(OFFSET_TO_RVA, RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET)
(PTR_TO_RVA, RVA_TO_PTR, OFFSET_TO_PTR, get_section_info)
(copy_executable_and_dump_data): Use DWORD_PTR instead of DWORD
for compatibility with x64.
src/sysdep.c (STDERR_FILENO): Define if not already defined.
src/ralloc.c (real_morecore): Argument type is now ptrdiff_t.
(__morecore): Argument type is now ptrdiff_t.
(ROUNDUP, MEM_ROUNDUP): Use size_t instead of 'unsigned long'.
(relinquish): Use ptrdiff_t type for 'excess'.
(r_alloc_sbrk): Argument type is now ptrdiff_t.
src/makefile.w32-in (HEAPSIZE): Get value from EMACS_HEAPSIZE.
(bootstrap-temacs-CMD, bootstrap-temacs-SH): Use $(EMACS_PURESIZE)
instead of a literal number.
src/gmalloc.c [WINDOWSNT]: Include w32heap.h.
(min): Define only if not already defined.
src/frame.c (x_report_frame_params): Use EMACS_UINT for the return
value of FRAME_X_WINDOW, to fit a 64-bit pointer on 64-bit Windows
hosts.
src/image.c (x_bitmap_pixmap): Return ptrdiff_t, not int, since
'bitmaps' is a pointer.
src/dispextern.h (x_bitmap_pixmap): Adjust prototype.
src/alloc.c (gdb_make_enums_visible): Now conditional on __GNUC__.
nt/makefile.w32-in ($(TRES)): Use $(EMACS_MANIFEST).
nt/inc/sys/socket.h: Don't map Winsock error codes to standard ones
that are already defined.
nt/inc/ms-w32.h (EMACS_INT, EMACS_UINT, EMACS_INT_MAX, PRIuMAX)
(pI, _INTPTR) [_MSC_VER]: Fix definitions for MSVC.
[_MSC_VER]: Add pragmas to suppress some MSVC warnings.
nt/preprep.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_move_sections, ADJUST_IMPORT_RVA, main): Use
DWORD_PTR instead of DWORD for compatibility with x64.
nt/nmake.defs: Support AMD64.
(EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST): New macros.
nt/gmake.defs: (EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST):
New macros.
nt/addsection.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_add_section, main): Use DWORD_PTR instead of
DWORD, for compatibility with x64.
nt/emacs-x64.manifest: New file.
nt/emacs-x86.manifest: Renamed from emacs.manifest.
lib-src/ntlib.c (gettimeofday): Copy from src/w32.c. lib/gettime.
needs this function.
2012-09-30 21:36:42 +00:00
|
|
|
|
1994-11-01 10:27:02 +00:00
|
|
|
#define MAXPATHLEN _MAX_PATH
|
|
|
|
|
|
|
|
/* Emulate sleep...we could have done this with a define, but that
|
|
|
|
would necessitate including windows.h in the files that used it.
|
|
|
|
This is much easier. */
|
2013-03-30 17:00:51 +00:00
|
|
|
unsigned
|
|
|
|
sleep (unsigned seconds)
|
1994-11-01 10:27:02 +00:00
|
|
|
{
|
|
|
|
Sleep (seconds * 1000);
|
2013-03-30 17:00:51 +00:00
|
|
|
return 0;
|
1994-11-01 10:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the current working directory. */
|
1996-07-15 19:57:23 +00:00
|
|
|
char *
|
1994-11-01 10:27:02 +00:00
|
|
|
getwd (char *dir)
|
|
|
|
{
|
1996-05-03 18:28:37 +00:00
|
|
|
if (GetCurrentDirectory (MAXPATHLEN, dir) > 0)
|
|
|
|
return dir;
|
|
|
|
return NULL;
|
1994-11-01 10:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HANDLE getppid_parent;
|
|
|
|
static int getppid_ppid;
|
|
|
|
|
|
|
|
int
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
getppid (void)
|
1994-11-01 10:27:02 +00:00
|
|
|
{
|
|
|
|
char *ppid;
|
|
|
|
DWORD result;
|
|
|
|
|
1998-05-30 23:37:12 +00:00
|
|
|
ppid = getenv ("EM_PARENT_PROCESS_ID");
|
2003-02-04 14:56:31 +00:00
|
|
|
if (!ppid)
|
1994-11-01 10:27:02 +00:00
|
|
|
{
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
printf ("no pid.\n");
|
1994-11-01 10:27:02 +00:00
|
|
|
return 0;
|
2003-02-04 14:56:31 +00:00
|
|
|
}
|
|
|
|
else
|
1994-11-01 10:27:02 +00:00
|
|
|
{
|
|
|
|
getppid_ppid = atoi (ppid);
|
|
|
|
}
|
|
|
|
|
2003-02-04 14:56:31 +00:00
|
|
|
if (!getppid_parent)
|
1994-11-01 10:27:02 +00:00
|
|
|
{
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi (ppid));
|
2003-02-04 14:56:31 +00:00
|
|
|
if (!getppid_parent)
|
1994-11-01 10:27:02 +00:00
|
|
|
{
|
|
|
|
printf ("Failed to open handle to parent process: %d\n",
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
GetLastError ());
|
1994-11-01 10:27:02 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = WaitForSingleObject (getppid_parent, 0);
|
2003-02-04 14:56:31 +00:00
|
|
|
switch (result)
|
1994-11-01 10:27:02 +00:00
|
|
|
{
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
/* The parent is still alive. */
|
|
|
|
return getppid_ppid;
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
/* The parent is gone. Return the pid of Unix init (1). */
|
|
|
|
return 1;
|
|
|
|
case WAIT_FAILED:
|
|
|
|
default:
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
printf ("Checking parent status failed: %d\n", GetLastError ());
|
1994-11-01 10:27:02 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
1996-05-03 18:28:37 +00:00
|
|
|
|
|
|
|
char *
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
getlogin (void)
|
1996-05-03 18:28:37 +00:00
|
|
|
{
|
|
|
|
static char user_name[256];
|
|
|
|
DWORD length = sizeof (user_name);
|
|
|
|
|
|
|
|
if (GetUserName (user_name, &length))
|
|
|
|
return user_name;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
cuserid (char * s)
|
|
|
|
{
|
|
|
|
char * name = getlogin ();
|
|
|
|
if (s)
|
|
|
|
return strcpy (s, name ? name : "");
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2009-03-21 11:31:50 +00:00
|
|
|
unsigned
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
getuid (void)
|
1996-05-03 18:28:37 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-30 17:00:51 +00:00
|
|
|
unsigned
|
|
|
|
geteuid (void)
|
|
|
|
{
|
|
|
|
return getuid ();
|
|
|
|
}
|
|
|
|
|
2010-04-03 02:23:51 +00:00
|
|
|
unsigned
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
getgid (void)
|
2010-04-03 02:23:51 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
getegid (void)
|
2010-04-03 02:23:51 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-05-03 18:28:37 +00:00
|
|
|
int
|
2009-03-21 11:31:50 +00:00
|
|
|
setuid (unsigned uid)
|
1996-05-03 18:28:37 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-03 02:23:51 +00:00
|
|
|
int
|
Fix the MS-Windows build broken by 2011-01-17T19:01:01Z!eggert@cs.ucla.edu and emacs-23/2010-05-21T19:51:48Z!acm@muc.de.
lib/makefile.w32-in:
lib/getopt_.h: New files.
src/s/ms-w32.h (HAVE_MKTIME): Remove.
src/makefile.w32-in (LOCAL_FLAGS): Add -I../lib.
(GNULIB): New variable.
(LIBS): Add $(GNULIB).
$(TEMACS): Depend on $(GNULIB).
<top-level>: Fix font-lock disrupted by a lone `"'.
src/makefile.w32-in (LOCAL_FLAGS): Add -I../lib.
(GETOPTOBJS, GETOPTDEPS): Remove targets.
(MOVEMAILOBJS): Replace $(GETOPTOBJS) with ../lib/$(BLD)/libgnu.$(A).
($(BLD)/movemail.exe): Depend on ../lib/getopt.h.
(ECLIENTOBJS, ETAGSOBJ, CTAGSOBJ, EBROWSEOBJ): Replace getopt.o
and getopt1.o with ../lib/$(BLD)/libgnu.$(A).
(clean): Don't remove getopt.h.
(getopt.h, $(BLD)/getopt.$(O), $(BLD)/getopt1.$(O)): Remove targets.
($(BLD)/ctags.$(O), $(BLD)/etags.$(O)): Replace getopt.h with
$(EMACS_ROOT)/lib/getopt.h.
nt/makefile.w32-in (all-other-dirs-nmake, all-other-dirs-gmake)
(bootstrap-nmake, bootstrap-gmake, bootstrap-clean-nmake)
(bootstrap-clean-gmake, clean-other-dirs-nmake)
(clean-other-dirs-gmake, cleanall-other-dirs-nmake)
(cleanall-other-dirs-gmake, distclean-other-dirs-nmake)
(distclean-other-dirs-gmake, maintainer-clean-other-dirs-nmake)
(maintainer-clean-other-dirs-gmake): Recurse into ../lib as well.
nt/configure.bat: Create lib/makefile.
nt/config.nt (HAVE_MKTIME, BROKEN_MKTIME): Remove.
(HAVE_ATTRIBUTE_ALIGNED, HAVE_C99_STRTOLD, HAVE_DECL_GETENV)
(HAVE_DECL_LOCALTIME_R, HAVE_WCHAR_T, PACKAGE, VERSION, inline)
(_GL_UNUSED, _UNUSED_PARAMETER_): Add definitions, for gnulib.
2011-01-29 12:36:11 +00:00
|
|
|
setregid (unsigned rgid, unsigned gid)
|
2010-04-03 02:23:51 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-05-03 18:28:37 +00:00
|
|
|
struct passwd *
|
2009-03-21 11:31:50 +00:00
|
|
|
getpwuid (unsigned uid)
|
1996-05-03 18:28:37 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
getpass (const char * prompt)
|
|
|
|
{
|
|
|
|
static char input[256];
|
|
|
|
HANDLE in;
|
|
|
|
HANDLE err;
|
|
|
|
DWORD count;
|
|
|
|
|
|
|
|
in = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
err = GetStdHandle (STD_ERROR_HANDLE);
|
|
|
|
|
|
|
|
if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
|
|
|
|
{
|
|
|
|
int istty = (GetFileType (in) == FILE_TYPE_CHAR);
|
|
|
|
DWORD old_flags;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (istty)
|
|
|
|
{
|
|
|
|
if (GetConsoleMode (in, &old_flags))
|
|
|
|
SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
|
|
|
|
else
|
|
|
|
istty = 0;
|
|
|
|
}
|
|
|
|
rc = ReadFile (in, input, sizeof (input), &count, NULL);
|
|
|
|
if (count >= 2 && input[count - 2] == '\r')
|
|
|
|
input[count - 2] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0)
|
|
|
|
if (count >= 2 && buf[count - 2] == '\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
WriteFile (err, "\r\n", 2, &count, NULL);
|
|
|
|
if (istty)
|
|
|
|
SetConsoleMode (in, old_flags);
|
|
|
|
if (rc)
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
Support x64 build on MS-Windows with MSVC.
src/w32term.h (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK): Define for x64.
(SET_SCROLL_BAR_W32_WINDOW): Cast ID to intptr_t, for
compatibility with x64.
src/w32term.c (w32_draw_underwave): Don't use GCC extensions for
defining an XRectangle structure.
src/w32proc.c (RVA_TO_PTR, w32_executable_type): Fix pointer
arithmetics for compatibility with x64.
src/w32menu.c (add_menu_item): Use UINT_PTR instead of UINT, for
compatibility with x64.
src/w32heap.h: Adjust prototypes and declarations.
src/w32heap.c (RVA_TO_PTR, allocate_heap, sbrk, init_heap)
(round_heap): Use DWORD_PTR, ptrdiff_t and size_t instead of
DWORD, long, and unsigned long, for compatibility with x64.
(allocate_heap) [_WIN64]: Reserve 32GB of memory.
(sbrk): Argument is now of type ptrdiff_t.
src/w32fns.c (HMONITOR): Condition declaration on _WIN32_WINNT being
less than 0x0500.
(w32_msg_pump): Use WPARAM type for 'result'.
src/w32.c (init_environment, get_emacs_configuration): Support AMD64
architecture.
(init_ntproc): Cast arguments of _open_osfhandle to intptr_t, for
compatibility with x64.
src/vm-limit.c (lim_data): Now size_t.
(check_memory_limits): Adjust prototypes of real_morecore and
__morecore to receive argument of type ptrdiff_t. Use size_t for
five_percent and data_size.
src/unexw32.c: Use DWORD_PTR instead of DWORD for file-scope
variables, for compatibility with x64.
(rva_to_section, offset_to_section, relocate_offset)
(OFFSET_TO_RVA, RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET)
(PTR_TO_RVA, RVA_TO_PTR, OFFSET_TO_PTR, get_section_info)
(copy_executable_and_dump_data): Use DWORD_PTR instead of DWORD
for compatibility with x64.
src/sysdep.c (STDERR_FILENO): Define if not already defined.
src/ralloc.c (real_morecore): Argument type is now ptrdiff_t.
(__morecore): Argument type is now ptrdiff_t.
(ROUNDUP, MEM_ROUNDUP): Use size_t instead of 'unsigned long'.
(relinquish): Use ptrdiff_t type for 'excess'.
(r_alloc_sbrk): Argument type is now ptrdiff_t.
src/makefile.w32-in (HEAPSIZE): Get value from EMACS_HEAPSIZE.
(bootstrap-temacs-CMD, bootstrap-temacs-SH): Use $(EMACS_PURESIZE)
instead of a literal number.
src/gmalloc.c [WINDOWSNT]: Include w32heap.h.
(min): Define only if not already defined.
src/frame.c (x_report_frame_params): Use EMACS_UINT for the return
value of FRAME_X_WINDOW, to fit a 64-bit pointer on 64-bit Windows
hosts.
src/image.c (x_bitmap_pixmap): Return ptrdiff_t, not int, since
'bitmaps' is a pointer.
src/dispextern.h (x_bitmap_pixmap): Adjust prototype.
src/alloc.c (gdb_make_enums_visible): Now conditional on __GNUC__.
nt/makefile.w32-in ($(TRES)): Use $(EMACS_MANIFEST).
nt/inc/sys/socket.h: Don't map Winsock error codes to standard ones
that are already defined.
nt/inc/ms-w32.h (EMACS_INT, EMACS_UINT, EMACS_INT_MAX, PRIuMAX)
(pI, _INTPTR) [_MSC_VER]: Fix definitions for MSVC.
[_MSC_VER]: Add pragmas to suppress some MSVC warnings.
nt/preprep.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_move_sections, ADJUST_IMPORT_RVA, main): Use
DWORD_PTR instead of DWORD for compatibility with x64.
nt/nmake.defs: Support AMD64.
(EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST): New macros.
nt/gmake.defs: (EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST):
New macros.
nt/addsection.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_add_section, main): Use DWORD_PTR instead of
DWORD, for compatibility with x64.
nt/emacs-x64.manifest: New file.
nt/emacs-x86.manifest: Renamed from emacs.manifest.
lib-src/ntlib.c (gettimeofday): Copy from src/w32.c. lib/gettime.
needs this function.
2012-09-30 21:36:42 +00:00
|
|
|
/* This is needed because lib/gettime.c calls gettimeofday, which MSVC
|
|
|
|
doesn't have. Copied from w32.c. */
|
|
|
|
void
|
|
|
|
gettimeofday (struct timeval *tv, struct timezone *tz)
|
|
|
|
{
|
|
|
|
struct _timeb tb;
|
|
|
|
_ftime (&tb);
|
|
|
|
|
|
|
|
tv->tv_sec = tb.time;
|
|
|
|
tv->tv_usec = tb.millitm * 1000L;
|
|
|
|
/* Implementation note: _ftime sometimes doesn't update the dstflag
|
|
|
|
according to the new timezone when the system timezone is
|
|
|
|
changed. We could fix that by using GetSystemTime and
|
|
|
|
GetTimeZoneInformation, but that doesn't seem necessary, since
|
|
|
|
Emacs always calls gettimeofday with the 2nd argument NULL (see
|
|
|
|
current_emacs_time). */
|
|
|
|
if (tz)
|
|
|
|
{
|
|
|
|
tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
|
|
|
|
tz->tz_dsttime = tb.dstflag; /* type of dst correction */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-03 18:28:37 +00:00
|
|
|
int
|
2009-03-21 11:31:50 +00:00
|
|
|
fchown (int fd, unsigned uid, unsigned gid)
|
1996-05-03 18:28:37 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Place a wrapper around the MSVC version of ctime. It returns NULL
|
2003-02-04 14:56:31 +00:00
|
|
|
on network directories, so we handle that case here.
|
1996-05-03 18:28:37 +00:00
|
|
|
(Ulrich Leodolter, 1/11/95). */
|
|
|
|
char *
|
|
|
|
sys_ctime (const time_t *t)
|
|
|
|
{
|
|
|
|
char *str = (char *) ctime (t);
|
|
|
|
return (str ? str : "Sun Jan 01 00:00:00 1970");
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *
|
Convert some more functions to standard C.
* lib-src/emacsclient.c (get_current_dir_name, w32_get_resource)
(w32_getenv, w32_set_user_model_id, w32_window_app, w32_execvp)
(close_winsock, initialize_sockets, w32_find_emacs_process)
(w32_give_focus):
* lib-src/ntlib.c (getlogin, getuid, getgid, getegid):
* nt/addpm.c (add_registry, main):
* nt/cmdproxy.c (get_env_size):
* nt/ddeclient.c (main):
* nt/runemacs.c (set_user_model_id):
* src/alloc.c (emacs_blocked_free, emacs_blocked_malloc)
(emacs_blocked_realloc, uninterrupt_malloc):
* src/fringe.c (w32_reset_fringes):
* src/image.c (convert_mono_to_color_image, lookup_rgb_color)
(init_color_table, XPutPixel, jpeg_resync_to_restart_wrapper):
* src/sound.c (be2hs, do_play_sound):
* src/vm-limit.c (get_lim_data, ret_lim_data):
* src/w32term.c (x_free_frame_resources):
* src/xfaces.c (x_create_gc, x_free_gc):
Convert definitions to standard C.
2010-07-20 20:21:03 +00:00
|
|
|
sys_fopen (const char * path, const char * mode)
|
1996-05-03 18:28:37 +00:00
|
|
|
{
|
|
|
|
return fopen (path, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_chdir (const char * path)
|
|
|
|
{
|
|
|
|
return _chdir (path);
|
|
|
|
}
|
2003-09-01 15:45:59 +00:00
|
|
|
|
2008-05-09 20:37:32 +00:00
|
|
|
static FILETIME utc_base_ft;
|
|
|
|
static long double utc_base;
|
|
|
|
static int init = 0;
|
|
|
|
|
|
|
|
static time_t
|
|
|
|
convert_time (FILETIME ft)
|
|
|
|
{
|
|
|
|
long double ret;
|
|
|
|
|
|
|
|
if (CompareFileTime (&ft, &utc_base_ft) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = (long double) ft.dwHighDateTime
|
|
|
|
* 4096.0L * 1024.0L * 1024.0L + ft.dwLowDateTime;
|
|
|
|
ret -= utc_base;
|
|
|
|
return (time_t) (ret * 1e-7L);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_exec (const char * name)
|
|
|
|
{
|
|
|
|
char * p = strrchr (name, '.');
|
|
|
|
return
|
|
|
|
(p != NULL
|
|
|
|
&& (stricmp (p, ".exe") == 0 ||
|
|
|
|
stricmp (p, ".com") == 0 ||
|
|
|
|
stricmp (p, ".bat") == 0 ||
|
|
|
|
stricmp (p, ".cmd") == 0));
|
|
|
|
}
|
|
|
|
|
2015-08-15 17:40:06 +00:00
|
|
|
/* FIXME? This is in configure.ac now - is this still needed? */
|
2008-05-09 20:37:32 +00:00
|
|
|
#define IS_DIRECTORY_SEP(x) ((x) == '/' || (x) == '\\')
|
|
|
|
|
|
|
|
/* We need this because nt/inc/sys/stat.h defines struct stat that is
|
|
|
|
incompatible with the MS run-time libraries. */
|
|
|
|
int
|
|
|
|
stat (const char * path, struct stat * buf)
|
|
|
|
{
|
|
|
|
WIN32_FIND_DATA wfd;
|
|
|
|
HANDLE fh;
|
|
|
|
int permission;
|
|
|
|
int len;
|
|
|
|
int rootdir = FALSE;
|
|
|
|
char *name = alloca (FILENAME_MAX);
|
|
|
|
|
|
|
|
if (!init)
|
|
|
|
{
|
|
|
|
/* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
|
|
|
|
SYSTEMTIME st;
|
|
|
|
|
|
|
|
st.wYear = 1970;
|
|
|
|
st.wMonth = 1;
|
|
|
|
st.wDay = 1;
|
|
|
|
st.wHour = 0;
|
|
|
|
st.wMinute = 0;
|
|
|
|
st.wSecond = 0;
|
|
|
|
st.wMilliseconds = 0;
|
|
|
|
|
|
|
|
SystemTimeToFileTime (&st, &utc_base_ft);
|
|
|
|
utc_base = (long double) utc_base_ft.dwHighDateTime
|
|
|
|
* 4096.0L * 1024.0L * 1024.0L + utc_base_ft.dwLowDateTime;
|
|
|
|
init = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path == NULL || buf == NULL || *path == '\0')
|
|
|
|
{
|
|
|
|
errno = EFAULT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (_mbspbrk (path, "*?|<>\""))
|
|
|
|
{
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy (name, path);
|
|
|
|
/* Remove trailing directory separator, unless name is the root
|
|
|
|
directory of a drive in which case ensure there is a trailing
|
|
|
|
separator. */
|
|
|
|
len = strlen (name);
|
|
|
|
rootdir = IS_DIRECTORY_SEP (name[0])
|
|
|
|
|| (len == 3 && name[1] == ':' && IS_DIRECTORY_SEP (name[2]));
|
|
|
|
if (rootdir)
|
|
|
|
{
|
|
|
|
if (GetDriveType (name) < 2)
|
|
|
|
{
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memset (&wfd, 0, sizeof (wfd));
|
|
|
|
wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
wfd.ftCreationTime = utc_base_ft;
|
|
|
|
wfd.ftLastAccessTime = utc_base_ft;
|
|
|
|
wfd.ftLastWriteTime = utc_base_ft;
|
|
|
|
strcpy (wfd.cFileName, name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IS_DIRECTORY_SEP (name[len-1]))
|
|
|
|
name[len - 1] = 0;
|
|
|
|
|
|
|
|
fh = FindFirstFile (name, &wfd);
|
|
|
|
if (fh == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
FindClose (fh);
|
|
|
|
}
|
|
|
|
buf->st_mode = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
|
|
|
|
S_IFDIR : S_IFREG;
|
|
|
|
buf->st_nlink = 1;
|
|
|
|
buf->st_ino = 0;
|
|
|
|
|
|
|
|
if (name[0] && name[1] == ':')
|
|
|
|
buf->st_dev = tolower (name[0]) - 'a' + 1;
|
|
|
|
else
|
|
|
|
buf->st_dev = _getdrive ();
|
|
|
|
buf->st_rdev = buf->st_dev;
|
|
|
|
|
|
|
|
buf->st_size = wfd.nFileSizeLow;
|
|
|
|
|
|
|
|
/* Convert timestamps to Unix format. */
|
|
|
|
buf->st_mtime = convert_time (wfd.ftLastWriteTime);
|
|
|
|
buf->st_atime = convert_time (wfd.ftLastAccessTime);
|
|
|
|
if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
|
|
|
|
buf->st_ctime = convert_time (wfd.ftCreationTime);
|
|
|
|
if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
|
|
|
|
|
|
|
|
/* determine rwx permissions */
|
|
|
|
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
|
|
permission = S_IREAD;
|
|
|
|
else
|
|
|
|
permission = S_IREAD | S_IWRITE;
|
|
|
|
|
|
|
|
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
permission |= S_IEXEC;
|
|
|
|
else if (is_exec (name))
|
|
|
|
permission |= S_IEXEC;
|
|
|
|
|
|
|
|
buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Support symlinks on latest versions of MS-Windows.
src/w32.c: Include winioctl.h and aclapi.h.
(is_symlink, chase_symlinks, enable_privilege, restore_privilege)
(revert_to_self): Forward declarations of static functions.
<static BOOL g_b_init_get_security_info>:
<g_b_init_create_symbolic_link>: New static flags.
(globals_of_w32): Initialize them to zero.
(GetSecurityInfo_Proc, CreateSymbolicLink_Proc): New typedefs.
(map_w32_filename): Improve commentary. Simplify switch.
(SYMBOLIC_LINK_FLAG_DIRECTORY): Define if not defined in system
headers (most versions of MinGW w32api don't).
(get_security_info, create_symbolic_link)
(get_file_security_desc_by_handle, is_symlink, chase_symlinks):
New functions.
(sys_access, sys_chmod): Call 'chase_symlinks' to resolve symlinks
in the argument file name.
(sys_access): Call unc_volume_file_attributes only if
GetFileAttributes fails with network-related error codes.
(sys_rename): Diagnose renaming of a symlink when the user doesn't
have the required privileges.
(get_file_security_desc_by_name): Renamed from
get_file_security_desc.
(stat_worker): New function, with most of the guts of 'stat', and
with addition of handling of symlinks and support for 'lstat'. If
possible, get file's attributes and security information by
handle, not by name. Produce S_IFLNK bit for symlinks, when
called from 'lstat'.
(stat, lstat): New functions, call 'stat_worker'.
(symlink, readlink, careadlinkat): Rewritten to create and resolve
symlinks when the underlying filesystem supports them.
lib/src/ntlib.c (lstat): New function, calls 'stat'.
nt/inc/sys/stat.h (S_IFLNK): Define.
(S_ISLNK): A non-trivial definition.
(lstat): Prototype instead of a macro that redirects to 'stat'.
lisp/files.el (file-truename): Don't skip symlink-chasing part on
windows-nt. Incorporate the resolution of 8+3 short aliases on
Windows into the loop that recursively chases symlinks. Compare
directory and its parent case-insensitively on MS-Windows and
MS-DOS.
etc/NEWS: Announce the symlink support on MS-Windows.
2012-08-03 10:23:30 +00:00
|
|
|
int
|
|
|
|
lstat (const char * path, struct stat * buf)
|
|
|
|
{
|
|
|
|
return stat (path, buf);
|
|
|
|
}
|
2013-08-04 17:52:25 +00:00
|
|
|
|
|
|
|
/* Implementation of mkostemp for MS-Windows, to avoid race conditions
|
2013-08-05 17:09:28 +00:00
|
|
|
when using mktemp. Copied from w32.c.
|
2013-08-04 17:52:25 +00:00
|
|
|
|
2013-08-05 17:09:28 +00:00
|
|
|
This is used only in update-game-score.c. It is overkill for that
|
|
|
|
use case, since update-game-score renames the temporary file into
|
|
|
|
the game score file, which isn't atomic on MS-Windows anyway, when
|
|
|
|
the game score already existed before running the program, which it
|
|
|
|
almost always does. But using a simpler implementation just to
|
|
|
|
make a point is uneconomical... */
|
2013-08-04 17:52:25 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
mkostemp (char * template, int flags)
|
|
|
|
{
|
|
|
|
char * p;
|
|
|
|
int i, fd = -1;
|
|
|
|
unsigned uid = GetCurrentThreadId ();
|
|
|
|
int save_errno = errno;
|
|
|
|
static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#";
|
|
|
|
|
|
|
|
errno = EINVAL;
|
|
|
|
if (template == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
p = template + strlen (template);
|
|
|
|
i = 5;
|
|
|
|
/* replace up to the last 5 X's with uid in decimal */
|
|
|
|
while (--p >= template && p[0] == 'X' && --i >= 0)
|
|
|
|
{
|
|
|
|
p[0] = '0' + uid % 10;
|
|
|
|
uid /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < 0 && p[0] == 'X')
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
p[0] = first_char[i];
|
|
|
|
if ((fd = open (template,
|
|
|
|
flags | _O_CREAT | _O_EXCL | _O_RDWR,
|
|
|
|
S_IRUSR | S_IWUSR)) >= 0
|
|
|
|
|| errno != EEXIST)
|
|
|
|
{
|
|
|
|
if (fd >= 0)
|
|
|
|
errno = save_errno;
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (++i < sizeof (first_char));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Template is badly formed or else we can't generate a unique name. */
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-05 17:09:28 +00:00
|
|
|
|
|
|
|
/* On Windows, you cannot rename into an existing file. */
|
|
|
|
int
|
|
|
|
sys_rename (const char *from, const char *to)
|
|
|
|
{
|
|
|
|
int retval = rename (from, to);
|
|
|
|
|
|
|
|
if (retval < 0 && errno == EEXIST)
|
|
|
|
{
|
|
|
|
if (unlink (to) == 0)
|
|
|
|
retval = rename (from, to);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|