# HG changeset patch # User Claus Gittinger # Date 1236296551 -3600 # Node ID 0b0ea0b5235ef64ee5f48769949111af23944984 # Parent 0ca41183ee3e722d2d77bf2a5370d13f827725ca unicode support for removeFile, removeDirectory, createFile and createDirectory diff -r 0ca41183ee3e -r 0b0ea0b5235e Win32OperatingSystem.st --- a/Win32OperatingSystem.st Thu Mar 05 20:13:39 2009 +0100 +++ b/Win32OperatingSystem.st Fri Mar 06 00:42:31 2009 +0100 @@ -3872,23 +3872,48 @@ %{ if (__isString(aPathName)) { - int ret; - SECURITY_ATTRIBUTES sa; - - sa.nLength = sizeof( sa ); - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = TRUE; - - ret = CreateDirectory(__stringVal(aPathName), &sa); - if (ret != TRUE) { - __threadErrno = __WIN32_ERR(GetLastError()); - @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); - RETURN (false); - } - RETURN (true); - } -%}. - self primitiveFailed + int ret; + SECURITY_ATTRIBUTES sa; + + sa.nLength = sizeof( sa ); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; + + ret = CreateDirectoryA(__stringVal(aPathName), &sa); + if (ret != TRUE) { + __threadErrno = __WIN32_ERR(GetLastError()); + @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); + RETURN (false); + } + RETURN (true); + } + if (__isUnicode16String(aPathName)) { + int ret; + SECURITY_ATTRIBUTES sa; + wchar_t _wPathName[MAXPATHLEN+1]; + int i, l; + + l = __unicode16StringSize(aPathName); + if (l > MAXPATHLEN) l = MAXPATHLEN; + for (i=0; ia_element; int numAttrib = __arraySize(attributeSpec); - int i; + int i, l; DWORD access, share, create, attr; - if (! __isString(pathName)) { - fileHandle = nil; - argumentError = @symbol(badPathName); - goto badArgument; + if (__isString(pathName)) { + name = __stringVal(pathName); + } else if (__isUnicode16String(pathName)) { + l = __unicode16StringSize(pathName); + if (l > MAXPATHLEN) l = MAXPATHLEN; + for (i=0; i access:%x share:%x create:%x attr:%x\n", - name, access, share, create, attr); -#endif - h = CreateFile(name, access, share, 0 /* sa */, create, attr, 0 /* hTempl */); + name, access, share, create, attr); +#endif + if (__isString(pathName)) { + h = CreateFileA(name, access, share, 0 /* sa */, create, attr, 0 /* hTempl */); + } else { + h = CreateFileW(_wPathName, access, share, 0 /* sa */, create, attr, 0 /* hTempl */); + } + if (h != INVALID_HANDLE_VALUE) { - __externalAddressVal(fileHandle) = (void *)h; + __externalAddressVal(fileHandle) = (void *)h; } else { - fileHandle = nil; - errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) ); + fileHandle = nil; + errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) ); } badArgument: ; %}. fileHandle notNil ifTrue:[ - fileHandle registerForFinalization. - ^ fileHandle. + fileHandle registerForFinalization. + ^ fileHandle. ]. errorNumber isNil ifTrue:[ - self error:'invalid argument(s): ', argumentError. + self error:'invalid argument(s): ', argumentError. ] ifFalse:[ - (self errorHolderForNumber:errorNumber) reportError + (self errorHolderForNumber:errorNumber) reportError ]. ! @@ -4167,24 +4206,51 @@ if (__isString(fullPathName)) { #ifdef DO_WRAP_CALLS - { - char _aPathName[MAXPATHLEN]; - - strncpy(_aPathName, __stringVal(fullPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; - do { - __threadErrno = 0; - ret = STX_API_CALL1( "RemoveDirectory", RemoveDirectory, _aPathName); - } while ((ret < 0) && (__threadErrno == EINTR)); - } -#else - ret = RemoveDirectory((char *)__stringVal(fullPathName)); - __threadErrno = __WIN32_ERR(GetLastError()); -#endif - if (ret != TRUE) { - @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); - RETURN (false); - } - RETURN (true); + { + char _aPathName[MAXPATHLEN]; + + strncpy(_aPathName, __stringVal(fullPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; + do { + __threadErrno = 0; + ret = STX_API_CALL1( "RemoveDirectoryA", RemoveDirectoryA, _aPathName); + } while ((ret < 0) && (__threadErrno == EINTR)); + } +#else + ret = RemoveDirectoryA((char *)__stringVal(fullPathName)); + __threadErrno = __WIN32_ERR(GetLastError()); +#endif + if (ret != TRUE) { + @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); + RETURN (false); + } + RETURN (true); + } + if (__isUnicode16String(fullPathName)) { +#ifdef DO_WRAP_CALLS + { + wchar_t _wPathName[MAXPATHLEN+1]; + int i, l; + + l = __unicode16StringSize(fullPathName); + if (l > MAXPATHLEN) l = MAXPATHLEN; + for (i=0; i MAXPATHLEN) l = MAXPATHLEN; + for (i=0; i