Windows SWI upgrades
This commit is contained in:
parent
290e58e262
commit
5023da7893
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _DIRENT_H_INCLUDED
|
#ifndef _DIRENT_H_INCLUDED
|
||||||
@ -28,8 +28,8 @@
|
|||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
|
||||||
#undef _export
|
#undef _export
|
||||||
#if defined(_UXNT_KERNEL) && !defined(__LCC__)
|
#if defined(_UXNT_KERNEL) && !defined(__MINGW32__)
|
||||||
#define _export __declspec(dllexport)
|
#define _export _declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define _export extern
|
#define _export extern
|
||||||
#endif
|
#endif
|
||||||
@ -37,7 +37,7 @@
|
|||||||
#define DIRENT_MAX 512
|
#define DIRENT_MAX 512
|
||||||
|
|
||||||
typedef struct dirent
|
typedef struct dirent
|
||||||
{ void * data; /* actually WIN32_FIND_DATA * */
|
{ void * data; /* actually WIN32_FIND_DATA * */
|
||||||
int first;
|
int first;
|
||||||
void * handle; /* actually HANDLE */
|
void * handle; /* actually HANDLE */
|
||||||
/* dirent */
|
/* dirent */
|
||||||
|
@ -297,9 +297,9 @@ pt_popen(const char *cmd, const char *mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( pc->mode == 'r' )
|
if ( pc->mode == 'r' )
|
||||||
fptr = _fdopen(_open_osfhandle((long)pc->out[0],_O_BINARY),"r");
|
fptr = _fdopen(_open_osfhandle((intptr_t)pc->out[0],_O_BINARY),"r");
|
||||||
else
|
else
|
||||||
fptr = _fdopen(_open_osfhandle((long)pc->in[1],_O_BINARY),"w");
|
fptr = _fdopen(_open_osfhandle((intptr_t)pc->in[1],_O_BINARY),"w");
|
||||||
|
|
||||||
finito:
|
finito:
|
||||||
if ( fptr )
|
if ( fptr )
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
@ -31,7 +31,7 @@ UTF-8 Decoding, based on http://www.cl.cam.ac.uk/~mgk25/unicode.html
|
|||||||
#define CONT(i) ISUTF8_CB(in[1])
|
#define CONT(i) ISUTF8_CB(in[1])
|
||||||
#define VAL(i, s) ((in[i]&0x3f) << s)
|
#define VAL(i, s) ((in[i]&0x3f) << s)
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
_xos_utf8_get_char(const char *in, int *chr)
|
_xos_utf8_get_char(const char *in, int *chr)
|
||||||
{ /* 2-byte, 0x80-0x7ff */
|
{ /* 2-byte, 0x80-0x7ff */
|
||||||
if ( (in[0]&0xe0) == 0xc0 && CONT(1) )
|
if ( (in[0]&0xe0) == 0xc0 && CONT(1) )
|
||||||
@ -60,12 +60,12 @@ _xos_utf8_get_char(const char *in, int *chr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*chr = *in;
|
*chr = *in;
|
||||||
|
|
||||||
return (char *)in+1;
|
return (char *)in+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
_xos_utf8_put_char(char *out, int chr)
|
_xos_utf8_put_char(char *out, int chr)
|
||||||
{ if ( chr < 0x80 )
|
{ if ( chr < 0x80 )
|
||||||
{ *out++ = chr;
|
{ *out++ = chr;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -52,7 +52,7 @@
|
|||||||
((chr) < 0x80 ? out[0]=(char)(chr), out+1 \
|
((chr) < 0x80 ? out[0]=(char)(chr), out+1 \
|
||||||
: _xos_utf8_put_char(out, (chr)))
|
: _xos_utf8_put_char(out, (chr)))
|
||||||
|
|
||||||
extern char *_xos_utf8_get_char(const char *in, int *chr);
|
static char *_xos_utf8_get_char(const char *in, int *chr);
|
||||||
extern char *_xos_utf8_put_char(char *out, int chr);
|
static char *_xos_utf8_put_char(char *out, int chr);
|
||||||
|
|
||||||
#endif /*UTF8_H_INCLUDED*/
|
#endif /*UTF8_H_INCLUDED*/
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
/* $Id$
|
/* Part of SWI-Prolog
|
||||||
|
|
||||||
Part of SWI-Prolog
|
|
||||||
|
|
||||||
Author: Jan Wielemaker
|
Author: Jan Wielemaker
|
||||||
E-mail: jan@swi.psy.uva.nl
|
E-mail: J.Wielemaker@vu.nl
|
||||||
WWW: http://www.swi-prolog.org
|
WWW: http://www.swi-prolog.org
|
||||||
Copyright (C): 1985-2002, University of Amsterdam
|
Copyright (C): 1985-2012, University of Amsterdam
|
||||||
|
Vu University Amsterdam
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -19,7 +18,7 @@
|
|||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define UNICODE 1
|
#define UNICODE 1
|
||||||
@ -52,11 +51,6 @@
|
|||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MAXPATHLEN
|
|
||||||
#define MAXPATHLEN 256
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __LCC__
|
#ifdef __LCC__
|
||||||
#define _close close
|
#define _close close
|
||||||
#define _read read
|
#define _read read
|
||||||
@ -72,6 +66,10 @@
|
|||||||
#define XENOMAP 1
|
#define XENOMAP 1
|
||||||
#define XENOMEM 2
|
#define XENOMEM 2
|
||||||
|
|
||||||
|
#ifndef PATH_MAX
|
||||||
|
#define PATH_MAX 260
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
* ERRNO *
|
* ERRNO *
|
||||||
@ -146,6 +144,21 @@ utf8towcs(wchar_t *dest, const char *src, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
utf8_strlen(const char *s, size_t len)
|
||||||
|
{ const char *e = &s[len];
|
||||||
|
unsigned int l = 0;
|
||||||
|
|
||||||
|
while(s<e)
|
||||||
|
{ int chr;
|
||||||
|
|
||||||
|
s = utf8_get_char(s, &chr);
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
@ -169,11 +182,11 @@ existsAndWriteableDir(const TCHAR *name)
|
|||||||
|
|
||||||
char *
|
char *
|
||||||
_xos_home() /* expansion of ~ */
|
_xos_home() /* expansion of ~ */
|
||||||
{ static char home[MAXPATHLEN];
|
{ static char home[PATH_MAX];
|
||||||
static int done = FALSE;
|
static int done = FALSE;
|
||||||
|
|
||||||
if ( !done )
|
if ( !done )
|
||||||
{ TCHAR h[MAXPATHLEN];
|
{ TCHAR h[PATH_MAX];
|
||||||
|
|
||||||
/* Unix, set by user */
|
/* Unix, set by user */
|
||||||
if ( GetEnvironmentVariable(_T("HOME"), h, sizeof(h)) &&
|
if ( GetEnvironmentVariable(_T("HOME"), h, sizeof(h)) &&
|
||||||
@ -184,8 +197,8 @@ _xos_home() /* expansion of ~ */
|
|||||||
{ _xos_canonical_filenameW(h, home, sizeof(home), 0);
|
{ _xos_canonical_filenameW(h, home, sizeof(home), 0);
|
||||||
} else
|
} else
|
||||||
{ TCHAR d[100];
|
{ TCHAR d[100];
|
||||||
TCHAR p[MAXPATHLEN];
|
TCHAR p[PATH_MAX];
|
||||||
TCHAR tmp[MAXPATHLEN];
|
TCHAR tmp[PATH_MAX];
|
||||||
int haved, havep;
|
int haved, havep;
|
||||||
|
|
||||||
haved = GetEnvironmentVariable(_T("HOMEDRIVE"), d, sizeof(d));
|
haved = GetEnvironmentVariable(_T("HOMEDRIVE"), d, sizeof(d));
|
||||||
@ -245,7 +258,8 @@ _xos_os_filenameW(const char *cname, wchar_t *osname, size_t len)
|
|||||||
q += 3;
|
q += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( q[0] == '/' || q[0] == '\\' ) /* deal with //host/share */
|
if ( (q[0] == '/' || q[0] == '\\') &&
|
||||||
|
(q[1] == '/' || q[1] == '\\') ) /* deal with //host/share */
|
||||||
{ if ( s+1 >= e )
|
{ if ( s+1 >= e )
|
||||||
{ errno = ENAMETOOLONG;
|
{ errno = ENAMETOOLONG;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -600,7 +614,6 @@ _xos_fopen(const char *path, const char *mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
* FILE MANIPULATIONS *
|
* FILE MANIPULATIONS *
|
||||||
*******************************/
|
*******************************/
|
||||||
@ -608,11 +621,101 @@ _xos_fopen(const char *path, const char *mode)
|
|||||||
int
|
int
|
||||||
_xos_access(const char *path, int mode)
|
_xos_access(const char *path, int mode)
|
||||||
{ TCHAR buf[PATH_MAX];
|
{ TCHAR buf[PATH_MAX];
|
||||||
|
char sd_buf[512];
|
||||||
|
SECURITY_DESCRIPTOR *sd;
|
||||||
|
BOOL access_status;
|
||||||
|
DWORD desired_access = 0;
|
||||||
|
DWORD sd_size, granted_access;
|
||||||
|
HANDLE token = 0, imp_token = 0;
|
||||||
|
GENERIC_MAPPING generic_mapping;
|
||||||
|
PRIVILEGE_SET privelege_set;
|
||||||
|
DWORD priv_set_len = sizeof(PRIVILEGE_SET);
|
||||||
|
int retval = -1;
|
||||||
|
SECURITY_INFORMATION sec_info =
|
||||||
|
DACL_SECURITY_INFORMATION |
|
||||||
|
OWNER_SECURITY_INFORMATION |
|
||||||
|
GROUP_SECURITY_INFORMATION;
|
||||||
|
|
||||||
if ( !_xos_os_filenameW(path, buf, PATH_MAX) )
|
if ( !_xos_os_filenameW(path, buf, PATH_MAX) )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return _waccess(buf, mode);
|
if ( mode == F_OK )
|
||||||
|
return _waccess(buf, F_OK);
|
||||||
|
|
||||||
|
sd = (SECURITY_DESCRIPTOR*)&sd_buf;
|
||||||
|
if ( !GetFileSecurity(buf, sec_info, sd, sizeof(sd_buf), &sd_size) )
|
||||||
|
{ if ( GetLastError() == ERROR_INVALID_FUNCTION )
|
||||||
|
{ goto simple;
|
||||||
|
} else if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
|
||||||
|
{ errno = ENOENT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !(sd = malloc(sd_size)) )
|
||||||
|
{ errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !GetFileSecurity(buf, sec_info, sd, sd_size, &sd_size) )
|
||||||
|
goto simple;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mode & W_OK )
|
||||||
|
{ if ( _waccess(buf, W_OK ) < 0 ) /* read-only bit set */
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !OpenThreadToken(GetCurrentThread(),
|
||||||
|
TOKEN_DUPLICATE | TOKEN_READ,
|
||||||
|
TRUE,
|
||||||
|
&token) )
|
||||||
|
{ if ( GetLastError() != ERROR_NO_TOKEN )
|
||||||
|
goto simple;
|
||||||
|
|
||||||
|
if ( !OpenProcessToken(GetCurrentProcess(),
|
||||||
|
TOKEN_DUPLICATE | TOKEN_READ,
|
||||||
|
&token) )
|
||||||
|
goto simple;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !DuplicateToken(token,
|
||||||
|
SecurityImpersonation,
|
||||||
|
&imp_token) )
|
||||||
|
goto simple;
|
||||||
|
|
||||||
|
if (mode & R_OK) desired_access |= GENERIC_READ;
|
||||||
|
if (mode & W_OK) desired_access |= GENERIC_WRITE;
|
||||||
|
if (mode & X_OK) desired_access |= GENERIC_EXECUTE;
|
||||||
|
|
||||||
|
generic_mapping.GenericRead = FILE_GENERIC_READ;
|
||||||
|
generic_mapping.GenericWrite = FILE_GENERIC_WRITE;
|
||||||
|
generic_mapping.GenericExecute = FILE_GENERIC_EXECUTE;
|
||||||
|
generic_mapping.GenericAll = FILE_ALL_ACCESS;
|
||||||
|
MapGenericMask(&desired_access, &generic_mapping);
|
||||||
|
|
||||||
|
if ( !AccessCheck(sd,
|
||||||
|
imp_token,
|
||||||
|
desired_access,
|
||||||
|
&generic_mapping,
|
||||||
|
&privelege_set,
|
||||||
|
&priv_set_len,
|
||||||
|
&granted_access,
|
||||||
|
&access_status) )
|
||||||
|
goto simple;
|
||||||
|
|
||||||
|
if ( access_status )
|
||||||
|
retval = 0;
|
||||||
|
|
||||||
|
out:
|
||||||
|
if ( sd && (char*)sd != sd_buf ) free(sd);
|
||||||
|
if (imp_token) CloseHandle(imp_token);
|
||||||
|
if (token) CloseHandle(token);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
|
||||||
|
simple:
|
||||||
|
retval = _waccess(buf, mode);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -858,6 +961,7 @@ _xos_getenv(const char *name, char *buf, size_t buflen)
|
|||||||
size = GetEnvironmentVariable(nm, valp, size+1);
|
size = GetEnvironmentVariable(nm, valp, size+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size = wcslen(valp); /* return sometimes holds 0-bytes */
|
||||||
if ( wcstoutf8(buf, valp, buflen) )
|
if ( wcstoutf8(buf, valp, buflen) )
|
||||||
rc = strlen(buf);
|
rc = strlen(buf);
|
||||||
else
|
else
|
||||||
@ -876,16 +980,27 @@ _xos_getenv(const char *name, char *buf, size_t buflen)
|
|||||||
int
|
int
|
||||||
_xos_setenv(const char *name, char *value, int overwrite)
|
_xos_setenv(const char *name, char *value, int overwrite)
|
||||||
{ TCHAR nm[PATH_MAX];
|
{ TCHAR nm[PATH_MAX];
|
||||||
TCHAR val[PATH_MAX];
|
TCHAR buf[PATH_MAX];
|
||||||
|
TCHAR *val = buf;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if ( !utf8towcs(nm, name, PATH_MAX) )
|
if ( !utf8towcs(nm, name, PATH_MAX) )
|
||||||
return -1;
|
return -1;
|
||||||
if ( !overwrite && GetEnvironmentVariable(nm, NULL, 0) > 0 )
|
if ( !overwrite && GetEnvironmentVariable(nm, NULL, 0) > 0 )
|
||||||
return 0;
|
return 0;
|
||||||
if ( !utf8towcs(val, value, PATH_MAX) )
|
if ( !utf8towcs(val, value, PATH_MAX) )
|
||||||
return -1;
|
{ size_t wlen = utf8_strlen(value, strlen(value)) + 1;
|
||||||
|
|
||||||
if ( SetEnvironmentVariable(nm, val) )
|
if ( (val = malloc(wlen*sizeof(TCHAR))) == NULL )
|
||||||
|
return -1;
|
||||||
|
utf8towcs(val, value, wlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = SetEnvironmentVariable(nm, val);
|
||||||
|
if ( val != buf )
|
||||||
|
free(val);
|
||||||
|
|
||||||
|
if ( rc )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return -1; /* TBD: convert error */
|
return -1; /* TBD: convert error */
|
||||||
|
Reference in New Issue
Block a user