mingw32 unicode fixups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21955 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-11-05 16:20:19 +00:00
parent 4ef387ccd5
commit 8333380ff0
18 changed files with 314 additions and 191 deletions

View file

@ -1,3 +1,26 @@
2005-11-05 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Additions/GNUstepBase/Win32_Utilities.h:
* Headers/Foundation/NSFileManager.h:
* Headers/Foundation/NSString.h:
* Source/NSBundle.m:
* Source/NSData.m:
* Source/NSFileManager.m:
* Source/NSLog.m:
* Source/NSPathUtilities.m:
* Source/NSProcessInfo.m:
* Source/NSString.m:
* Source/NSTimeZone.m:
* Source/objc-load.m:
* Source/win32-load.h:
* Source/Additions/GSObjCRuntime.m:
* Source/win32/NSMessagePortWin32.m:
* Source/win32/NSUserDefaultsWin32.m:
* Source/win32/Win32_Utilities.m:
Attempt to rationalise mingw32 unicode support, use explicit unicode
methods throughput, fix several bugs where APIs were not using
unicode when they should have been doing.
2005-11-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSCompatibility.m: don't generate macos-x (xml) property

View file

@ -45,10 +45,10 @@ void Win32_Utilities_init(void);
void Win32_Utilities_fini(void);
/* ---- Environment Functions ---- */
NSString *Win32NSStringFromEnvironmentVariable(const char * envVar);
NSString *Win32NSStringFromEnvironmentVariable(NSString *envVar);
/* ---- Registry Functions ---- */
HKEY Win32OpenRegistry(HKEY hive, const char *key);
HKEY Win32OpenRegistry(HKEY hive, NSString *key);
NSString *Win32NSStringFromRegistry(HKEY regkey, NSString *regValue);
// NSNumber *Win32NSNumberFromRegistry(HKEY regkey, NSString *regValue);
// NSData *Win32NSDataFromRegistry(HKEY regkey, NSString *regValue);

View file

@ -222,6 +222,8 @@
* Convert from OpenStep internal string format to a string in
* the local filesystem format, suitable for passing to system functions.<br />
* This representation may vary between filesystems.<br />
* Converts the standard path separator ('/') and path extension ('.')
* characters to the local representation if necessary.<br />
* On mingw32 systems, the filesystem representation is 16-bit unicode and is
* expected to be used in conjunction with the variants of system calls which
* work with unicode strings.<br />
@ -232,6 +234,8 @@
/**
* Convert from OpenStep internal string format to a string in
* the local filesystem format, suitable for passing to system functions.<br />
* Converts the standard path separator ('/') and path extension ('.')
* characters to the local representation if necessary.<br />
* This representation may vary between filesystems.<br />
* On mingw32 systems, the filesystem representation is 16-bit unicode and is
* expected to be used in conjunction with the variants of system calls which
@ -260,6 +264,10 @@
* Convert to OpenStep internal string format from a string in
* the local filesystem format, as returned by system functions.<br />
* This representation may vary between filesystems.<br />
* The GNUstep version of this method currently does not bother to change
* any path separator and extension characters to the standard values
* ('/' and '.' respectively) as the path handling methods of [NSString]
* should be able to handle native format strings.<br />
* On mingw32 systems, the filesystem representation is 16-bit unicode and
* is expected to have come from the variant of a system call which works
* with unicode strings.
@ -271,6 +279,10 @@
* Convert to OpenStep internal string format from a string in
* the local filesystem format, as returned by system functions.<br />
* This representation may vary between filesystems.<br />
* The GNUstep version of this method currently does not bother to change
* any path separator and extension characters to the standard values
* ('/' and '.' respectively) as the path handling methods of [NSString]
* should be able to handle native format strings.<br />
* On mingw32 systems, the filesystem representation is 16-bit unicode and
* is expected to have come from the variant of a system call which works
* with unicode strings.

View file

@ -341,7 +341,9 @@ enum {
* for long.<br />
* NB. On mingw32 systems the filesystem representation of a path is a 16-bit
* unicode character string, so you should only pass the value returned by
* this method to functions expecting wide characters.
* this method to functions expecting wide characters.<br />
* This method uses [NSFileManager-fileSystemRepresentationWithPath:] to
* perform the conversion.
*/
- (const unichar*) fileSystemRepresentation;
#else
@ -352,7 +354,9 @@ enum {
* for long.<br />
* NB. On mingw32 systems the filesystem representation of a path is a 16-bit
* unicode character string, so you should only pass the value returned by
* this method to functions expecting wide characters.
* this method to functions expecting wide characters.<br />
* This method uses [NSFileManager-fileSystemRepresentationWithPath:] to
* perform the conversion.
*/
- (const char*) fileSystemRepresentation;
#endif
@ -361,10 +365,14 @@ enum {
/**
* Converts the receiver to a C string path using the character encoding
* appropriate to the local file system. This string will be stored
* into buffer if it is shorter than size, otherwise NO is returned.<br />
* into buffer if it is shorter (number of characters) than size,
* otherwise NO is returned.<br />
* NB. On mingw32 systems the filesystem representation of a path is a 16-bit
* unicode character string, so the buffer you pass to this method must be
* twice as many bytes as the size (number of characters) you expect to receive.
* twice as many bytes as the size (number of characters) you expect to
* receive.<br />
* This method uses [NSFileManager-fileSystemRepresentationWithPath:] to
* perform the conversion.
*/
- (BOOL) getFileSystemRepresentation: (unichar*)buffer
maxLength: (unsigned int)size;
@ -372,10 +380,14 @@ enum {
/**
* Converts the receiver to a C string path using the character encoding
* appropriate to the local file system. This string will be stored
* into buffer if it is shorter than size, otherwise NO is returned.<br />
* into buffer if it is shorter (number of characters) than size,
* otherwise NO is returned.<br />
* NB. On mingw32 systems the filesystem representation of a path is a 16-bit
* unicode character string, so the buffer you pass to this method must be
* twice as many bytes as the size (number of characters) you expect to receive.
* twice as many bytes as the size (number of characters) you expect to
* receive.<br />
* This method uses [NSFileManager-fileSystemRepresentationWithPath:] to
* perform the conversion.
*/
- (BOOL) getFileSystemRepresentation: (char*)buffer
maxLength: (unsigned int)size;

View file

@ -2213,21 +2213,27 @@ GSAutoreleasedBuffer(unsigned size)
/* Getting a system error message on a variety of systems */
/*
* Getting a system error message on a variety of systems.
* Currently 8bit string ... perhaps we should move to unicode.
*/
#ifdef __MINGW32__
LPTSTR GetErrorMsg(DWORD msgId)
const char *GetErrorMsg(DWORD msgId)
{
LPVOID lpMsgBuf;
void *lpMsgBuf = 0;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, msgId,
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
msgId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&lpMsgBuf, 0, NULL);
(LPSTR)&lpMsgBuf,
(DWORD)0,
NULL);
return (LPTSTR)lpMsgBuf;
return (const char*)lpMsgBuf;
}
#else
#ifndef HAVE_STRERROR

View file

@ -122,7 +122,7 @@ static NSString *library_combo =
const char *
objc_executable_location (void)
{
return [[_executable_path stringByDeletingLastPathComponent]
return (const char*)[[_executable_path stringByDeletingLastPathComponent]
fileSystemRepresentation];
}

View file

@ -64,11 +64,8 @@
*
*/
#if defined(__MINGW32__)
#define UNICODE
#define _UNICODE
#endif
#include "config.h"
#include "GNUstepBase/preface.h"
#include "GNUstepBase/GSObjCRuntime.h"
#include "Foundation/NSObjCRuntime.h"
#include "Foundation/NSByteOrder.h"
@ -1005,7 +1002,7 @@ static unsigned gsu32Align;
c = -1;
}
#else
if (MoveFileEx(wthePath, wtheRealPath, MOVEFILE_REPLACE_EXISTING) != 0)
if (MoveFileExW(wthePath, wtheRealPath, MOVEFILE_REPLACE_EXISTING) != 0)
{
c = 0;
}

View file

@ -38,13 +38,7 @@
#define _FILE_OFFSET_BITS 64
#if defined(__MINGW32__)
#define UNICODE
#define _UNICODE
#endif
#include "config.h"
#include <string.h>
#include "GNUstepBase/preface.h"
#include "Foundation/NSFileManager.h"
#include "Foundation/NSException.h"
@ -56,6 +50,7 @@
#include "Foundation/NSSet.h"
#include "GSPrivate.h"
#include <string.h>
#include <stdio.h>
/* determine directory reading files */
@ -79,9 +74,7 @@
#if defined(__MINGW32__)
#include <stdio.h>
#ifdef UNICODE
#include <wchar.h>
#endif
#define WIN32ERR ((DWORD)0xFFFFFFFF)
#endif
@ -183,7 +176,7 @@
* Macros to handle unichar filesystem support.
*/
#if defined(__MINGW32__) && defined(UNICODE)
#if defined(__MINGW32__)
#define _CHMOD(A,B) _wchmod(A,B)
#define _CLOSEDIR(A) _wclosedir(A)
@ -357,7 +350,7 @@ static NSStringEncoding defaultEncoding;
{
const _CHAR *lpath = (_CCP)[self fileSystemRepresentationWithPath: path];
#if defined(__MINGW32__)
return SetCurrentDirectory(lpath) == TRUE ? YES : NO;
return SetCurrentDirectoryW(lpath) == TRUE ? YES : NO;
#else
return (chdir(lpath) == 0) ? YES : NO;
#endif
@ -666,7 +659,7 @@ static NSStringEncoding defaultEncoding;
const _CHAR *lpath;
lpath = (_CCP)[self fileSystemRepresentationWithPath: completePath];
if (CreateDirectory(lpath, 0) == FALSE)
if (CreateDirectoryW(lpath, 0) == FALSE)
{
return NO;
}
@ -803,7 +796,7 @@ static NSStringEncoding defaultEncoding;
return NO;
#if defined(__MINGW32__)
fh = CreateFile(lpath, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
fh = CreateFileW(lpath, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
if (fh == INVALID_HANDLE_VALUE)
{
@ -879,25 +872,20 @@ static NSStringEncoding defaultEncoding;
NSString *currentDir = nil;
#if defined(__MINGW32__)
int len = GetCurrentDirectory(0, 0);
int len = GetCurrentDirectoryW(0, 0);
if (len > 0)
{
_CHAR *lpath = (_CHAR*)calloc(len+10,sizeof(_CHAR));
if (lpath != 0)
{
if (GetCurrentDirectory(len, lpath)>0)
if (GetCurrentDirectoryW(len, lpath)>0)
{
NSString *path;
// Windows may count the trailing nul ... we don't want to.
if (len > 0 && lpath[len] == 0) len--;
#ifdef UNICODE
path = [NSString stringWithCharacters: lpath length: len];
#else
path = [NSString stringWithCString: lpath length: len];
#endif
currentDir = path;
}
free(lpath);
@ -1226,7 +1214,7 @@ static NSStringEncoding defaultEncoding;
#if defined(__MINGW32__)
DWORD res;
res = GetFileAttributes(lpath);
res = GetFileAttributesW(lpath);
if (res == WIN32ERR)
{
@ -1254,7 +1242,7 @@ static NSStringEncoding defaultEncoding;
if (!is_dir)
{
#if defined(__MINGW32__)
if (DeleteFile(lpath) == FALSE)
if (DeleteFileW(lpath) == FALSE)
#else
if (unlink(lpath) < 0)
#endif
@ -1336,7 +1324,7 @@ static NSStringEncoding defaultEncoding;
{
DWORD res;
res = GetFileAttributes(lpath);
res = GetFileAttributesW(lpath);
if (res == WIN32ERR)
{
@ -1390,7 +1378,7 @@ static NSStringEncoding defaultEncoding;
{
DWORD res;
res = GetFileAttributes(lpath);
res = GetFileAttributesW(lpath);
if (res == WIN32ERR)
{
@ -1426,7 +1414,7 @@ static NSStringEncoding defaultEncoding;
{
DWORD res;
res = GetFileAttributes(lpath);
res = GetFileAttributesW(lpath);
if (res == WIN32ERR)
{
@ -1467,7 +1455,7 @@ static NSStringEncoding defaultEncoding;
{
DWORD res;
res = GetFileAttributes(lpath);
res = GetFileAttributesW(lpath);
if (res == WIN32ERR)
{
@ -1514,7 +1502,7 @@ static NSStringEncoding defaultEncoding;
{
DWORD res;
res = GetFileAttributes(lpath);
res = GetFileAttributesW(lpath);
if (res == WIN32ERR)
{
@ -1655,7 +1643,7 @@ static NSStringEncoding defaultEncoding;
DWORD TotalNumberClusters;
const _CHAR *lpath = (_CCP)[self fileSystemRepresentationWithPath: path];
if (!GetDiskFreeSpace(lpath, &SectorsPerCluster,
if (!GetDiskFreeSpaceW(lpath, &SectorsPerCluster,
&BytesPerSector, &NumberFreeClusters, &TotalNumberClusters))
{
return nil;
@ -1887,12 +1875,19 @@ static NSStringEncoding defaultEncoding;
#if defined(__MINGW__)
- (const unichar*) fileSystemRepresentationWithPath: (NSString*)path
{
NSRange r;
r = [path rangeOfString: @"/"];
if (r.length > 0)
{
path = [path stringByReplacingString: @"/" withString: @"\\"];
}
return (const unichar*)[path cStringUsingEncoding: NSUnicodeStringEncoding];
}
- (NSString*) stringWithFileSystemRepresentation: (const unichar*)string
length: (unsigned int)len
{
return [NSString stringWithCharacters: (const unichar*)string length: len/2];
return [NSString stringWithCharacters: string length: len];
}
#else
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
@ -2097,7 +2092,7 @@ inline void gsedRelease(GSEnumeratedDirectory X)
if (dirbuf)
{
#if defined(__MINGW32__) && defined(UNICODE)
#if defined(__MINGW32__)
/* Skip "." and ".." directory entries */
if (wcscmp(dirbuf->d_name, L".") == 0
|| wcscmp(dirbuf->d_name, L"..") == 0)
@ -2106,8 +2101,8 @@ inline void gsedRelease(GSEnumeratedDirectory X)
}
/* Name of file to return */
returnFileName = [_mgr
stringWithFileSystemRepresentation: (const char*)dirbuf->d_name
length: 2*wcslen(dirbuf->d_name)];
stringWithFileSystemRepresentation: dirbuf->d_name
length: wcslen(dirbuf->d_name)];
#else
/* Skip "." and ".." directory entries */
if (strcmp(dirbuf->d_name, ".") == 0
@ -2381,7 +2376,7 @@ inline void gsedRelease(GSEnumeratedDirectory X)
handler: (id)handler
{
#if defined(__MINGW32__)
if (CopyFile((_CCP)[self fileSystemRepresentationWithPath: source],
if (CopyFileW((_CCP)[self fileSystemRepresentationWithPath: source],
(_CCP)[self fileSystemRepresentationWithPath: destination], NO))
{
return YES;
@ -2863,7 +2858,7 @@ static NSSet *fileKeys = nil;
PSECURITY_DESCRIPTOR pSD;
// Get the handle of the file object.
hFile = CreateFile(
hFile = CreateFileW(
"myfile.txt",
GENERIC_READ,
FILE_SHARE_READ,
@ -2893,7 +2888,7 @@ static NSSet *fileKeys = nil;
sizeof(PSECURITY_DESCRIPTOR));
// Get the owner SID of the file.
dwRtnCode = GetSecurityInfo(
dwRtnCode = GetSecurityInfoW(
hFile,
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION,

View file

@ -41,6 +41,9 @@
#include <syslog.h>
#endif
#define UNISTR(X) \
((const unichar*)[(X) cStringUsingEncoding: NSUnicodeStringEncoding])
#if defined(HAVE_SYSLOG)
# if defined(LOG_ERR)
# if defined(LOG_USER)
@ -105,8 +108,12 @@ _NSLog_standard_printf_handler (NSString* message)
NSData *d;
const char *buf;
unsigned len;
#if defined(__WIN32__) || defined(HAVE_SYSLOG)
char *null_terminated_buf;
#if defined(__WIN32__)
LPCWSTR null_terminated_buf;
#else
#if defined(HAVE_SYSLOG)
char *null_terminated_buf;
#endif
#endif
static NSStringEncoding enc = 0;
@ -133,11 +140,9 @@ _NSLog_standard_printf_handler (NSString* message)
}
#if defined(__WIN32__)
null_terminated_buf = objc_malloc (sizeof (char) * (len + 1));
strncpy (null_terminated_buf, buf, len);
null_terminated_buf[len] = '\0';
null_terminated_buf = UNISTR(message);
OutputDebugString(null_terminated_buf);
OutputDebugStringW(null_terminated_buf);
if ((GSUserDefaultsFlag(GSLogSyslog) == YES
|| write(_NSLogDescriptor, buf, len) != (int)len) && !IsDebuggerPresent())
@ -147,22 +152,21 @@ _NSLog_standard_printf_handler (NSString* message)
if (!eventloghandle)
{
eventloghandle = RegisterEventSource(NULL,
[[[NSProcessInfo processInfo] processName] cString]);
UNISTR([[NSProcessInfo processInfo] processName]));
}
if (eventloghandle)
{
ReportEvent(eventloghandle, // event log handle
ReportEventW(eventloghandle, // event log handle
EVENTLOG_WARNING_TYPE, // event type
0, // category zero
0, // event identifier
NULL, // no user security identifier
1, // one substitution string
0, // no data
(LPCSTR*)&null_terminated_buf, // pointer to string array
&null_terminated_buf, // pointer to string array
NULL); // pointer to data
}
}
objc_free (null_terminated_buf);
#else
#if defined(HAVE_SYSLOG)

View file

@ -891,17 +891,18 @@ NSUserName(void)
#if defined(__WIN32__)
if (theUserName == nil)
{
const char *loginName = 0;
const unichar *loginName = 0;
/* The GetUserName function returns the current user name */
char buf[1024];
unichar buf[1024];
DWORD n = 1024;
if (GetEnvironmentVariable("LOGNAME", buf, 1024) != 0 && buf[0] != '\0')
if (GetEnvironmentVariableW(L"LOGNAME", buf, 1024) != 0 && buf[0] != '\0')
loginName = buf;
else if (GetUserName(buf, &n) != 0 && buf[0] != '\0')
else if (GetUserNameW(buf, &n) != 0 && buf[0] != '\0')
loginName = buf;
if (loginName)
theUserName = [[NSString alloc] initWithCString: loginName];
theUserName = [[NSString alloc] initWithCharacters: loginName
length: wcslen(loginName)];
else
[NSException raise: NSInternalInconsistencyException
format: @"Unable to determine current user name"];
@ -1078,11 +1079,12 @@ NSTemporaryDirectory(void)
#if !defined(__WIN32__)
int uid;
#else
char buffer[1024];
unichar buffer[1024];
if (GetTempPath(1024, buffer))
if (GetTempPathW(1024, buffer))
{
baseTempDirName = [NSString stringWithCString: buffer];
baseTempDirName = [NSString stringWithCharacters: buffer
length: wcslen(buffer)];
}
#endif

View file

@ -289,50 +289,69 @@ _gnu_process_args(int argc, char *argv[], char *env[])
NSMutableArray *keys = [NSMutableArray new];
NSMutableArray *values = [NSMutableArray new];
i = 0;
while (env[i])
{
#if defined(__MINGW32__)
char buf[1024];
char *cp;
DWORD len;
len = ExpandEnvironmentStrings(env[i], buf, 1022);
if (len > 1022)
{
char longbuf[len+2];
unichar *base;
len = ExpandEnvironmentStrings(env[i], longbuf, len);
cp = strchr(longbuf, '=');
*cp++ = '\0';
[keys addObject: [NSString stringWithCString: longbuf]];
[values addObject: [NSString stringWithCString: cp]];
}
else
{
if (len == 0)
strcpy(buf, env[i]);
cp = strchr(buf, '=');
*cp++ = '\0';
[keys addObject: [NSString stringWithCString: buf]];
[values addObject: [NSString stringWithCString: cp]];
}
#else
int len = strlen(env[i]);
char *cp = strchr(env[i], '=');
base = (unichar*)GetEnvironmentStringsW();
if (base != 0)
{
const unichar *start = base;
const unichar *wenvp = start;
if (len && cp)
while (*wenvp != 0)
{
char buf[len+2];
NSString *key;
NSString *val;
strcpy(buf, env[i]);
cp = &buf[cp - env[i]];
*cp++ = '\0';
[keys addObject: [NSString stringWithCString: buf]];
[values addObject: [NSString stringWithCString: cp]];
while (*wenvp != '=' && *wenvp != 0)
{
wenvp++;
}
if (*wenvp == '=')
{
key = [NSString stringWithCharacters: start
length: wenvp - start];
wenvp++;
start = wenvp;
}
else
{
break; // Bad format ... expected '='
}
while (*wenvp != 0)
{
wenvp++;
}
val = [NSString stringWithCharacters: start
length: wenvp - start];
wenvp++; // Skip past variable terminator
[keys addObject: key];
[values addObject: val];
}
FreeEnvironmentStringsW(base);
env = 0; // Suppress standard code.
}
#endif
i++;
if (env != 0)
{
i = 0;
while (env[i])
{
int len = strlen(env[i]);
char *cp = strchr(env[i], '=');
if (len && cp)
{
char buf[len+2];
strcpy(buf, env[i]);
cp = &buf[cp - env[i]];
*cp++ = '\0';
[keys addObject: [NSString stringWithCString: buf]];
[values addObject: [NSString stringWithCString: cp]];
}
i++;
}
}
IF_NO_GC(RELEASE(_gnu_environment));
_gnu_environment = [[NSDictionary alloc] initWithObjects: values

View file

@ -3482,9 +3482,20 @@ static NSFileManager *fm = nil;
- (BOOL) getFileSystemRepresentation: (unichar*)buffer
maxLength: (unsigned int)size
{
const unichar *ptr = [self fileSystemRepresentation];
const unichar *ptr;
unsigned i;
if (size == 0)
{
return NO;
}
if (buffer == 0)
{
[NSException raise: NSInvalidArgumentException
format: @"%@ given null pointer",
NSStringFromSelector(_cmd)];
}
ptr = [self fileSystemRepresentation];
for (i = 0; i < size; i++)
{
buffer[i] = ptr[i];
@ -3495,7 +3506,7 @@ static NSFileManager *fm = nil;
}
if (i == size && ptr[i] != 0)
{
return NO;
return NO; // Not at end.
}
return YES;
}
@ -3512,9 +3523,23 @@ static NSFileManager *fm = nil;
- (BOOL) getFileSystemRepresentation: (char*)buffer
maxLength: (unsigned int)size
{
const char* ptr = [self fileSystemRepresentation];
const char* ptr;
if (size == 0)
{
return NO;
}
if (buffer == 0)
{
[NSException raise: NSInvalidArgumentException
format: @"%@ given null pointer",
NSStringFromSelector(_cmd)];
}
ptr = [self fileSystemRepresentation];
if (strlen(ptr) > size)
return NO;
{
return NO;
}
strcpy(buffer, ptr);
return YES;
}

View file

@ -1259,13 +1259,13 @@ static NSMapTable *absolutes = 0;
{
HKEY regkey;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, \
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE, \
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", 0, KEY_READ, &regkey))
{
char buf[255];
DWORD bufsize=255;
DWORD type;
if (ERROR_SUCCESS==RegQueryValueEx(regkey, "StandardName", 0, &type, buf, &bufsize))
if (ERROR_SUCCESS==RegQueryValueExA(regkey, "StandardName", 0, &type, buf, &bufsize))
{
bufsize=strlen(buf);
while (bufsize && isspace(buf[bufsize-1]))
@ -1723,6 +1723,13 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
int *hour, int *minute, int *second, int *mil);
int dayOfCommonEra(NSTimeInterval when);
/* FIXME
* This is a horrible mess ... indentation etc all over the place.
* It's also not unicode ... which is OK as the timezone registry
* names are ascii ... but we ought to be consistent.
*/
@implementation GSWindowsTimeZone
- (NSString*) abbreviationForDate: (NSDate*)aDate
@ -1752,14 +1759,14 @@ int dayOfCommonEra(NSTimeInterval when);
BOOL isNT = NO,regFound=NO;
/* Open the key in the local machine hive where the time zone data is stored. */
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, &regDirKey))
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, &regDirKey))
{
isNT=YES;
regFound=YES;
}
else
{
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, &regDirKey))
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, &regDirKey))
{
regFound=YES;
}
@ -1787,7 +1794,7 @@ int dayOfCommonEra(NSTimeInterval when);
BOOL tzFound = NO;
/* Get the class name and the value count. */
retCode = RegQueryInfoKey(
retCode = RegQueryInfoKeyA(
regDirKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
@ -1809,7 +1816,7 @@ int dayOfCommonEra(NSTimeInterval when);
{
cbName = 255;
retCode = RegEnumKeyEx(regDirKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime);
retCode = RegEnumKeyExA(regDirKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime);
if (retCode == ERROR_SUCCESS)
{
char keyBuffer[16384];
@ -1820,7 +1827,7 @@ int dayOfCommonEra(NSTimeInterval when);
else
sprintf(keyBuffer,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones\\%s",achKey);
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyBuffer, 0, KEY_READ, &regKey))
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyBuffer, 0, KEY_READ, &regKey))
{
char buf[256];
char standardName[256];
@ -1831,7 +1838,7 @@ int dayOfCommonEra(NSTimeInterval when);
/* check standardname */
standardName[0]='\0';
bufsize=sizeof(buf);
if (ERROR_SUCCESS==RegQueryValueEx(regKey, "Std", 0, &type, buf, &bufsize))
if (ERROR_SUCCESS==RegQueryValueExA(regKey, "Std", 0, &type, buf, &bufsize))
{
strcpy(standardName,buf);
if (strcmp(standardName,cName) == 0)
@ -1841,7 +1848,7 @@ int dayOfCommonEra(NSTimeInterval when);
/* check daylightname */
daylightName[0]='\0';
bufsize=sizeof(buf);
if (ERROR_SUCCESS==RegQueryValueEx(regKey, "Dlt", 0, &type, buf, &bufsize))
if (ERROR_SUCCESS==RegQueryValueExA(regKey, "Dlt", 0, &type, buf, &bufsize))
{
strcpy(daylightName,buf);
if (strcmp(daylightName,cName) == 0)
@ -1852,7 +1859,7 @@ int dayOfCommonEra(NSTimeInterval when);
{
/* Read in the time zone data */
bufsize=sizeof(buf);
if (ERROR_SUCCESS==RegQueryValueEx(regKey, "TZI", 0, &type, buf, &bufsize))
if (ERROR_SUCCESS==RegQueryValueExA(regKey, "TZI", 0, &type, buf, &bufsize))
{
TZI *tzi = (void*)buf;
Bias = tzi->Bias;

View file

@ -292,14 +292,14 @@ objc_unload_modules(FILE *errorStream,
NSString *
objc_get_symbol_path(Class theClass, Category *theCategory)
{
char buf[MAX_PATH];
unichar buf[MAX_PATH];
MEMORY_BASIC_INFORMATION memInfo;
NSCAssert(!theCategory, @"objc_get_symbol_path doesn't support categories");
VirtualQueryEx(GetCurrentProcess(), theClass, &memInfo, sizeof(memInfo));
if (GetModuleFileName(memInfo.AllocationBase, buf, sizeof(buf)))
if (GetModuleFileNameW(memInfo.AllocationBase, buf, sizeof(buf)))
{
return [NSString stringWithCString:buf];
return [NSString stringWithCharacters: buf length: wcslen(buf)];
}
return 0;
}

View file

@ -36,7 +36,7 @@ typedef void* dl_symbol_t;
static int
__objc_dynamic_init(const char* exec_path)
{
return 0;
return 0;
}
/* Link in the module given by the name 'module'. Return a handle which can
@ -45,7 +45,7 @@ __objc_dynamic_init(const char* exec_path)
static dl_handle_t
__objc_dynamic_link(const char* module, int mode, const char* debug_file)
{
return LoadLibraryExW((const unichar*)module, 0, 0);
return LoadLibraryExW((const unichar*)module, 0, 0);
}
/* Return the address of a symbol given by the name 'symbol' from the module

View file

@ -49,6 +49,10 @@
#include <stdio.h>
#include <stdlib.h>
#define UNISTR(X) \
((const unichar*)[(X) cStringUsingEncoding: NSUnicodeStringEncoding])
/*
* Largest chunk of data possible in DO
*/
@ -248,7 +252,8 @@ static unsigned wordAlign;
if (shouldListen == YES)
{
myHandle(port) = CreateMailslot([myName(port) UTF8String],
myHandle(port) = CreateMailslotW(
UNISTR(myName(port)),
0, /* No max message size. */
MAILSLOT_WAIT_FOREVER, /* No read/write timeout. */
(LPSECURITY_ATTRIBUTES)0);
@ -280,7 +285,8 @@ static unsigned wordAlign;
}
else
{
myHandle(port) = CreateFile([myName(port) UTF8String],
myHandle(port) = CreateFileW(
UNISTR(myName(port)),
GENERIC_WRITE,
FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES)0,

View file

@ -9,6 +9,9 @@
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSProcessInfo.h>
#define UNISTR(X) \
((const unichar*)[(X) cStringUsingEncoding: NSUnicodeStringEncoding])
extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
@interface NSUserDefaultsWin32 : NSUserDefaults
@ -155,8 +158,8 @@ struct NSUserDefaultsWin32_DomainInfo
if (dinfo->userKey == 0)
{
rc = RegOpenKeyEx(HKEY_CURRENT_USER,
[dPath cString],
rc = RegOpenKeyExW(HKEY_CURRENT_USER,
UNISTR(dPath),
0,
STANDARD_RIGHTS_WRITE|STANDARD_RIGHTS_READ
|KEY_SET_VALUE|KEY_QUERY_VALUE,
@ -174,8 +177,8 @@ struct NSUserDefaultsWin32_DomainInfo
}
if (dinfo->systemKey == 0)
{
rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
[dPath cString],
rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
UNISTR(dPath),
0,
STANDARD_RIGHTS_READ|KEY_QUERY_VALUE,
&(dinfo->systemKey));
@ -201,7 +204,8 @@ struct NSUserDefaultsWin32_DomainInfo
if (dinfo->systemKey)
{
DWORD i = 0;
char *name = malloc(100), *data = malloc(1000);
unichar *name = malloc(200);
unsigned char *data = malloc(1000);
DWORD namelenbuf = 100, datalenbuf = 1000;
DWORD type;
@ -209,7 +213,7 @@ struct NSUserDefaultsWin32_DomainInfo
{
DWORD namelen = namelenbuf, datalen = datalenbuf;
rc = RegEnumValue(dinfo->systemKey,
rc = RegEnumValueW(dinfo->systemKey,
i,
name,
&namelen,
@ -224,9 +228,12 @@ struct NSUserDefaultsWin32_DomainInfo
id v;
NSString *k;
v = [NSString stringWithCString: data];
v = [NSString stringWithCString: data
encoding: NSASCIIStringEncoding];
v = [v propertyList];
k = [NSString stringWithCString: name];
k = AUTORELEASE([[NSString alloc] initWithBytes: name
length: namelen * sizeof(unichar)
encoding: NSUnicodeStringEncoding]);
[domainDict setObject: v forKey: k];
}
NS_HANDLER
@ -238,11 +245,11 @@ struct NSUserDefaultsWin32_DomainInfo
if (namelen >= namelenbuf)
{
namelenbuf = namelen + 1;
name = realloc(name, namelenbuf);
name = realloc(name, namelenbuf * sizeof(unichar));
}
if (datalen >= datalenbuf)
{
datalenbuf = datalen+1;
datalenbuf = datalen + 1;
data = realloc(data, datalenbuf);
}
continue;
@ -253,7 +260,7 @@ struct NSUserDefaultsWin32_DomainInfo
}
else
{
NSLog(@"RegEnumValue error %d", rc);
NSLog(@"RegEnumValueW error %d", rc);
break;
}
i++;
@ -265,7 +272,8 @@ struct NSUserDefaultsWin32_DomainInfo
if (dinfo->userKey)
{
DWORD i = 0;
char *name = malloc(100), *data = malloc(1000);
unichar *name = malloc(200);
unsigned char *data = malloc(1000);
DWORD namelenbuf = 100, datalenbuf = 1000;
DWORD type;
@ -273,7 +281,7 @@ struct NSUserDefaultsWin32_DomainInfo
{
DWORD namelen = namelenbuf, datalen = datalenbuf;
rc = RegEnumValue(dinfo->userKey,
rc = RegEnumValueW(dinfo->userKey,
i,
name,
&namelen,
@ -288,9 +296,12 @@ struct NSUserDefaultsWin32_DomainInfo
id v;
NSString *k;
v = [NSString stringWithCString: data];
v = [NSString stringWithCString: data
encoding: NSASCIIStringEncoding];
v = [v propertyList];
k = [NSString stringWithCString: name];
k = AUTORELEASE([[NSString alloc] initWithBytes: name
length: namelen * sizeof(unichar)
encoding: NSUnicodeStringEncoding]);
[domainDict setObject: v forKey: k];
}
NS_HANDLER
@ -302,11 +313,11 @@ struct NSUserDefaultsWin32_DomainInfo
if (namelen >= namelenbuf)
{
namelenbuf = namelen + 1;
name = realloc(name, namelenbuf);
name = realloc(name, namelenbuf * sizeof(unichar));
}
if (datalen >= datalenbuf)
{
datalenbuf = datalen+1;
datalenbuf = datalen + 1;
data = realloc(data, datalenbuf);
}
continue;
@ -317,7 +328,7 @@ struct NSUserDefaultsWin32_DomainInfo
}
else
{
NSLog(@"RegEnumValue error %d", rc);
NSLog(@"RegEnumValueW error %d", rc);
break;
}
i++;
@ -378,8 +389,8 @@ struct NSUserDefaultsWin32_DomainInfo
else
{
// If the key didn't exist, but now it does, we want to read it.
rc = RegOpenKeyEx(HKEY_CURRENT_USER,
[dPath cString],
rc = RegOpenKeyExW(HKEY_CURRENT_USER,
UNISTR(dPath),
0,
STANDARD_RIGHTS_WRITE|STANDARD_RIGHTS_READ
|KEY_SET_VALUE|KEY_QUERY_VALUE,
@ -423,8 +434,8 @@ struct NSUserDefaultsWin32_DomainInfo
else
{
// If the key didn't exist, but now it does, we want to read it.
rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
[dPath cString],
rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
UNISTR(dPath),
0,
STANDARD_RIGHTS_READ|KEY_QUERY_VALUE,
&(dinfo->systemKey));
@ -489,10 +500,10 @@ struct NSUserDefaultsWin32_DomainInfo
}
if (dinfo->userKey == 0)
{
rc = RegCreateKeyEx(HKEY_CURRENT_USER,
[dPath cString],
rc = RegCreateKeyExW(HKEY_CURRENT_USER,
UNISTR(dPath),
0,
"",
L"",
REG_OPTION_NON_VOLATILE,
STANDARD_RIGHTS_WRITE|STANDARD_RIGHTS_READ|KEY_SET_VALUE
|KEY_QUERY_VALUE,
@ -515,11 +526,17 @@ struct NSUserDefaultsWin32_DomainInfo
if (oldvalue == nil || [value isEqual: oldvalue] == NO)
{
NSString *result = 0;
NSString *result = nil;
const unsigned char *ptr;
GSPropertyListMake(value, nil, NO, NO, 0, &result);
rc = RegSetValueEx(dinfo->userKey, [valName cString], 0,
REG_SZ, [result cString], [result cStringLength]+1);
ptr = [result cStringUsingEncoding: NSASCIIStringEncoding];
rc = RegSetValueExW(dinfo->userKey,
UNISTR(valName),
0,
REG_SZ,
ptr,
strlen(ptr) + 1);
if (rc != ERROR_SUCCESS)
{
NSLog(@"Failed to insert HKEY_CURRENT_USER\\%@\\%@ (%x)",
@ -535,7 +552,7 @@ struct NSUserDefaultsWin32_DomainInfo
if ([domainDict objectForKey: valName] == nil)
{
// Delete value from registry
rc = RegDeleteValue(dinfo->userKey, [valName cString]);
rc = RegDeleteValueW(dinfo->userKey, UNISTR(valName));
if (rc != ERROR_SUCCESS)
{
NSLog(@"Failed to delete HKEY_CURRENT_USER\\%@\\%@ (%x)",

View file

@ -28,6 +28,9 @@
#include "GNUstepBase/Win32_Utilities.h"
#define UNISTR(X) \
((const unichar*)[(X) cStringUsingEncoding: NSUnicodeStringEncoding])
/* ------------------ */
/* Internal Variables */
/* ------------------ */
@ -41,11 +44,11 @@
* Returns a hive key or 0 if unable.
*/
HKEY
Win32OpenRegistry(HKEY hive, const char *key)
Win32OpenRegistryW(HKEY hive, NSString *key)
{
HKEY regkey;
if (ERROR_SUCCESS == RegOpenKeyEx(hive, key, 0, KEY_READ, &regkey))
if (RegOpenKeyExW(hive, UNISTR(key), 0, KEY_READ, &regkey) == ERROR_SUCCESS)
{
return regkey;
}
@ -59,20 +62,16 @@ Win32OpenRegistry(HKEY hive, const char *key)
NSString *
Win32NSStringFromRegistry(HKEY regkey, NSString *regValue)
{
char buf[MAX_PATH];
DWORD bufsize=MAX_PATH;
unichar buf[MAX_PATH];
DWORD bufsize = MAX_PATH;
DWORD type;
if (ERROR_SUCCESS==RegQueryValueEx(regkey, [regValue cString], 0, &type, buf, &bufsize))
if (RegQueryValueExW(regkey, UNISTR(regValue), 0, &type, (unsigned char*)buf,
&bufsize) == ERROR_SUCCESS)
{
// FIXME: Check type is correct!
bufsize=strlen(buf);
while (bufsize && isspace(buf[bufsize-1]))
{
bufsize--;
}
return [NSString stringWithCString:buf length:bufsize];
// FIXME check type is correct
return [NSString stringWithCharacters: buf
length: bufsize / sizeof(unichar)];
}
return nil;
}
@ -89,31 +88,29 @@ Win32NSStringFromRegistry(HKEY regkey, NSString *regValue)
* Obtains an NSString for the environment variable named envVar.
*/
NSString *
Win32NSStringFromEnvironmentVariable(const char * envVar)
Win32NSStringFromEnvironmentVariable(NSString *envVar)
{
char buf[1024], *nb;
unichar buf[1024], *nb;
DWORD n;
NSString *s = nil;
[gnustep_global_lock lock];
n = GetEnvironmentVariable(envVar, buf, 1024);
n = GetEnvironmentVariableW(UNISTR(envVar), buf, 1024);
if (n > 1024)
{
/* Buffer not big enough, so dynamically allocate it */
nb = (char *)NSZoneMalloc(NSDefaultMallocZone(), sizeof(char)*(n+1));
nb = (unichar *)NSZoneMalloc(NSDefaultMallocZone(),
sizeof(unichar)*(n + 1));
if (nb != NULL)
{
n = GetEnvironmentVariable(envVar, nb, n+1);
nb[n] = '\0';
s = [NSString stringWithCString: nb];
n = GetEnvironmentVariableW(UNISTR(envVar), nb, n + 1);
s = [NSString stringWithCharacters: nb length: n];
NSZoneFree(NSDefaultMallocZone(), nb);
}
}
else if (n > 0)
{
/* null terminate it and return the string */
buf[n] = '\0';
s = [NSString stringWithCString: buf];
s = [NSString stringWithCharacters: buf length: n];
}
[gnustep_global_lock unlock];
return s;
@ -141,15 +138,15 @@ Win32GetUserProfileDirectory(NSString *loginName)
* unusable because it contains spaces), we use HOMEPATH in
* preference to USERPROFILE.
*/
s = Win32NSStringFromEnvironmentVariable("HOMEPATH");
s = Win32NSStringFromEnvironmentVariable(@"HOMEPATH");
if (s != nil && ([s length] < 2 || [s characterAtIndex: 1] != ':'))
{
s = [Win32NSStringFromEnvironmentVariable("HOMEDRIVE")
s = [Win32NSStringFromEnvironmentVariable(@"HOMEDRIVE")
stringByAppendingString: s];
}
if (s == nil)
{
s = Win32NSStringFromEnvironmentVariable("USERPROFILE");
s = Win32NSStringFromEnvironmentVariable(@"USERPROFILE");
}
if (s == nil)
@ -162,7 +159,8 @@ Win32GetUserProfileDirectory(NSString *loginName)
else
{
s = nil;
NSLog(@"Trying to get home for '%@' when user is '%@'", loginName, NSUserName());
NSLog(@"Trying to get home for '%@' when user is '%@'",
loginName, NSUserName());
NSLog(@"Can't determine other user home directories in Win32.");
}
@ -179,7 +177,7 @@ Win32GetUserProfileDirectory(NSString *loginName)
* Locates specified directory on Win32 systems
*/
NSString *
Win32FindDirectory( DWORD DirCSIDL)
Win32FindDirectory(DWORD DirCSIDL)
{
[NSException raise: NSInternalInconsistencyException
format: @"Not implemented! Can't find directories in Win32."];