aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/w32.c')
-rw-r--r--src/w32.c103
1 files changed, 86 insertions, 17 deletions
diff --git a/src/w32.c b/src/w32.c
index 53bf2e811e2..3d3d33453c6 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1,5 +1,5 @@
1/* Utility and Unix shadow routines for GNU Emacs on the Microsoft W32 API. 1/* Utility and Unix shadow routines for GNU Emacs on the Microsoft W32 API.
2 Copyright (C) 1994-1995, 2000-2011 Free Software Foundation, Inc. 2 Copyright (C) 1994-1995, 2000-2012 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -94,8 +94,10 @@ typedef struct _MEMORY_STATUS_EX {
94 94
95#include <tlhelp32.h> 95#include <tlhelp32.h>
96#include <psapi.h> 96#include <psapi.h>
97#ifndef _MSC_VER
97#include <w32api.h> 98#include <w32api.h>
98#if !defined(__MINGW32__) || __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 15) 99#endif
100#if !defined (__MINGW32__) || __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 15)
99/* This either is not in psapi.h or guarded by higher value of 101/* This either is not in psapi.h or guarded by higher value of
100 _WIN32_WINNT than what we use. w32api supplied with MinGW 3.15 102 _WIN32_WINNT than what we use. w32api supplied with MinGW 3.15
101 defines it in psapi.h */ 103 defines it in psapi.h */
@@ -1452,6 +1454,14 @@ sigprocmask (int how, const sigset_t *set, sigset_t *oset)
1452} 1454}
1453 1455
1454int 1456int
1457pthread_sigmask (int how, const sigset_t *set, sigset_t *oset)
1458{
1459 if (sigprocmask (how, set, oset) == -1)
1460 return EINVAL;
1461 return 0;
1462}
1463
1464int
1455setpgrp (int pid, int gid) 1465setpgrp (int pid, int gid)
1456{ 1466{
1457 return 0; 1467 return 0;
@@ -1539,7 +1549,12 @@ init_environment (char ** argv)
1539 read-only filesystem, like CD-ROM or a write-protected floppy. 1549 read-only filesystem, like CD-ROM or a write-protected floppy.
1540 The only way to be really sure is to actually create a file and 1550 The only way to be really sure is to actually create a file and
1541 see if it succeeds. But I think that's too much to ask. */ 1551 see if it succeeds. But I think that's too much to ask. */
1552#ifdef _MSC_VER
1553 /* MSVC's _access crashes with D_OK. */
1554 if (tmp && sys_access (tmp, D_OK) == 0)
1555#else
1542 if (tmp && _access (tmp, D_OK) == 0) 1556 if (tmp && _access (tmp, D_OK) == 0)
1557#endif
1543 { 1558 {
1544 char * var = alloca (strlen (tmp) + 8); 1559 char * var = alloca (strlen (tmp) + 8);
1545 sprintf (var, "TMPDIR=%s", tmp); 1560 sprintf (var, "TMPDIR=%s", tmp);
@@ -1639,6 +1654,24 @@ init_environment (char ** argv)
1639 } 1654 }
1640 } 1655 }
1641 1656
1657 /* When Emacs is invoked with --no-site-lisp, we must remove the
1658 site-lisp directories from the default value of EMACSLOADPATH.
1659 This assumes that the site-lisp entries are at the front, and
1660 that additional entries do exist. */
1661 if (no_site_lisp)
1662 {
1663 for (i = 0; i < N_ENV_VARS; i++)
1664 {
1665 if (strcmp (env_vars[i].name, "EMACSLOADPATH") == 0)
1666 {
1667 char *site;
1668 while ((site = strstr (env_vars[i].def_value, "site-lisp")))
1669 env_vars[i].def_value = strchr (site, ';') + 1;
1670 break;
1671 }
1672 }
1673 }
1674
1642#define SET_ENV_BUF_SIZE (4 * MAX_PATH) /* to cover EMACSLOADPATH */ 1675#define SET_ENV_BUF_SIZE (4 * MAX_PATH) /* to cover EMACSLOADPATH */
1643 1676
1644 /* Treat emacs_dir specially: set it unconditionally based on our 1677 /* Treat emacs_dir specially: set it unconditionally based on our
@@ -1907,6 +1940,9 @@ get_emacs_configuration_options (void)
1907#ifdef EMACSDEBUG 1940#ifdef EMACSDEBUG
1908 " --no-opt", 1941 " --no-opt",
1909#endif 1942#endif
1943#ifdef ENABLE_CHECKING
1944 " --enable-checking",
1945#endif
1910 /* configure.bat already sets USER_CFLAGS and USER_LDFLAGS 1946 /* configure.bat already sets USER_CFLAGS and USER_LDFLAGS
1911 with a starting space to save work here. */ 1947 with a starting space to save work here. */
1912#ifdef USER_CFLAGS 1948#ifdef USER_CFLAGS
@@ -2861,6 +2897,8 @@ sys_rename (const char * oldname, const char * newname)
2861{ 2897{
2862 BOOL result; 2898 BOOL result;
2863 char temp[MAX_PATH]; 2899 char temp[MAX_PATH];
2900 int newname_dev;
2901 int oldname_dev;
2864 2902
2865 /* MoveFile on Windows 95 doesn't correctly change the short file name 2903 /* MoveFile on Windows 95 doesn't correctly change the short file name
2866 alias in a number of circumstances (it is not easy to predict when 2904 alias in a number of circumstances (it is not easy to predict when
@@ -2877,6 +2915,9 @@ sys_rename (const char * oldname, const char * newname)
2877 2915
2878 strcpy (temp, map_w32_filename (oldname, NULL)); 2916 strcpy (temp, map_w32_filename (oldname, NULL));
2879 2917
2918 /* volume_info is set indirectly by map_w32_filename. */
2919 oldname_dev = volume_info.serialnum;
2920
2880 if (os_subtype == OS_WIN95) 2921 if (os_subtype == OS_WIN95)
2881 { 2922 {
2882 char * o; 2923 char * o;
@@ -2884,12 +2925,12 @@ sys_rename (const char * oldname, const char * newname)
2884 int i = 0; 2925 int i = 0;
2885 2926
2886 oldname = map_w32_filename (oldname, NULL); 2927 oldname = map_w32_filename (oldname, NULL);
2887 if (o = strrchr (oldname, '\\')) 2928 if ((o = strrchr (oldname, '\\')))
2888 o++; 2929 o++;
2889 else 2930 else
2890 o = (char *) oldname; 2931 o = (char *) oldname;
2891 2932
2892 if (p = strrchr (temp, '\\')) 2933 if ((p = strrchr (temp, '\\')))
2893 p++; 2934 p++;
2894 else 2935 else
2895 p = temp; 2936 p = temp;
@@ -2920,13 +2961,38 @@ sys_rename (const char * oldname, const char * newname)
2920 all the permutations of shared or subst'd drives, etc.) */ 2961 all the permutations of shared or subst'd drives, etc.) */
2921 2962
2922 newname = map_w32_filename (newname, NULL); 2963 newname = map_w32_filename (newname, NULL);
2964
2965 /* volume_info is set indirectly by map_w32_filename. */
2966 newname_dev = volume_info.serialnum;
2967
2923 result = rename (temp, newname); 2968 result = rename (temp, newname);
2924 2969
2925 if (result < 0 2970 if (result < 0)
2926 && errno == EEXIST 2971 {
2927 && _chmod (newname, 0666) == 0 2972
2928 && _unlink (newname) == 0) 2973 if (errno == EACCES
2929 result = rename (temp, newname); 2974 && newname_dev != oldname_dev)
2975 {
2976 /* The implementation of `rename' on Windows does not return
2977 errno = EXDEV when you are moving a directory to a
2978 different storage device (ex. logical disk). It returns
2979 EACCES instead. So here we handle such situations and
2980 return EXDEV. */
2981 DWORD attributes;
2982
2983 if ((attributes = GetFileAttributes (temp)) != -1
2984 && attributes & FILE_ATTRIBUTE_DIRECTORY)
2985 errno = EXDEV;
2986 }
2987 else if (errno == EEXIST)
2988 {
2989 if (_chmod (newname, 0666) != 0)
2990 return result;
2991 if (_unlink (newname) != 0)
2992 return result;
2993 result = rename (temp, newname);
2994 }
2995 }
2930 2996
2931 return result; 2997 return result;
2932} 2998}
@@ -3042,7 +3108,7 @@ generate_inode_val (const char * name)
3042 unsigned hash; 3108 unsigned hash;
3043 3109
3044 /* Get the truly canonical filename, if it exists. (Note: this 3110 /* Get the truly canonical filename, if it exists. (Note: this
3045 doesn't resolve aliasing due to subst commands, or recognise hard 3111 doesn't resolve aliasing due to subst commands, or recognize hard
3046 links. */ 3112 links. */
3047 if (!w32_get_long_filename ((char *)name, fullname, MAX_PATH)) 3113 if (!w32_get_long_filename ((char *)name, fullname, MAX_PATH))
3048 abort (); 3114 abort ();
@@ -3388,7 +3454,7 @@ stat (const char * path, struct stat * buf)
3388 FILE_FLAG_BACKUP_SEMANTICS, NULL)) 3454 FILE_FLAG_BACKUP_SEMANTICS, NULL))
3389 != INVALID_HANDLE_VALUE) 3455 != INVALID_HANDLE_VALUE)
3390 { 3456 {
3391 /* This is more accurate in terms of gettting the correct number 3457 /* This is more accurate in terms of getting the correct number
3392 of links, but is quite slow (it is noticeable when Emacs is 3458 of links, but is quite slow (it is noticeable when Emacs is
3393 making a list of file name completions). */ 3459 making a list of file name completions). */
3394 BY_HANDLE_FILE_INFORMATION info; 3460 BY_HANDLE_FILE_INFORMATION info;
@@ -5748,7 +5814,7 @@ w32_delayed_load (Lisp_Object libraries, Lisp_Object library_id)
5748 for (dlls = XCDR (dlls); CONSP (dlls); dlls = XCDR (dlls)) 5814 for (dlls = XCDR (dlls); CONSP (dlls); dlls = XCDR (dlls))
5749 { 5815 {
5750 CHECK_STRING_CAR (dlls); 5816 CHECK_STRING_CAR (dlls);
5751 if (library_dll = LoadLibrary (SDATA (XCAR (dlls)))) 5817 if ((library_dll = LoadLibrary (SDATA (XCAR (dlls)))))
5752 { 5818 {
5753 found = XCAR (dlls); 5819 found = XCAR (dlls);
5754 break; 5820 break;
@@ -5769,7 +5835,10 @@ check_windows_init_file (void)
5769 it cannot find the Windows installation file. If this file does 5835 it cannot find the Windows installation file. If this file does
5770 not exist in the expected place, tell the user. */ 5836 not exist in the expected place, tell the user. */
5771 5837
5772 if (!noninteractive && !inhibit_window_system) 5838 if (!noninteractive && !inhibit_window_system
5839 /* Vload_path is not yet initialized when we are loading
5840 loadup.el. */
5841 && NILP (Vpurify_flag))
5773 { 5842 {
5774 Lisp_Object objs[2]; 5843 Lisp_Object objs[2];
5775 Lisp_Object full_load_path; 5844 Lisp_Object full_load_path;
@@ -5827,7 +5896,7 @@ term_ntproc (void)
5827void 5896void
5828init_ntproc (void) 5897init_ntproc (void)
5829{ 5898{
5830 /* Initialise the socket interface now if available and requested by 5899 /* Initialize the socket interface now if available and requested by
5831 the user by defining PRELOAD_WINSOCK; otherwise loading will be 5900 the user by defining PRELOAD_WINSOCK; otherwise loading will be
5832 delayed until open-network-stream is called (w32-has-winsock can 5901 delayed until open-network-stream is called (w32-has-winsock can
5833 also be used to dynamically load or reload winsock). 5902 also be used to dynamically load or reload winsock).
@@ -6204,7 +6273,7 @@ emacs_gnutls_pull (gnutls_transport_ptr_t p, void* buf, size_t sz)
6204 6273
6205 for (;;) 6274 for (;;)
6206 { 6275 {
6207 n = sys_read(fd, (char*)buf, sz); 6276 n = sys_read (fd, (char*)buf, sz);
6208 6277
6209 if (n >= 0) 6278 if (n >= 0)
6210 return n; 6279 return n;
@@ -6214,7 +6283,7 @@ emacs_gnutls_pull (gnutls_transport_ptr_t p, void* buf, size_t sz)
6214 if (err == EWOULDBLOCK) 6283 if (err == EWOULDBLOCK)
6215 { 6284 {
6216 /* Set a small timeout. */ 6285 /* Set a small timeout. */
6217 EMACS_SET_SECS_USECS(timeout, 1, 0); 6286 EMACS_SET_SECS_USECS (timeout, 1, 0);
6218 FD_ZERO (&fdset); 6287 FD_ZERO (&fdset);
6219 FD_SET ((int)fd, &fdset); 6288 FD_SET ((int)fd, &fdset);
6220 6289
@@ -6244,7 +6313,7 @@ emacs_gnutls_push (gnutls_transport_ptr_t p, const void* buf, size_t sz)
6244{ 6313{
6245 struct Lisp_Process *process = (struct Lisp_Process *)p; 6314 struct Lisp_Process *process = (struct Lisp_Process *)p;
6246 int fd = process->outfd; 6315 int fd = process->outfd;
6247 ssize_t n = sys_write(fd, buf, sz); 6316 ssize_t n = sys_write (fd, buf, sz);
6248 6317
6249 /* 0 or more bytes written means everything went fine. */ 6318 /* 0 or more bytes written means everything went fine. */
6250 if (n >= 0) 6319 if (n >= 0)