#include <ctype.h>
#include <io.h>
#include <fcntl.h>
+#include <unistd.h>
#include <signal.h>
#include <sys/file.h>
#include <mbstring.h>
#include "w32.h"
#include "w32common.h"
#include "w32heap.h"
-#include "systime.h"
-#include "syswait.h"
-#include "process.h"
+#include "syswait.h" /* for WNOHANG */
#include "syssignal.h"
#include "w32term.h"
-#include "dispextern.h" /* for xstrcasecmp */
#include "coding.h"
#define RVA_TO_PTR(var,section,filedata) \
{
/* This catches both MSYS 1.x and MSYS2
executables (the DLL name is msys-1.0.dll and
- msys-2.0.dll, respectively). There's doesn't
+ msys-2.0.dll, respectively). There doesn't
seem to be a reason to distinguish between
the two, for now. */
*is_msys_app = TRUE;
absolute. So we double-check this here, just in case. */
if (faccessat (AT_FDCWD, cmdname, X_OK, AT_EACCESS) != 0)
{
- struct gcpro gcpro1;
-
program = build_string (cmdname);
full = Qnil;
- GCPRO1 (program);
openp (Vexec_path, program, Vexec_suffixes, &full, make_number (X_OK), 0);
- UNGCPRO;
if (NILP (full))
{
errno = EINVAL;
return -1;
}
program = ENCODE_FILE (full);
- cmdname = SDATA (program);
+ cmdname = SSDATA (program);
}
else
{
/* We explicitly require that the command's file name be encodable
in the current ANSI codepage, because we will be invoking it via
the ANSI APIs. */
- if (_mbspbrk (cmdname_a, "?"))
+ if (_mbspbrk ((unsigned char *)cmdname_a, (const unsigned char *)"?"))
{
errno = ENOENT;
return -1;
cmdname = alloca (MAX_PATH);
if (egetenv ("CMDPROXY"))
- strcpy (cmdname, egetenv ("CMDPROXY"));
+ {
+ /* Implementation note: since process-environment, where
+ 'egetenv' looks, is encoded in the system codepage, we
+ don't need to encode the cmdproxy file name if we get it
+ from the environment. */
+ strcpy (cmdname, egetenv ("CMDPROXY"));
+ }
else
- strcpy (lispstpcpy (cmdname, Vinvocation_directory), "cmdproxy.exe");
+ {
+ char *q = lispstpcpy (cmdname,
+ /* exec-directory needs to be encoded. */
+ ansi_encode_filename (Vexec_directory));
+ /* If we are run from the source tree, use cmdproxy.exe from
+ the same source tree. */
+ for (p = q - 2; p > cmdname; p = CharPrevA (cmdname, p))
+ if (*p == '/')
+ break;
+ if (*p == '/' && xstrcasecmp (p, "/lib-src/") == 0)
+ q = stpcpy (p, "/nt/");
+ strcpy (q, "cmdproxy.exe");
+ }
/* Can't use unixtodos_filename here, since that needs its file
name argument encoded in UTF-8. */
cp = fd_info[i].cp;
if (FD_ISSET (i, &owfds)
&& cp
- && (fd_info[i].flags && FILE_CONNECT) == 0)
+ && (fd_info[i].flags & FILE_CONNECT) == 0)
{
DebPrint (("sys_select: fd %d is in wfds, but FILE_CONNECT is reset!\n", i));
cp = NULL;
filename = Fexpand_file_name (filename, Qnil);
/* luckily, this returns the short version of each element in the path. */
- if (w32_get_short_filename (SDATA (ENCODE_FILE (filename)),
+ if (w32_get_short_filename (SSDATA (ENCODE_FILE (filename)),
shortname, MAX_PATH) == 0)
return Qnil;
/* first expand it. */
filename = Fexpand_file_name (filename, Qnil);
- if (!w32_get_long_filename (SDATA (ENCODE_FILE (filename)), longname,
+ if (!w32_get_long_filename (SSDATA (ENCODE_FILE (filename)), longname,
MAX_UTF8_PATH))
return Qnil;
program = Fexpand_file_name (program, Qnil);
encoded_progname = ENCODE_FILE (program);
- progname = SDATA (encoded_progname);
+ progname = SSDATA (encoded_progname);
unixtodos_filename (progname);
filename_to_ansi (progname, progname_a);
/* Reject file names that cannot be encoded in the current ANSI
codepage. */
- if (_mbspbrk (progname_a, "?"))
+ if (_mbspbrk ((unsigned char *)progname_a, (const unsigned char *)"?"))
return Qunknown;
if (w32_executable_type (progname_a, &is_dos_app, &is_cygwin_app,
(Lisp_Object cp)
{
CHARSETINFO info;
- DWORD dwcp;
+ DWORD_PTR dwcp;
CHECK_NUMBER (cp);
if (!IsValidCodePage (XINT (cp)))
return Qnil;
- /* Going through a temporary DWORD variable avoids compiler warning
+ /* Going through a temporary DWORD_PTR variable avoids compiler warning
about cast to pointer from integer of different size, when
- building --with-wide-int. */
+ building --with-wide-int or building for 64bit. */
dwcp = XINT (cp);
if (TranslateCharsetInfo ((DWORD *) dwcp, &info, TCI_SRCCODEPAGE))
return make_number (info.ciCharset);
return found_lcid;
}
-#ifndef _NSLCMPERROR
-# define _NSLCMPERROR INT_MAX
+#ifndef _NLSCMPERROR
+# define _NLSCMPERROR INT_MAX
#endif
#ifndef LINGUISTIC_IGNORECASE
# define LINGUISTIC_IGNORECASE 0x00000010
#endif
+typedef int (WINAPI *CompareStringW_Proc)
+ (LCID, DWORD, LPCWSTR, int, LPCWSTR, int);
+
int
w32_compare_strings (const char *s1, const char *s2, char *locname,
int ignore_case)
wchar_t *string1_w, *string2_w;
int val, needed;
extern BOOL g_b_init_compare_string_w;
- static int (WINAPI *pCompareStringW)(LCID, DWORD, LPCWSTR, int, LPCWSTR, int);
+ static CompareStringW_Proc pCompareStringW;
DWORD flags = 0;
USE_SAFE_ALLOCA;
{
if (os_subtype == OS_9X)
{
- pCompareStringW = GetProcAddress (LoadLibrary ("Unicows.dll"),
- "CompareStringW");
+ pCompareStringW =
+ (CompareStringW_Proc) GetProcAddress (LoadLibrary ("Unicows.dll"),
+ "CompareStringW");
if (!pCompareStringW)
{
errno = EINVAL;
/* This return value is compatible with wcscoll and
other MS CRT functions. */
- return _NSLCMPERROR;
+ return _NLSCMPERROR;
}
}
else
else
{
errno = EINVAL;
- return _NSLCMPERROR;
+ return _NLSCMPERROR;
}
needed = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, s2, -1, NULL, 0);
{
SAFE_FREE ();
errno = EINVAL;
- return _NSLCMPERROR;
+ return _NLSCMPERROR;
}
if (locname)
if (!val)
{
errno = EINVAL;
- return _NSLCMPERROR;
+ return _NLSCMPERROR;
}
return val - 2;
}