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:
CaS 2005-11-05 16:20:19 +00:00
parent 44a6542243
commit e6fd4ca0d1
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> 2005-11-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSCompatibility.m: don't generate macos-x (xml) property * 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); void Win32_Utilities_fini(void);
/* ---- Environment Functions ---- */ /* ---- Environment Functions ---- */
NSString *Win32NSStringFromEnvironmentVariable(const char * envVar); NSString *Win32NSStringFromEnvironmentVariable(NSString *envVar);
/* ---- Registry Functions ---- */ /* ---- Registry Functions ---- */
HKEY Win32OpenRegistry(HKEY hive, const char *key); HKEY Win32OpenRegistry(HKEY hive, NSString *key);
NSString *Win32NSStringFromRegistry(HKEY regkey, NSString *regValue); NSString *Win32NSStringFromRegistry(HKEY regkey, NSString *regValue);
// NSNumber *Win32NSNumberFromRegistry(HKEY regkey, NSString *regValue); // NSNumber *Win32NSNumberFromRegistry(HKEY regkey, NSString *regValue);
// NSData *Win32NSDataFromRegistry(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 * Convert from OpenStep internal string format to a string in
* the local filesystem format, suitable for passing to system functions.<br /> * the local filesystem format, suitable for passing to system functions.<br />
* This representation may vary between filesystems.<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 * 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 * expected to be used in conjunction with the variants of system calls which
* work with unicode strings.<br /> * work with unicode strings.<br />
@ -232,6 +234,8 @@
/** /**
* Convert from OpenStep internal string format to a string in * Convert from OpenStep internal string format to a string in
* the local filesystem format, suitable for passing to system functions.<br /> * 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 /> * This representation may vary between filesystems.<br />
* On mingw32 systems, the filesystem representation is 16-bit unicode and is * 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 * 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 * Convert to OpenStep internal string format from a string in
* the local filesystem format, as returned by system functions.<br /> * the local filesystem format, as returned by system functions.<br />
* This representation may vary between filesystems.<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 * 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 * is expected to have come from the variant of a system call which works
* with unicode strings. * with unicode strings.
@ -271,6 +279,10 @@
* Convert to OpenStep internal string format from a string in * Convert to OpenStep internal string format from a string in
* the local filesystem format, as returned by system functions.<br /> * the local filesystem format, as returned by system functions.<br />
* This representation may vary between filesystems.<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 * 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 * is expected to have come from the variant of a system call which works
* with unicode strings. * with unicode strings.

View file

@ -341,7 +341,9 @@ enum {
* for long.<br /> * for long.<br />
* NB. On mingw32 systems the filesystem representation of a path is a 16-bit * 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 * 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; - (const unichar*) fileSystemRepresentation;
#else #else
@ -352,7 +354,9 @@ enum {
* for long.<br /> * for long.<br />
* NB. On mingw32 systems the filesystem representation of a path is a 16-bit * 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 * 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; - (const char*) fileSystemRepresentation;
#endif #endif
@ -361,10 +365,14 @@ enum {
/** /**
* Converts the receiver to a C string path using the character encoding * Converts the receiver to a C string path using the character encoding
* appropriate to the local file system. This string will be stored * 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 * 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 * 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 - (BOOL) getFileSystemRepresentation: (unichar*)buffer
maxLength: (unsigned int)size; maxLength: (unsigned int)size;
@ -372,10 +380,14 @@ enum {
/** /**
* Converts the receiver to a C string path using the character encoding * Converts the receiver to a C string path using the character encoding
* appropriate to the local file system. This string will be stored * 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 * 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 * 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 - (BOOL) getFileSystemRepresentation: (char*)buffer
maxLength: (unsigned int)size; 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__ #ifdef __MINGW32__
LPTSTR GetErrorMsg(DWORD msgId)
const char *GetErrorMsg(DWORD msgId)
{ {
LPVOID lpMsgBuf; void *lpMsgBuf = 0;
FormatMessage( FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_FROM_SYSTEM | | FORMAT_MESSAGE_IGNORE_INSERTS,
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
NULL, msgId, msgId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&lpMsgBuf, 0, NULL); (LPSTR)&lpMsgBuf,
(DWORD)0,
NULL);
return (LPTSTR)lpMsgBuf; return (const char*)lpMsgBuf;
} }
#else #else
#ifndef HAVE_STRERROR #ifndef HAVE_STRERROR

View file

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

View file

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

View file

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

View file

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

View file

@ -891,17 +891,18 @@ NSUserName(void)
#if defined(__WIN32__) #if defined(__WIN32__)
if (theUserName == nil) if (theUserName == nil)
{ {
const char *loginName = 0; const unichar *loginName = 0;
/* The GetUserName function returns the current user name */ /* The GetUserName function returns the current user name */
char buf[1024]; unichar buf[1024];
DWORD n = 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; loginName = buf;
else if (GetUserName(buf, &n) != 0 && buf[0] != '\0') else if (GetUserNameW(buf, &n) != 0 && buf[0] != '\0')
loginName = buf; loginName = buf;
if (loginName) if (loginName)
theUserName = [[NSString alloc] initWithCString: loginName]; theUserName = [[NSString alloc] initWithCharacters: loginName
length: wcslen(loginName)];
else else
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
format: @"Unable to determine current user name"]; format: @"Unable to determine current user name"];
@ -1078,11 +1079,12 @@ NSTemporaryDirectory(void)
#if !defined(__WIN32__) #if !defined(__WIN32__)
int uid; int uid;
#else #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 #endif

View file

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

View file

@ -3482,9 +3482,20 @@ static NSFileManager *fm = nil;
- (BOOL) getFileSystemRepresentation: (unichar*)buffer - (BOOL) getFileSystemRepresentation: (unichar*)buffer
maxLength: (unsigned int)size maxLength: (unsigned int)size
{ {
const unichar *ptr = [self fileSystemRepresentation]; const unichar *ptr;
unsigned i; 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++) for (i = 0; i < size; i++)
{ {
buffer[i] = ptr[i]; buffer[i] = ptr[i];
@ -3495,7 +3506,7 @@ static NSFileManager *fm = nil;
} }
if (i == size && ptr[i] != 0) if (i == size && ptr[i] != 0)
{ {
return NO; return NO; // Not at end.
} }
return YES; return YES;
} }
@ -3512,9 +3523,23 @@ static NSFileManager *fm = nil;
- (BOOL) getFileSystemRepresentation: (char*)buffer - (BOOL) getFileSystemRepresentation: (char*)buffer
maxLength: (unsigned int)size 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) if (strlen(ptr) > size)
return NO; {
return NO;
}
strcpy(buffer, ptr); strcpy(buffer, ptr);
return YES; return YES;
} }

View file

@ -1259,13 +1259,13 @@ static NSMapTable *absolutes = 0;
{ {
HKEY regkey; HKEY regkey;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, \ if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE, \
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", 0, KEY_READ, &regkey)) "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", 0, KEY_READ, &regkey))
{ {
char buf[255]; char buf[255];
DWORD bufsize=255; DWORD bufsize=255;
DWORD type; 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); bufsize=strlen(buf);
while (bufsize && isspace(buf[bufsize-1])) 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 *hour, int *minute, int *second, int *mil);
int dayOfCommonEra(NSTimeInterval when); 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 @implementation GSWindowsTimeZone
- (NSString*) abbreviationForDate: (NSDate*)aDate - (NSString*) abbreviationForDate: (NSDate*)aDate
@ -1752,14 +1759,14 @@ int dayOfCommonEra(NSTimeInterval when);
BOOL isNT = NO,regFound=NO; BOOL isNT = NO,regFound=NO;
/* Open the key in the local machine hive where the time zone data is stored. */ /* 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; isNT=YES;
regFound=YES; regFound=YES;
} }
else 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; regFound=YES;
} }
@ -1787,7 +1794,7 @@ int dayOfCommonEra(NSTimeInterval when);
BOOL tzFound = NO; BOOL tzFound = NO;
/* Get the class name and the value count. */ /* Get the class name and the value count. */
retCode = RegQueryInfoKey( retCode = RegQueryInfoKeyA(
regDirKey, // key handle regDirKey, // key handle
achClass, // buffer for class name achClass, // buffer for class name
&cchClassName, // size of class string &cchClassName, // size of class string
@ -1809,7 +1816,7 @@ int dayOfCommonEra(NSTimeInterval when);
{ {
cbName = 255; 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) if (retCode == ERROR_SUCCESS)
{ {
char keyBuffer[16384]; char keyBuffer[16384];
@ -1820,7 +1827,7 @@ int dayOfCommonEra(NSTimeInterval when);
else else
sprintf(keyBuffer,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones\\%s",achKey); 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 buf[256];
char standardName[256]; char standardName[256];
@ -1831,7 +1838,7 @@ int dayOfCommonEra(NSTimeInterval when);
/* check standardname */ /* check standardname */
standardName[0]='\0'; standardName[0]='\0';
bufsize=sizeof(buf); 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); strcpy(standardName,buf);
if (strcmp(standardName,cName) == 0) if (strcmp(standardName,cName) == 0)
@ -1841,7 +1848,7 @@ int dayOfCommonEra(NSTimeInterval when);
/* check daylightname */ /* check daylightname */
daylightName[0]='\0'; daylightName[0]='\0';
bufsize=sizeof(buf); 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); strcpy(daylightName,buf);
if (strcmp(daylightName,cName) == 0) if (strcmp(daylightName,cName) == 0)
@ -1852,7 +1859,7 @@ int dayOfCommonEra(NSTimeInterval when);
{ {
/* Read in the time zone data */ /* Read in the time zone data */
bufsize=sizeof(buf); 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; TZI *tzi = (void*)buf;
Bias = tzi->Bias; Bias = tzi->Bias;

View file

@ -292,14 +292,14 @@ objc_unload_modules(FILE *errorStream,
NSString * NSString *
objc_get_symbol_path(Class theClass, Category *theCategory) objc_get_symbol_path(Class theClass, Category *theCategory)
{ {
char buf[MAX_PATH]; unichar buf[MAX_PATH];
MEMORY_BASIC_INFORMATION memInfo; MEMORY_BASIC_INFORMATION memInfo;
NSCAssert(!theCategory, @"objc_get_symbol_path doesn't support categories"); NSCAssert(!theCategory, @"objc_get_symbol_path doesn't support categories");
VirtualQueryEx(GetCurrentProcess(), theClass, &memInfo, sizeof(memInfo)); 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; return 0;
} }

View file

@ -36,7 +36,7 @@ typedef void* dl_symbol_t;
static int static int
__objc_dynamic_init(const char* exec_path) __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 /* 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 static dl_handle_t
__objc_dynamic_link(const char* module, int mode, const char* debug_file) __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 /* Return the address of a symbol given by the name 'symbol' from the module

View file

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

View file

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

View file

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