3245 "/ command.com command-line parsing here (sigh). |
3250 "/ command.com command-line parsing here (sigh). |
3246 |
3251 |
3247 hasRedirection := (aCommandString isNil or:[aCommandString includesAny:'<>|']). |
3252 hasRedirection := (aCommandString isNil or:[aCommandString includesAny:'<>|']). |
3248 |
3253 |
3249 hasRedirection ifFalse:[ |
3254 hasRedirection ifFalse:[ |
3250 "/ test whether the commandString is an executable; |
3255 "/ test whether the commandString is an executable; |
3251 "/ then, no shell is required |
3256 "/ then, no shell is required |
3252 cmdName := aCommandString withoutSeparators. |
3257 cmdName := aCommandString withoutSeparators. |
3253 (cmdName notEmpty and:[(cmdName startsWith:$") not]) ifTrue:[ |
3258 (cmdName notEmpty and:[(cmdName startsWith:$") not]) ifTrue:[ |
3254 |index file suffix| |
3259 |index file suffix| |
3255 |
3260 |
3256 index := cmdName indexOfSeparatorStartingAt:1. |
3261 index := cmdName indexOfSeparatorStartingAt:1. |
3257 index ~~ 0 ifTrue:[ |
3262 index ~~ 0 ifTrue:[ |
3258 args := cmdName copyFrom:(index+1). |
3263 args := cmdName copyFrom:(index+1). |
3259 cmdName := cmdName copyFrom:1 to:(index-1). |
3264 cmdName := cmdName copyFrom:1 to:(index-1). |
3260 ] ifFalse:[ |
3265 ] ifFalse:[ |
3261 args := ''. |
3266 args := ''. |
3262 ]. |
3267 ]. |
3263 |
3268 |
3264 file := cmdName asFilename. |
3269 file := cmdName asFilename. |
3265 suffix := file suffix. |
3270 suffix := file suffix. |
3266 |
3271 |
3267 suffix isEmptyOrNil ifTrue:[ |
3272 suffix isEmptyOrNil ifTrue:[ |
3268 suffix := 'exe'. |
3273 suffix := 'exe'. |
3269 file := file withSuffix:suffix. |
3274 file := file withSuffix:suffix. |
3270 ]. |
3275 ]. |
3271 |
3276 |
3272 (file exists and:[suffix = 'exe' or:[suffix = 'com']]) ifTrue:[ |
3277 (file exists and:[suffix = 'exe' or:[suffix = 'com']]) ifTrue:[ |
3273 "/ is an executable, no shell required |
3278 "/ is an executable, no shell required |
3274 path := file fullAlternativePathName. |
3279 path := file fullAlternativePathName. |
3275 ^ Array with:path with:aCommandString. |
3280 ^ Array with:path with:aCommandString. |
3276 "/ ^ Array with:path with:(path, ' ', args). |
3281 "/ ^ Array with:path with:(path, ' ', args). |
3277 ]. |
3282 ]. |
3278 path := self pathOfCommand:cmdName. |
3283 path := self pathOfCommand:cmdName. |
3279 path notNil ifTrue:[ |
3284 path notNil ifTrue:[ |
3280 "/ is an executable, no shell required |
3285 "/ is an executable, no shell required |
3281 ^ Array with:path with:aCommandString. |
3286 ^ Array with:path with:aCommandString. |
3282 "/ ^ Array with:path with:(path, ' ', args). |
3287 "/ ^ Array with:path with:(path, ' ', args). |
3283 ]. |
3288 ]. |
3284 ]. |
3289 ]. |
3285 ]. |
3290 ]. |
3286 |
3291 |
3287 shell := self getEnvironment:'COMSPEC'. |
3292 shell := self getEnvironment:'COMSPEC'. |
3288 shell isNil ifTrue:[ |
3293 shell isNil ifTrue:[ |
3289 wDir := self getWindowsSystemDirectory asFilename. |
3294 wDir := self getWindowsSystemDirectory asFilename. |
3290 shell := #('cmd.exe' 'command.com') detect:[:eachCommand| |
3295 shell := #('cmd.exe' 'command.com') detect:[:eachCommand| |
3291 (wDir / eachCommand) isExecutable |
3296 (wDir / eachCommand) isExecutable |
3292 ] ifNone:[ |
3297 ] ifNone:[ |
3293 self error:'no cmd.exe available'. |
3298 self error:'no cmd.exe available'. |
3294 ]. |
3299 ]. |
3295 shell := (wDir / shell) pathName. |
3300 shell := (wDir / shell) pathName. |
3296 ]. |
3301 ]. |
3297 |
3302 |
3298 aCommandString isEmptyOrNil ifTrue:[ |
3303 aCommandString isEmptyOrNil ifTrue:[ |
3299 ^ Array with:shell with:nil |
3304 ^ Array with:shell with:nil |
3300 ]. |
3305 ]. |
3301 |
3306 |
3302 ^ Array with:shell with:(' /c "' , aCommandString, '"') |
3307 ^ Array with:shell with:(' /c "' , aCommandString, '"') |
3303 |
3308 |
3304 " |
3309 " |
3313 |
3318 |
3314 exec:aCommandPath withArguments:argString environment:environment fileDescriptors:fdArray fork:doFork newPgrp:newPgrp inDirectory:aDirectory |
3319 exec:aCommandPath withArguments:argString environment:environment fileDescriptors:fdArray fork:doFork newPgrp:newPgrp inDirectory:aDirectory |
3315 "Internal lowLevel entry for combined fork & exec for WIN32 |
3320 "Internal lowLevel entry for combined fork & exec for WIN32 |
3316 |
3321 |
3317 If fork is false (chain a command): |
3322 If fork is false (chain a command): |
3318 execute the OS command specified by the argument, aCommandPath, with |
3323 execute the OS command specified by the argument, aCommandPath, with |
3319 arguments in argArray (no arguments, if nil). |
3324 arguments in argArray (no arguments, if nil). |
3320 If successful, this method does not return and smalltalk is gone. |
3325 If successful, this method does not return and smalltalk is gone. |
3321 If not successful, it does return. |
3326 If not successful, it does return. |
3322 Normal use is with forkForCommand. |
3327 Normal use is with forkForCommand. |
3323 |
3328 |
3324 If fork is true (subprocess command execution): |
3329 If fork is true (subprocess command execution): |
3325 fork a child to do the above. |
3330 fork a child to do the above. |
3326 The process id of the child process is returned; nil if the fork failed. |
3331 The process id of the child process is returned; nil if the fork failed. |
3327 |
3332 |
3328 fdArray contains the filedescriptors, to be used for the child (if fork is true). |
3333 fdArray contains the filedescriptors, to be used for the child (if fork is true). |
3329 fdArray[1] = 15 -> use fd 15 as stdin. |
3334 fdArray[1] = 15 -> use fd 15 as stdin. |
3330 If an element of the array is set to nil, the corresponding filedescriptor |
3335 If an element of the array is set to nil, the corresponding filedescriptor |
3331 will be closed for the child. |
3336 will be closed for the child. |
3332 fdArray[0] == StdIn for child |
3337 fdArray[0] == StdIn for child |
3333 fdArray[1] == StdOut for child |
3338 fdArray[1] == StdOut for child |
3334 fdArray[2] == StdErr for child |
3339 fdArray[2] == StdErr for child |
3335 on VMS, these must be channels as returned by createMailBox. |
3340 on VMS, these must be channels as returned by createMailBox. |
3336 |
3341 |
3337 NOTE that in WIN32 the fds are HANDLES. |
3342 NOTE that in WIN32 the fds are HANDLES. |
3338 |
3343 |
3339 If newPgrp is true, the subprocess will be established in a new process group. |
3344 If newPgrp is true, the subprocess will be established in a new process group. |
3340 The processgroup will be equal to id. |
3345 The processgroup will be equal to id. |
3341 newPgrp is not used on WIN32 and VMS systems." |
3346 newPgrp is not used on WIN32 and VMS systems." |
3342 |
3347 |
3343 |dirPath rslt| |
3348 |dirPath rslt| |
3344 |
3349 |
3345 aDirectory notNil ifTrue:[ |
3350 aDirectory notNil ifTrue:[ |
3346 dirPath := aDirectory asFilename asAbsoluteFilename osNameForDirectory. |
3351 dirPath := aDirectory asFilename asAbsoluteFilename osNameForDirectory. |
3347 (dirPath endsWith:':') ifTrue:[ |
3352 (dirPath endsWith:':') ifTrue:[ |
3348 dirPath := dirPath , '\'. |
3353 dirPath := dirPath , '\'. |
3349 ]. |
3354 ]. |
3350 ]. |
3355 ]. |
3351 |
3356 |
3352 rslt := self |
3357 rslt := self |
3353 primExec:aCommandPath |
3358 primExec:aCommandPath |
3354 commandLine:argString |
3359 commandLine:argString |
3355 fileDescriptors:fdArray |
3360 fileDescriptors:fdArray |
3356 fork:doFork |
3361 fork:doFork |
3357 newPgrp:newPgrp |
3362 newPgrp:newPgrp |
3358 inPath:dirPath |
3363 inPath:dirPath |
3359 createFlags:nil. |
3364 createFlags:nil. |
3360 |
3365 |
3361 "/ 'created ' print. cmdLine print. ' -> ' print. rslt printCR. |
3366 "/ 'created ' print. cmdLine print. ' -> ' print. rslt printCR. |
3362 ^ rslt |
3367 ^ rslt |
3363 |
3368 |
3364 "Modified: / 31.1.1998 / 10:54:24 / md" |
3369 "Modified: / 31.1.1998 / 10:54:24 / md" |
3566 PROCESS_INFORMATION lppiProcInfo; |
3571 PROCESS_INFORMATION lppiProcInfo; |
3567 SECURITY_ATTRIBUTES sa; |
3572 SECURITY_ATTRIBUTES sa; |
3568 SECURITY_DESCRIPTOR sd; |
3573 SECURITY_DESCRIPTOR sd; |
3569 |
3574 |
3570 if ((__isStringLike(commandPath) || (commandPath == nil)) && __isStringLike(commandLine)) { |
3575 if ((__isStringLike(commandPath) || (commandPath == nil)) && __isStringLike(commandLine)) { |
3571 if (commandPath != nil) { |
3576 if (commandPath != nil) { |
3572 cmdPath = __stringVal(commandPath); |
3577 cmdPath = __stringVal(commandPath); |
3573 } |
3578 } |
3574 cmdLine = __stringVal(commandLine); |
3579 cmdLine = __stringVal(commandLine); |
3575 |
3580 |
3576 if (__isStringLike(dirName)) { |
3581 if (__isStringLike(dirName)) { |
3577 dir = __stringVal(dirName); |
3582 dir = __stringVal(dirName); |
3578 } |
3583 } |
3579 |
3584 |
3580 /* |
3585 /* |
3581 * create descriptors as req'd |
3586 * create descriptors as req'd |
3582 */ |
3587 */ |
3583 memset(&sa, 0, sizeof (sa)); |
3588 memset(&sa, 0, sizeof (sa)); |
3584 sa.nLength = sizeof( sa ); |
3589 sa.nLength = sizeof( sa ); |
3585 sa.lpSecurityDescriptor = NULL; |
3590 sa.lpSecurityDescriptor = NULL; |
3586 sa.bInheritHandle = TRUE; |
3591 sa.bInheritHandle = TRUE; |
3587 InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); |
3592 InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); |
3588 SetSecurityDescriptorDacl(&sd, -1, 0, 0); |
3593 SetSecurityDescriptorDacl(&sd, -1, 0, 0); |
3589 |
3594 |
3590 sa.lpSecurityDescriptor = &sd; |
3595 sa.lpSecurityDescriptor = &sd; |
3591 memset(&lppiProcInfo, 0, sizeof (lppiProcInfo)); |
3596 memset(&lppiProcInfo, 0, sizeof (lppiProcInfo)); |
3592 |
3597 |
3593 memset(&lpsiStartInfo, 0, sizeof (lpsiStartInfo)); |
3598 memset(&lpsiStartInfo, 0, sizeof (lpsiStartInfo)); |
3594 lpsiStartInfo.cb = sizeof(lpsiStartInfo); |
3599 lpsiStartInfo.cb = sizeof(lpsiStartInfo); |
3595 lpsiStartInfo.lpReserved = NULL; |
3600 lpsiStartInfo.lpReserved = NULL; |
3596 lpsiStartInfo.lpDesktop = NULL; |
3601 lpsiStartInfo.lpDesktop = NULL; |
3597 lpsiStartInfo.lpTitle = NULL; |
3602 lpsiStartInfo.lpTitle = NULL; |
3598 lpsiStartInfo.dwX = 0; |
3603 lpsiStartInfo.dwX = 0; |
3599 lpsiStartInfo.dwY = 0; |
3604 lpsiStartInfo.dwY = 0; |
3600 lpsiStartInfo.dwXSize = 100; |
3605 lpsiStartInfo.dwXSize = 100; |
3601 lpsiStartInfo.dwYSize = 100; |
3606 lpsiStartInfo.dwYSize = 100; |
3602 lpsiStartInfo.dwXCountChars = 0; |
3607 lpsiStartInfo.dwXCountChars = 0; |
3603 lpsiStartInfo.dwYCountChars = 0; |
3608 lpsiStartInfo.dwYCountChars = 0; |
3604 lpsiStartInfo.dwFillAttribute = 0; |
3609 lpsiStartInfo.dwFillAttribute = 0; |
3605 if (0 /*__isWinNT*/) { |
3610 if (0 /*__isWinNT*/) { |
3606 lpsiStartInfo.dwFlags = STARTF_USESTDHANDLES; |
3611 lpsiStartInfo.dwFlags = STARTF_USESTDHANDLES; |
3607 lpsiStartInfo.wShowWindow = SW_SHOWDEFAULT; |
3612 lpsiStartInfo.wShowWindow = SW_SHOWDEFAULT; |
3608 } else { |
3613 } else { |
3609 lpsiStartInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES /*| STARTF_USEPOSITION*/; |
3614 lpsiStartInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES /*| STARTF_USEPOSITION*/; |
3610 lpsiStartInfo.wShowWindow = SW_HIDE /*SW_SHOWDEFAULT*/; |
3615 lpsiStartInfo.wShowWindow = SW_HIDE /*SW_SHOWDEFAULT*/; |
3611 } |
3616 } |
3612 lpsiStartInfo.cbReserved2 = 0; |
3617 lpsiStartInfo.cbReserved2 = 0; |
3613 lpsiStartInfo.lpReserved2 = NULL; |
3618 lpsiStartInfo.lpReserved2 = NULL; |
3614 lpsiStartInfo.hStdInput = NULL; |
3619 lpsiStartInfo.hStdInput = NULL; |
3615 lpsiStartInfo.hStdOutput = NULL; |
3620 lpsiStartInfo.hStdOutput = NULL; |
3616 lpsiStartInfo.hStdError = NULL; |
3621 lpsiStartInfo.hStdError = NULL; |
3617 |
3622 |
3618 /* |
3623 /* |
3619 * set create process flags |
3624 * set create process flags |
3620 * if the flags arg is nil, use common defaults; |
3625 * if the flags arg is nil, use common defaults; |
3621 * if non-nil, it must be a positive integer containing the fdwCreate bits. |
3626 * if non-nil, it must be a positive integer containing the fdwCreate bits. |
3622 */ |
3627 */ |
3623 if (flagsOrNil != nil) { |
3628 if (flagsOrNil != nil) { |
3624 fdwCreate = __longIntVal(flagsOrNil); |
3629 fdwCreate = __longIntVal(flagsOrNil); |
3625 } else { |
3630 } else { |
3626 if (0 /* __isWinNT */) |
3631 if (0 /* __isWinNT */) |
3627 fdwCreate = 0; //IDLE_PRIORITY_CLASS; |
3632 fdwCreate = 0; //IDLE_PRIORITY_CLASS; |
3628 else |
3633 else |
3629 fdwCreate = CREATE_NEW_CONSOLE; //|IDLE_PRIORITY_CLASS; // DETACHED_PROCESS; // NORMAL_PRIORITY_CLASS ; |
3634 fdwCreate = CREATE_NEW_CONSOLE; //|IDLE_PRIORITY_CLASS; // DETACHED_PROCESS; // NORMAL_PRIORITY_CLASS ; |
3630 |
3635 |
3631 if (newPgrp == true) { |
3636 if (newPgrp == true) { |
3632 fdwCreate |= CREATE_NEW_PROCESS_GROUP; |
3637 fdwCreate |= CREATE_NEW_PROCESS_GROUP; |
3633 } |
3638 } |
3634 fdwCreate |= CREATE_DEFAULT_ERROR_MODE; |
3639 fdwCreate |= CREATE_DEFAULT_ERROR_MODE; |
3635 } |
3640 } |
3636 |
3641 |
3637 if (fdArray == nil) { |
3642 if (fdArray == nil) { |
3638 lpsiStartInfo.hStdInput = (HANDLE) _get_osfhandle (0); |
3643 lpsiStartInfo.hStdInput = (HANDLE) _get_osfhandle (0); |
3639 lpsiStartInfo.hStdOutput = (HANDLE) _get_osfhandle (1); |
3644 lpsiStartInfo.hStdOutput = (HANDLE) _get_osfhandle (1); |
3640 lpsiStartInfo.hStdError = (HANDLE) _get_osfhandle (2); |
3645 lpsiStartInfo.hStdError = (HANDLE) _get_osfhandle (2); |
3641 } else if (__isArrayLike(fdArray) && (__arraySize(fdArray) >= 3)) { |
3646 } else if (__isArrayLike(fdArray) && (__arraySize(fdArray) >= 3)) { |
3642 if (__ArrayInstPtr(fdArray)->a_element[0] != nil) { |
3647 if (__ArrayInstPtr(fdArray)->a_element[0] != nil) { |
3643 if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[0])) { |
3648 if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[0])) { |
3644 lpsiStartInfo.hStdInput = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[0]); |
3649 lpsiStartInfo.hStdInput = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[0]); |
3645 } else { |
3650 } else { |
3646 lpsiStartInfo.hStdInput = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[0])); |
3651 lpsiStartInfo.hStdInput = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[0])); |
3647 } |
3652 } |
3648 } |
3653 } |
3649 if (__ArrayInstPtr(fdArray)->a_element[1] != nil) { |
3654 if (__ArrayInstPtr(fdArray)->a_element[1] != nil) { |
3650 if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[1])) { |
3655 if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[1])) { |
3651 lpsiStartInfo.hStdOutput = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[1]); |
3656 lpsiStartInfo.hStdOutput = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[1]); |
3652 } else { |
3657 } else { |
3653 lpsiStartInfo.hStdOutput = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[1])); |
3658 lpsiStartInfo.hStdOutput = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[1])); |
3654 } |
3659 } |
3655 } |
3660 } |
3656 if (__ArrayInstPtr(fdArray)->a_element[2] != nil) { |
3661 if (__ArrayInstPtr(fdArray)->a_element[2] != nil) { |
3657 if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[2])) { |
3662 if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[2])) { |
3658 lpsiStartInfo.hStdError = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[2]); |
3663 lpsiStartInfo.hStdError = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[2]); |
3659 } else { |
3664 } else { |
3660 lpsiStartInfo.hStdError = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[2])); |
3665 lpsiStartInfo.hStdError = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[2])); |
3661 } |
3666 } |
3662 } |
3667 } |
3663 #if defined(PROCESSDEBUGWIN32) |
3668 #if defined(PROCESSDEBUGWIN32) |
3664 console_fprintf(stderr, "stdin %x\n", lpsiStartInfo.hStdInput); |
3669 console_fprintf(stderr, "stdin %x\n", lpsiStartInfo.hStdInput); |
3665 console_fprintf(stderr, "stdout %x\n",lpsiStartInfo.hStdOutput); |
3670 console_fprintf(stderr, "stdout %x\n",lpsiStartInfo.hStdOutput); |
3666 console_fprintf(stderr, "stderr %x\n",lpsiStartInfo.hStdError); |
3671 console_fprintf(stderr, "stderr %x\n",lpsiStartInfo.hStdError); |
3667 #endif |
3672 #endif |
3668 } else { |
3673 } else { |
3669 console_fprintf(stderr, "Win32OS [warning]: bad fd arg in createProcess\n"); |
3674 console_fprintf(stderr, "Win32OS [warning]: bad fd arg in createProcess\n"); |
3670 } |
3675 } |
3671 |
3676 |
3672 if (doFork == true) { |
3677 if (doFork == true) { |
3673 #ifdef PROCESSDEBUGWIN32 |
3678 #ifdef PROCESSDEBUGWIN32 |
3674 console_fprintf(stderr, "create process cmdPath:<%s> cmdLine:<%s> in <%s>\n", cmdPath, cmdLine, dir); |
3679 console_fprintf(stderr, "create process cmdPath:<%s> cmdLine:<%s> in <%s>\n", cmdPath, cmdLine, dir); |
3675 #endif |
3680 #endif |
3676 if (CreateProcess( cmdPath, |
3681 if (CreateProcess( cmdPath, |
3677 cmdLine, |
3682 cmdLine, |
3678 &sa, NULL /* &sa */, /* sec-attribs */ |
3683 &sa, NULL /* &sa */, /* sec-attribs */ |
3679 sa.bInheritHandle, /* inherit handles */ |
3684 sa.bInheritHandle, /* inherit handles */ |
3680 fdwCreate, |
3685 fdwCreate, |
3681 NULL, /* env */ |
3686 NULL, /* env */ |
3682 dir, |
3687 dir, |
3683 &lpsiStartInfo, |
3688 &lpsiStartInfo, |
3684 &lppiProcInfo )) |
3689 &lppiProcInfo )) |
3685 { |
3690 { |
3686 CloseHandle(lppiProcInfo.hThread); |
3691 CloseHandle(lppiProcInfo.hThread); |
3687 #ifdef PROCESSDEBUGWIN32 |
3692 #ifdef PROCESSDEBUGWIN32 |
3688 console_fprintf(stderr, "created process hProcess=%x\n", lppiProcInfo.hProcess); |
3693 console_fprintf(stderr, "created process hProcess=%x\n", lppiProcInfo.hProcess); |
3689 #endif |
3694 #endif |
3690 __externalAddressVal(handle) = lppiProcInfo.hProcess; |
3695 __externalAddressVal(handle) = lppiProcInfo.hProcess; |
3691 ((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(handle))->pid = __mkSmallInteger(lppiProcInfo.dwProcessId); |
3696 ((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(handle))->pid = __mkSmallInteger(lppiProcInfo.dwProcessId); |
3692 RETURN (handle); |
3697 RETURN (handle); |
3693 } |
3698 } |
3694 #ifdef PROCESSDEBUGWIN32 |
3699 #ifdef PROCESSDEBUGWIN32 |
3695 console_fprintf(stderr, "created process error %d\n", GetLastError()); |
3700 console_fprintf(stderr, "created process error %d\n", GetLastError()); |
3696 #endif |
3701 #endif |
3697 RETURN (nil); |
3702 RETURN (nil); |
3698 } else { |
3703 } else { |
3699 ; /* should never be called that way */ |
3704 ; /* should never be called that way */ |
3700 } |
3705 } |
3701 } |
3706 } |
3702 %}. |
3707 %}. |
3703 " |
3708 " |
3704 path-argument not string |
3709 path-argument not string |
3705 or argArray not an array/nil |
3710 or argArray not an array/nil |
4135 %{ |
4140 %{ |
4136 int ret; |
4141 int ret; |
4137 |
4142 |
4138 if (__isStringLike(fullPathName)) { |
4143 if (__isStringLike(fullPathName)) { |
4139 #ifdef DO_WRAP_CALLS |
4144 #ifdef DO_WRAP_CALLS |
4140 { |
4145 { |
4141 char _aPathName[MAXPATHLEN]; |
4146 char _aPathName[MAXPATHLEN]; |
4142 |
4147 |
4143 strncpy(_aPathName, __stringVal(fullPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
4148 strncpy(_aPathName, __stringVal(fullPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
4144 do { |
4149 do { |
4145 __threadErrno = 0; |
4150 __threadErrno = 0; |
4146 ret = STX_API_NOINT_CALL1( "RemoveDirectoryA", RemoveDirectoryA, _aPathName); |
4151 ret = STX_API_NOINT_CALL1( "RemoveDirectoryA", RemoveDirectoryA, _aPathName); |
4147 } while ((ret < 0) && (__threadErrno == EINTR)); |
4152 } while ((ret < 0) && (__threadErrno == EINTR)); |
4148 } |
4153 } |
4149 #else |
4154 #else |
4150 ret = RemoveDirectoryA((char *)__stringVal(fullPathName)); |
4155 ret = RemoveDirectoryA((char *)__stringVal(fullPathName)); |
4151 __threadErrno = __WIN32_ERR(GetLastError()); |
4156 __threadErrno = __WIN32_ERR(GetLastError()); |
4152 #endif |
4157 #endif |
4153 if (ret != TRUE) { |
4158 if (ret != TRUE) { |
4154 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4159 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4155 RETURN (false); |
4160 RETURN (false); |
4156 } |
4161 } |
4157 RETURN (true); |
4162 RETURN (true); |
4158 } |
4163 } |
4159 if (__isUnicode16String(fullPathName)) { |
4164 if (__isUnicode16String(fullPathName)) { |
4160 #ifdef DO_WRAP_CALLS |
4165 #ifdef DO_WRAP_CALLS |
4161 { |
4166 { |
4162 wchar_t _wPathName[MAXPATHLEN+1]; |
4167 wchar_t _wPathName[MAXPATHLEN+1]; |
4163 int i, l; |
4168 int i, l; |
4164 |
4169 |
4165 l = __unicode16StringSize(fullPathName); |
4170 l = __unicode16StringSize(fullPathName); |
4166 if (l > MAXPATHLEN) l = MAXPATHLEN; |
4171 if (l > MAXPATHLEN) l = MAXPATHLEN; |
4167 for (i=0; i<l; i++) { |
4172 for (i=0; i<l; i++) { |
4168 _wPathName[i] = __unicode16StringVal(fullPathName)[i]; |
4173 _wPathName[i] = __unicode16StringVal(fullPathName)[i]; |
4169 } |
4174 } |
4170 _wPathName[i] = 0; |
4175 _wPathName[i] = 0; |
4171 do { |
4176 do { |
4172 __threadErrno = 0; |
4177 __threadErrno = 0; |
4173 ret = STX_API_NOINT_CALL1( "RemoveDirectoryW", RemoveDirectoryW, _wPathName); |
4178 ret = STX_API_NOINT_CALL1( "RemoveDirectoryW", RemoveDirectoryW, _wPathName); |
4174 } while ((ret < 0) && (__threadErrno == EINTR)); |
4179 } while ((ret < 0) && (__threadErrno == EINTR)); |
4175 } |
4180 } |
4176 #else |
4181 #else |
4177 ret = RemoveDirectoryW((char *)__stringVal(fullPathName)); |
4182 ret = RemoveDirectoryW((char *)__stringVal(fullPathName)); |
4178 __threadErrno = __WIN32_ERR(GetLastError()); |
4183 __threadErrno = __WIN32_ERR(GetLastError()); |
4179 #endif |
4184 #endif |
4180 if (ret != TRUE) { |
4185 if (ret != TRUE) { |
4181 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4186 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4182 RETURN (false); |
4187 RETURN (false); |
4183 } |
4188 } |
4184 RETURN (true); |
4189 RETURN (true); |
4185 } |
4190 } |
4186 %}. |
4191 %}. |
4187 "/ |
4192 "/ |
4188 "/ either not a string argument, |
4193 "/ either not a string argument, |
4189 "/ or not supported by OS |
4194 "/ or not supported by OS |
4203 %{ |
4208 %{ |
4204 int ret; |
4209 int ret; |
4205 |
4210 |
4206 if (__isStringLike(fullPathName)) { |
4211 if (__isStringLike(fullPathName)) { |
4207 #ifdef DO_WRAP_CALLS |
4212 #ifdef DO_WRAP_CALLS |
4208 { |
4213 { |
4209 char _aPathName[MAXPATHLEN]; |
4214 char _aPathName[MAXPATHLEN]; |
4210 |
4215 |
4211 strncpy(_aPathName, __stringVal(fullPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
4216 strncpy(_aPathName, __stringVal(fullPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
4212 do { |
4217 do { |
4213 __threadErrno = 0; |
4218 __threadErrno = 0; |
4214 ret = STX_API_NOINT_CALL1( "DeleteFileA", DeleteFileA, _aPathName); |
4219 ret = STX_API_NOINT_CALL1( "DeleteFileA", DeleteFileA, _aPathName); |
4215 } while ((ret < 0) && (__threadErrno == EINTR)); |
4220 } while ((ret < 0) && (__threadErrno == EINTR)); |
4216 } |
4221 } |
4217 #else |
4222 #else |
4218 ret = DeleteFileA((char *)__stringVal(fullPathName)); |
4223 ret = DeleteFileA((char *)__stringVal(fullPathName)); |
4219 __threadErrno = __WIN32_ERR(GetLastError()); |
4224 __threadErrno = __WIN32_ERR(GetLastError()); |
4220 #endif |
4225 #endif |
4221 if (ret != TRUE) { |
4226 if (ret != TRUE) { |
4222 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4227 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4223 RETURN (false); |
4228 RETURN (false); |
4224 } |
4229 } |
4225 RETURN (true); |
4230 RETURN (true); |
4226 } |
4231 } |
4227 if (__isUnicode16String(fullPathName)) { |
4232 if (__isUnicode16String(fullPathName)) { |
4228 #ifdef DO_WRAP_CALLS |
4233 #ifdef DO_WRAP_CALLS |
4229 { |
4234 { |
4230 wchar_t _wPathName[MAXPATHLEN+1]; |
4235 wchar_t _wPathName[MAXPATHLEN+1]; |
4231 int i, l; |
4236 int i, l; |
4232 |
4237 |
4233 l = __unicode16StringSize(fullPathName); |
4238 l = __unicode16StringSize(fullPathName); |
4234 if (l > MAXPATHLEN) l = MAXPATHLEN; |
4239 if (l > MAXPATHLEN) l = MAXPATHLEN; |
4235 for (i=0; i<l; i++) { |
4240 for (i=0; i<l; i++) { |
4236 _wPathName[i] = __unicode16StringVal(fullPathName)[i]; |
4241 _wPathName[i] = __unicode16StringVal(fullPathName)[i]; |
4237 } |
4242 } |
4238 _wPathName[i] = 0; |
4243 _wPathName[i] = 0; |
4239 do { |
4244 do { |
4240 __threadErrno = 0; |
4245 __threadErrno = 0; |
4241 ret = STX_API_NOINT_CALL1( "DeleteFileW", DeleteFileW, _wPathName); |
4246 ret = STX_API_NOINT_CALL1( "DeleteFileW", DeleteFileW, _wPathName); |
4242 } while ((ret < 0) && (__threadErrno == EINTR)); |
4247 } while ((ret < 0) && (__threadErrno == EINTR)); |
4243 } |
4248 } |
4244 #else |
4249 #else |
4245 ret = DeleteFileW((char *)__stringVal(fullPathName)); |
4250 ret = DeleteFileW((char *)__stringVal(fullPathName)); |
4246 __threadErrno = __WIN32_ERR(GetLastError()); |
4251 __threadErrno = __WIN32_ERR(GetLastError()); |
4247 #endif |
4252 #endif |
4248 if (ret != TRUE) { |
4253 if (ret != TRUE) { |
4249 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4254 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4250 RETURN (false); |
4255 RETURN (false); |
4251 } |
4256 } |
4252 RETURN (true); |
4257 RETURN (true); |
4253 } |
4258 } |
4254 |
4259 |
4255 %}. |
4260 %}. |
4256 ^ self primitiveFailed |
4261 ^ self primitiveFailed |
4257 ! |
4262 ! |
4406 Notice that the returned number is OS dependent - use the |
4411 Notice that the returned number is OS dependent - use the |
4407 modeMasks as returned by OperatingSystem>>accessMaskFor:" |
4412 modeMasks as returned by OperatingSystem>>accessMaskFor:" |
4408 |
4413 |
4409 " |
4414 " |
4410 this could have been implemented as: |
4415 this could have been implemented as: |
4411 (self infoOf:aPathName) at:#mode |
4416 (self infoOf:aPathName) at:#mode |
4412 but for huge directory searches the code below is faster |
4417 but for huge directory searches the code below is faster |
4413 " |
4418 " |
4414 |
4419 |
4415 %{ |
4420 %{ |
4416 struct stat buf; |
4421 struct stat buf; |
4417 int ret; |
4422 int ret; |
4418 |
4423 |
4419 if (__isStringLike(aPathName)) { |
4424 if (__isStringLike(aPathName)) { |
4420 #ifdef DO_WRAP_CALLS |
4425 #ifdef DO_WRAP_CALLS |
4421 char _aPathName[MAXPATHLEN]; |
4426 char _aPathName[MAXPATHLEN]; |
4422 |
4427 |
4423 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
4428 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
4424 |
4429 |
4425 do { |
4430 do { |
4426 __threadErrno = 0; |
4431 __threadErrno = 0; |
4427 ret = STX_C_NOINT_CALL2( "stat", stat, _aPathName, &buf); |
4432 ret = STX_C_NOINT_CALL2( "stat", stat, _aPathName, &buf); |
4428 } while ((ret < 0) && (__threadErrno == EINTR)); |
4433 } while ((ret < 0) && (__threadErrno == EINTR)); |
4429 #else |
4434 #else |
4430 __BEGIN_INTERRUPTABLE__ |
4435 __BEGIN_INTERRUPTABLE__ |
4431 do { |
4436 do { |
4432 __threadErrno = 0; |
4437 __threadErrno = 0; |
4433 ret = stat( (char *)__stringVal(aPathName), &buf); |
4438 ret = stat( (char *)__stringVal(aPathName), &buf); |
4434 } while ((ret < 0) && (__threadErrno == EINTR)); |
4439 } while ((ret < 0) && (__threadErrno == EINTR)); |
4435 __END_INTERRUPTABLE__ |
4440 __END_INTERRUPTABLE__ |
4436 if (ret < 0) { |
4441 if (ret < 0) { |
4437 __threadErrno = __WIN32_ERR(GetLastError()); |
4442 __threadErrno = __WIN32_ERR(GetLastError()); |
4438 } |
4443 } |
4439 #endif |
4444 #endif |
4440 |
4445 |
4441 if (ret < 0) { |
4446 if (ret < 0) { |
4442 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4447 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
4443 RETURN ( nil ); |
4448 RETURN ( nil ); |
4444 } |
4449 } |
4445 RETURN ( __mkSmallInteger(buf.st_mode & 0777) ); |
4450 RETURN ( __mkSmallInteger(buf.st_mode & 0777) ); |
4446 } |
4451 } |
4447 %}. |
4452 %}. |
4448 ^ self primitiveFailed |
4453 ^ self primitiveFailed |
4449 |
4454 |
4450 " |
4455 " |
4865 %{ |
4870 %{ |
4866 int ret; |
4871 int ret; |
4867 wchar_t _aPathName[MAX_PATH+1]; |
4872 wchar_t _aPathName[MAX_PATH+1]; |
4868 |
4873 |
4869 if (__isStringLike(aPathName)) { |
4874 if (__isStringLike(aPathName)) { |
4870 int i; |
4875 int i; |
4871 int l = __stringSize(aPathName); |
4876 int l = __stringSize(aPathName); |
4872 if (l > MAX_PATH) l = MAX_PATH; |
4877 if (l > MAX_PATH) l = MAX_PATH; |
4873 |
4878 |
4874 for (i=0; i<l; i++) { |
4879 for (i=0; i<l; i++) { |
4875 _aPathName[i] = __stringVal(aPathName)[i]; |
4880 _aPathName[i] = __stringVal(aPathName)[i]; |
4876 } |
4881 } |
4877 _aPathName[i] = 0; |
4882 _aPathName[i] = 0; |
4878 } else if (__isUnicode16String(aPathName)) { |
4883 } else if (__isUnicode16String(aPathName)) { |
4879 int i; |
4884 int i; |
4880 int l = __unicode16StringSize(aPathName); |
4885 int l = __unicode16StringSize(aPathName); |
4881 if (l > MAX_PATH) l = MAX_PATH; |
4886 if (l > MAX_PATH) l = MAX_PATH; |
4882 |
4887 |
4883 for (i=0; i<l; i++) { |
4888 for (i=0; i<l; i++) { |
4884 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
4889 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
4885 } |
4890 } |
4886 _aPathName[i] = 0; |
4891 _aPathName[i] = 0; |
4887 } else |
4892 } else |
4888 goto badArgument; |
4893 goto badArgument; |
4889 |
4894 |
4890 #ifdef DO_WRAP_CALLS |
4895 #ifdef DO_WRAP_CALLS |
4891 do { |
4896 do { |
4892 __threadErrno = 0; |
4897 __threadErrno = 0; |
4893 ret = STX_API_NOINT_CALL3( "GetLongPathNameW", GetLongPathNameW, _aPathName, _aPathName, MAX_PATH+1); |
4898 ret = STX_API_NOINT_CALL3( "GetLongPathNameW", GetLongPathNameW, _aPathName, _aPathName, MAX_PATH+1); |
4894 } while ((ret == 0) && (__threadErrno == EINTR)); |
4899 } while ((ret == 0) && (__threadErrno == EINTR)); |
4895 #else |
4900 #else |
4896 ret = GetLongPathNameW(_aPathName, _aPathName, MAX_PATH+1); |
4901 ret = GetLongPathNameW(_aPathName, _aPathName, MAX_PATH+1); |
4897 if (ret == 0) { |
4902 if (ret == 0) { |
4898 __threadErrno = __WIN32_ERR(GetLastError()); |
4903 __threadErrno = __WIN32_ERR(GetLastError()); |
4899 } |
4904 } |
4900 #endif |
4905 #endif |
4901 RETURN ( __MKU16STRING(_aPathName)); |
4906 RETURN ( __MKU16STRING(_aPathName)); |
4902 |
4907 |
4903 badArgument:; |
4908 badArgument:; |
4904 %}. |
4909 %}. |
4905 ^ self primitiveFailed |
4910 ^ self primitiveFailed |
4906 |
4911 |
4907 " |
4912 " |
4908 self getLongPathName:'x:\' |
4913 self getLongPathName:'x:\' |
4909 self getLongPathName:'c:\Dokumente und Einstellungen' |
4914 self getLongPathName:'c:\Dokumente und Einstellungen' |
4910 self getShortPathName:'c:\Dokumente und Einstellungen' |
4915 self getShortPathName:'c:\Dokumente und Einstellungen' |
4911 " |
4916 " |
4912 ! |
4917 ! |
4913 |
4918 |
4914 getNullDevice |
4919 getNullDevice |
4915 "get the name of the null-device." |
4920 "get the name of the null-device." |
4923 %{ |
4928 %{ |
4924 int ret; |
4929 int ret; |
4925 wchar_t _aPathName[MAX_PATH+1]; |
4930 wchar_t _aPathName[MAX_PATH+1]; |
4926 |
4931 |
4927 if (__isStringLike(aPathName)) { |
4932 if (__isStringLike(aPathName)) { |
4928 int i; |
4933 int i; |
4929 int l = __stringSize(aPathName); |
4934 int l = __stringSize(aPathName); |
4930 if (l > MAX_PATH) l = MAX_PATH; |
4935 if (l > MAX_PATH) l = MAX_PATH; |
4931 |
4936 |
4932 for (i=0; i<l; i++) { |
4937 for (i=0; i<l; i++) { |
4933 _aPathName[i] = __stringVal(aPathName)[i]; |
4938 _aPathName[i] = __stringVal(aPathName)[i]; |
4934 } |
4939 } |
4935 _aPathName[i] = 0; |
4940 _aPathName[i] = 0; |
4936 } else if (__isUnicode16String(aPathName)) { |
4941 } else if (__isUnicode16String(aPathName)) { |
4937 int i; |
4942 int i; |
4938 int l = __unicode16StringSize(aPathName); |
4943 int l = __unicode16StringSize(aPathName); |
4939 if (l > MAX_PATH) l = MAX_PATH; |
4944 if (l > MAX_PATH) l = MAX_PATH; |
4940 |
4945 |
4941 for (i=0; i<l; i++) { |
4946 for (i=0; i<l; i++) { |
4942 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
4947 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
4943 } |
4948 } |
4944 _aPathName[i] = 0; |
4949 _aPathName[i] = 0; |
4945 } else |
4950 } else |
4946 goto badArgument; |
4951 goto badArgument; |
4947 |
4952 |
4948 #ifdef DO_WRAP_CALLS |
4953 #ifdef DO_WRAP_CALLS |
4949 do { |
4954 do { |
4950 __threadErrno = 0; |
4955 __threadErrno = 0; |
4951 ret = STX_API_NOINT_CALL3( "GetShortPathNameW", GetShortPathNameW, _aPathName, _aPathName, MAX_PATH+1); |
4956 ret = STX_API_NOINT_CALL3( "GetShortPathNameW", GetShortPathNameW, _aPathName, _aPathName, MAX_PATH+1); |
4952 } while ((ret == 0) && (__threadErrno == EINTR)); |
4957 } while ((ret == 0) && (__threadErrno == EINTR)); |
4953 #else |
4958 #else |
4954 ret = GetShortPathNameW(_aPathName, _aPathName, MAX_PATH+1); |
4959 ret = GetShortPathNameW(_aPathName, _aPathName, MAX_PATH+1); |
4955 if (ret == 0) { |
4960 if (ret == 0) { |
4956 __threadErrno = __WIN32_ERR(GetLastError()); |
4961 __threadErrno = __WIN32_ERR(GetLastError()); |
4957 } |
4962 } |
4958 #endif |
4963 #endif |
4959 RETURN ( __MKU16STRING(_aPathName)); |
4964 RETURN ( __MKU16STRING(_aPathName)); |
4960 |
4965 |
4961 badArgument:; |
4966 badArgument:; |
4962 %}. |
4967 %}. |
4963 ^ self primitiveFailed |
4968 ^ self primitiveFailed |
4964 |
4969 |
4965 " |
4970 " |
4966 self getShortPathName:'x:\' |
4971 self getShortPathName:'x:\' |
4967 self getShortPathName:'c:\Dokumente und Einstellungen' |
4972 self getShortPathName:'c:\Dokumente und Einstellungen' |
4968 self getLongPathName:'c:\Dokumente und Einstellungen' |
4973 self getLongPathName:'c:\Dokumente und Einstellungen' |
4969 " |
4974 " |
4970 ! |
4975 ! |
4971 |
4976 |
4972 getVolumeInformation: rootPath |
4977 getVolumeInformation: rootPath |
4973 name: volumeNameBuffer |
4978 name: volumeNameBuffer |
5035 %{ |
5040 %{ |
5036 int ret; |
5041 int ret; |
5037 |
5042 |
5038 if (__isStringLike(aPathName)) { |
5043 if (__isStringLike(aPathName)) { |
5039 #ifdef DO_WRAP_CALLS |
5044 #ifdef DO_WRAP_CALLS |
5040 char _aPathName[MAXPATHLEN]; |
5045 char _aPathName[MAXPATHLEN]; |
5041 |
5046 |
5042 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5047 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5043 do { |
5048 do { |
5044 __threadErrno = 0; |
5049 __threadErrno = 0; |
5045 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5050 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5046 } while ((ret == -1) && (__threadErrno == EINTR)); |
5051 } while ((ret == -1) && (__threadErrno == EINTR)); |
5047 #else |
5052 #else |
5048 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5053 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5049 if (ret == -1) { |
5054 if (ret == -1) { |
5050 __threadErrno = __WIN32_ERR(GetLastError()); |
5055 __threadErrno = __WIN32_ERR(GetLastError()); |
5051 } |
5056 } |
5052 #endif |
5057 #endif |
5053 } else if (__isUnicode16String(aPathName)) { |
5058 } else if (__isUnicode16String(aPathName)) { |
5054 wchar_t _wPathName[MAXPATHLEN+1]; |
5059 wchar_t _wPathName[MAXPATHLEN+1]; |
5055 int i, l; |
5060 int i, l; |
5056 |
5061 |
5057 l = __unicode16StringSize(aPathName); |
5062 l = __unicode16StringSize(aPathName); |
5058 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5063 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5059 for (i=0; i<l; i++) { |
5064 for (i=0; i<l; i++) { |
5060 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5065 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5061 } |
5066 } |
5062 _wPathName[i] = 0; |
5067 _wPathName[i] = 0; |
5063 #ifdef DO_WRAP_CALLS |
5068 #ifdef DO_WRAP_CALLS |
5064 do { |
5069 do { |
5065 __threadErrno = 0; |
5070 __threadErrno = 0; |
5066 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5071 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5067 } while ((ret == -1) && (__threadErrno == EINTR)); |
5072 } while ((ret == -1) && (__threadErrno == EINTR)); |
5068 #else |
5073 #else |
5069 ret = GetFileAttributesW(_wPathName); |
5074 ret = GetFileAttributesW(_wPathName); |
5070 if (ret == -1) { |
5075 if (ret == -1) { |
5071 __threadErrno = __WIN32_ERR(GetLastError()); |
5076 __threadErrno = __WIN32_ERR(GetLastError()); |
5072 } |
5077 } |
5073 #endif |
5078 #endif |
5074 } else |
5079 } else |
5075 goto err; |
5080 goto err; |
5076 |
5081 |
5077 if (ret < 0) { |
5082 if (ret < 0) { |
5078 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5083 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5079 RETURN ( false ); |
5084 RETURN ( false ); |
5080 } |
5085 } |
5081 RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false); |
5086 RETURN ( (ret & FILE_ATTRIBUTE_DIRECTORY) ? true : false); |
5082 err:; |
5087 err:; |
5083 %}. |
5088 %}. |
5084 ^ self primitiveFailed |
5089 ^ self primitiveFailed |
5085 |
5090 |
5086 "an alternative implementation would be: |
5091 "an alternative implementation would be: |
5087 ^ (self infoOf:aPathName) type == #directory |
5092 ^ (self infoOf:aPathName) type == #directory |
5088 " |
5093 " |
5089 " |
5094 " |
5090 self isDirectory:'.' |
5095 self isDirectory:'.' |
5091 self isDirectory:'.' asUnicode16String |
5096 self isDirectory:'.' asUnicode16String |
5092 " |
5097 " |
5126 "return true, if the file/dir 'aPathName' is readable. |
5131 "return true, if the file/dir 'aPathName' is readable. |
5127 For symbolic links, the pointed-to-file is checked." |
5132 For symbolic links, the pointed-to-file is checked." |
5128 |
5133 |
5129 %{ |
5134 %{ |
5130 if (__isStringLike(aPathName)) { |
5135 if (__isStringLike(aPathName)) { |
5131 int ret; |
5136 int ret; |
5132 |
5137 |
5133 /* |
5138 /* |
5134 * under windows, all files are readable ... |
5139 * under windows, all files are readable ... |
5135 * so, only check for the files existence here. |
5140 * so, only check for the files existence here. |
5136 */ |
5141 */ |
5137 #ifdef DO_WRAP_CALLS |
5142 #ifdef DO_WRAP_CALLS |
5138 char _aPathName[MAXPATHLEN]; |
5143 char _aPathName[MAXPATHLEN]; |
5139 |
5144 |
5140 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5145 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5141 do { |
5146 do { |
5142 __threadErrno = 0; |
5147 __threadErrno = 0; |
5143 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5148 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5144 } while ((ret < 0) && (__threadErrno == EINTR)); |
5149 } while ((ret < 0) && (__threadErrno == EINTR)); |
5145 #else |
5150 #else |
5146 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5151 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5147 if (ret < 0) { |
5152 if (ret < 0) { |
5148 __threadErrno = __WIN32_ERR(GetLastError()); |
5153 __threadErrno = __WIN32_ERR(GetLastError()); |
5149 } |
5154 } |
5150 #endif |
5155 #endif |
5151 if (ret < 0) { |
5156 if (ret < 0) { |
5152 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5157 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5153 RETURN (false); |
5158 RETURN (false); |
5154 } |
5159 } |
5155 RETURN (true); |
5160 RETURN (true); |
5156 } |
5161 } |
5157 |
5162 |
5158 if (__isUnicode16String(aPathName)) { |
5163 if (__isUnicode16String(aPathName)) { |
5159 int ret; |
5164 int ret; |
5160 |
5165 |
5161 /* |
5166 /* |
5162 * under windows, all files are readable ... |
5167 * under windows, all files are readable ... |
5163 * so, only check for the files existence here. |
5168 * so, only check for the files existence here. |
5164 */ |
5169 */ |
5165 wchar_t _wPathName[MAXPATHLEN+1]; |
5170 wchar_t _wPathName[MAXPATHLEN+1]; |
5166 int i, l; |
5171 int i, l; |
5167 |
5172 |
5168 l = __unicode16StringSize(aPathName); |
5173 l = __unicode16StringSize(aPathName); |
5169 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5174 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5170 for (i=0; i<l; i++) { |
5175 for (i=0; i<l; i++) { |
5171 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5176 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5172 } |
5177 } |
5173 _wPathName[i] = 0; |
5178 _wPathName[i] = 0; |
5174 #ifdef DO_WRAP_CALLS |
5179 #ifdef DO_WRAP_CALLS |
5175 do { |
5180 do { |
5176 __threadErrno = 0; |
5181 __threadErrno = 0; |
5177 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5182 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5178 } while ((ret < 0) && (__threadErrno == EINTR)); |
5183 } while ((ret < 0) && (__threadErrno == EINTR)); |
5179 #else |
5184 #else |
5180 ret = GetFileAttributesW(_wPathName); |
5185 ret = GetFileAttributesW(_wPathName); |
5181 if (ret < 0) { |
5186 if (ret < 0) { |
5182 __threadErrno = __WIN32_ERR(GetLastError()); |
5187 __threadErrno = __WIN32_ERR(GetLastError()); |
5183 } |
5188 } |
5184 #endif |
5189 #endif |
5185 if (ret < 0) { |
5190 if (ret < 0) { |
5186 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5191 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5187 RETURN (false); |
5192 RETURN (false); |
5188 } |
5193 } |
5189 RETURN (true); |
5194 RETURN (true); |
5190 } |
5195 } |
5191 %}. |
5196 %}. |
5192 ^ self primitiveFailed |
5197 ^ self primitiveFailed |
5193 |
5198 |
5194 " |
5199 " |
5219 %{ |
5224 %{ |
5220 int ret; |
5225 int ret; |
5221 |
5226 |
5222 if (__isStringLike(aPathName)) { |
5227 if (__isStringLike(aPathName)) { |
5223 #ifdef DO_WRAP_CALLS |
5228 #ifdef DO_WRAP_CALLS |
5224 char _aPathName[MAXPATHLEN]; |
5229 char _aPathName[MAXPATHLEN]; |
5225 |
5230 |
5226 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5231 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5227 do { |
5232 do { |
5228 __threadErrno = 0; |
5233 __threadErrno = 0; |
5229 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5234 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5230 } while ((ret == -1) && (__threadErrno == EINTR)); |
5235 } while ((ret == -1) && (__threadErrno == EINTR)); |
5231 #else |
5236 #else |
5232 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5237 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5233 if (ret == -1) { |
5238 if (ret == -1) { |
5234 __threadErrno = __WIN32_ERR(GetLastError()); |
5239 __threadErrno = __WIN32_ERR(GetLastError()); |
5235 } |
5240 } |
5236 #endif |
5241 #endif |
5237 } else if (__isUnicode16String(aPathName)) { |
5242 } else if (__isUnicode16String(aPathName)) { |
5238 wchar_t _wPathName[MAXPATHLEN+1]; |
5243 wchar_t _wPathName[MAXPATHLEN+1]; |
5239 int i, l; |
5244 int i, l; |
5240 |
5245 |
5241 l = __unicode16StringSize(aPathName); |
5246 l = __unicode16StringSize(aPathName); |
5242 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5247 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5243 for (i=0; i<l; i++) { |
5248 for (i=0; i<l; i++) { |
5244 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5249 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5245 } |
5250 } |
5246 _wPathName[i] = 0; |
5251 _wPathName[i] = 0; |
5247 #ifdef DO_WRAP_CALLS |
5252 #ifdef DO_WRAP_CALLS |
5248 do { |
5253 do { |
5249 __threadErrno = 0; |
5254 __threadErrno = 0; |
5250 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5255 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5251 } while ((ret == -1) && (__threadErrno == EINTR)); |
5256 } while ((ret == -1) && (__threadErrno == EINTR)); |
5252 #else |
5257 #else |
5253 ret = GetFileAttributesW(_wPathName); |
5258 ret = GetFileAttributesW(_wPathName); |
5254 if (ret == -1) { |
5259 if (ret == -1) { |
5255 __threadErrno = __WIN32_ERR(GetLastError()); |
5260 __threadErrno = __WIN32_ERR(GetLastError()); |
5256 } |
5261 } |
5257 #endif |
5262 #endif |
5258 } else |
5263 } else |
5259 goto err; |
5264 goto err; |
5260 |
5265 |
5261 if (ret == -1) { |
5266 if (ret == -1) { |
5262 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5267 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5263 RETURN ( false ); |
5268 RETURN ( false ); |
5264 } |
5269 } |
5265 RETURN (true); |
5270 RETURN (true); |
5266 |
5271 |
5267 err:; |
5272 err:; |
5268 %}. |
5273 %}. |
5332 WIN32_FILE_ATTRIBUTE_DATA fileAttributeData; |
5337 WIN32_FILE_ATTRIBUTE_DATA fileAttributeData; |
5333 unsigned INT ino; |
5338 unsigned INT ino; |
5334 wchar_t _aPathName[MAX_PATH+1]; |
5339 wchar_t _aPathName[MAX_PATH+1]; |
5335 |
5340 |
5336 if (__isStringLike(aPathName)) { |
5341 if (__isStringLike(aPathName)) { |
5337 int i; |
5342 int i; |
5338 int l = __stringSize(aPathName); |
5343 int l = __stringSize(aPathName); |
5339 if (l > MAX_PATH) l = MAX_PATH; |
5344 if (l > MAX_PATH) l = MAX_PATH; |
5340 |
5345 |
5341 for (i=0; i<l; i++) { |
5346 for (i=0; i<l; i++) { |
5342 _aPathName[i] = __stringVal(aPathName)[i]; |
5347 _aPathName[i] = __stringVal(aPathName)[i]; |
5343 } |
5348 } |
5344 _aPathName[i] = 0; |
5349 _aPathName[i] = 0; |
5345 } else if (__isUnicode16String(aPathName)) { |
5350 } else if (__isUnicode16String(aPathName)) { |
5346 int i; |
5351 int i; |
5347 int l = __unicode16StringSize(aPathName); |
5352 int l = __unicode16StringSize(aPathName); |
5348 if (l > MAX_PATH) l = MAX_PATH; |
5353 if (l > MAX_PATH) l = MAX_PATH; |
5349 |
5354 |
5350 for (i=0; i<l; i++) { |
5355 for (i=0; i<l; i++) { |
5351 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
5356 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
5352 } |
5357 } |
5353 _aPathName[i] = 0; |
5358 _aPathName[i] = 0; |
5354 } else |
5359 } else |
5355 goto badArgument; |
5360 goto badArgument; |
5356 |
5361 |
5357 #ifdef DO_WRAP_CALLS |
5362 #ifdef DO_WRAP_CALLS |
5358 { |
5363 { |
5359 do { |
5364 do { |
5360 __threadErrno = 0; |
5365 __threadErrno = 0; |
5361 result = STX_API_NOINT_CALL3( "GetFileAttributesExW", GetFileAttributesExW, _aPathName, GetFileExInfoStandard, &fileAttributeData); |
5366 result = STX_API_NOINT_CALL3( "GetFileAttributesExW", GetFileAttributesExW, _aPathName, GetFileExInfoStandard, &fileAttributeData); |
5362 } while (!result && (__threadErrno == EINTR)); |
5367 } while (!result && (__threadErrno == EINTR)); |
5363 } |
5368 } |
5364 #else |
5369 #else |
5365 result = GetFileAttributesExW(_aPathName, GetFileExInfoStandard, &fileAttributeData); |
5370 result = GetFileAttributesExW(_aPathName, GetFileExInfoStandard, &fileAttributeData); |
5366 if (!result) { |
5371 if (!result) { |
5367 __threadErrno = __WIN32_ERR(GetLastError()); |
5372 __threadErrno = __WIN32_ERR(GetLastError()); |
5368 } |
5373 } |
5369 #endif |
5374 #endif |
5370 |
5375 |
5371 if (!result) { |
5376 if (!result) { |
5372 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5377 @global(LastErrorNumber) = __mkSmallInteger(__threadErrno); |
5373 } else { |
5378 } else { |
5374 id = __mkSmallInteger(0); /* could get it by opening ... */ |
5379 id = __mkSmallInteger(0); /* could get it by opening ... */ |
5375 size = __MKLARGEINT64(1, fileAttributeData.nFileSizeLow, fileAttributeData.nFileSizeHigh); |
5380 size = __MKLARGEINT64(1, fileAttributeData.nFileSizeLow, fileAttributeData.nFileSizeHigh); |
5376 |
5381 |
5377 // if (fileAttributeData.cFileName[0] != '\0') { |
5382 // if (fileAttributeData.cFileName[0] != '\0') { |
5378 // bcopy(fileAttributeData.cFileName, fileNameBuffer, MAX_PATH*sizeof(wchar_t)); |
5383 // bcopy(fileAttributeData.cFileName, fileNameBuffer, MAX_PATH*sizeof(wchar_t)); |
5379 // fileNameBuffer[MAX_PATH] = '\0'; |
5384 // fileNameBuffer[MAX_PATH] = '\0'; |
5380 // fileName = __MKU16STRING(fileNameBuffer); /* FULL name */ |
5385 // fileName = __MKU16STRING(fileNameBuffer); /* FULL name */ |
5384 // bcopy(fileAttributeData.cAlternateFileName, alternativeFileNameBuffer, 14*sizeof(wchar_t)); |
5389 // bcopy(fileAttributeData.cAlternateFileName, alternativeFileNameBuffer, 14*sizeof(wchar_t)); |
5385 // alternativeFileNameBuffer[14] = '\0'; |
5390 // alternativeFileNameBuffer[14] = '\0'; |
5386 // alternativeName = __MKU16STRING(alternativeFileNameBuffer); /* DOS name */ |
5391 // alternativeName = __MKU16STRING(alternativeFileNameBuffer); /* DOS name */ |
5387 // } |
5392 // } |
5388 |
5393 |
5389 /* |
5394 /* |
5390 * simulate access bits |
5395 * simulate access bits |
5391 */ |
5396 */ |
5392 if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { |
5397 if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { |
5393 modeBits = 0444; |
5398 modeBits = 0444; |
5394 } else { |
5399 } else { |
5395 modeBits = 0666; |
5400 modeBits = 0666; |
5396 } |
5401 } |
5397 |
5402 |
5398 if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
5403 if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
5399 type = @symbol(directory); |
5404 type = @symbol(directory); |
5400 modeBits = 0777; /* executable and WRITABLE - refer to comment in #isWritable: */ |
5405 modeBits = 0777; /* executable and WRITABLE - refer to comment in #isWritable: */ |
5401 } else if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { |
5406 } else if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { |
5402 type = @symbol(symbolicLink); |
5407 type = @symbol(symbolicLink); |
5403 modeBits = 0777; /* even in UNIX symlinks have 0777 */ |
5408 modeBits = 0777; /* even in UNIX symlinks have 0777 */ |
5404 } else { |
5409 } else { |
5405 type = @symbol(regular); |
5410 type = @symbol(regular); |
5406 } |
5411 } |
5407 |
5412 |
5408 mode = __mkSmallInteger(modeBits); |
5413 mode = __mkSmallInteger(modeBits); |
5409 |
5414 |
5410 cOsTime = FileTimeToOsTime(&fileAttributeData.ftCreationTime); |
5415 cOsTime = FileTimeToOsTime(&fileAttributeData.ftCreationTime); |
5411 aOsTime = FileTimeToOsTime(&fileAttributeData.ftLastAccessTime); |
5416 aOsTime = FileTimeToOsTime(&fileAttributeData.ftLastAccessTime); |
5412 mOsTime = FileTimeToOsTime(&fileAttributeData.ftLastWriteTime); |
5417 mOsTime = FileTimeToOsTime(&fileAttributeData.ftLastWriteTime); |
5413 } |
5418 } |
5414 |
5419 |
5415 badArgument: ; |
5420 badArgument: ; |
5416 %}. |
5421 %}. |
5417 |
5422 |
5418 (aPathName endsWith:'.lnk') ifTrue:[ |
5423 (aPathName endsWith:'.lnk') ifTrue:[ |
5419 type := #symbolicLink. |
5424 type := #symbolicLink. |
5420 "/ now done lazyly in FileStatusInfo, when the path is accessed |
5425 "/ now done lazyly in FileStatusInfo, when the path is accessed |
5421 "/ path := self getLinkTarget:aPathName. |
5426 "/ path := self getLinkTarget:aPathName. |
5422 ]. |
5427 ]. |
5423 |
5428 |
5424 mode isNil ifTrue:[ |
5429 mode isNil ifTrue:[ |
5425 (self isDirectory:aPathName) ifTrue:[ |
5430 (self isDirectory:aPathName) ifTrue:[ |
5426 "/ the code above fails for root directories (these do not exist). |
5431 "/ the code above fails for root directories (these do not exist). |
5427 "/ simulate here |
5432 "/ simulate here |
5428 mode := 8r777. |
5433 mode := 8r777. |
5429 type := #directory. |
5434 type := #directory. |
5430 uid := gid := 0. |
5435 uid := gid := 0. |
5431 size := 0. |
5436 size := 0. |
5432 id := 0. |
5437 id := 0. |
5433 atime := mtime := ctime := Timestamp now. |
5438 atime := mtime := ctime := Timestamp now. |
5434 ]. |
5439 ]. |
5435 ]. |
5440 ]. |
5436 mode notNil ifTrue:[ |
5441 mode notNil ifTrue:[ |
5437 atime isNil ifTrue:[ |
5442 atime isNil ifTrue:[ |
5438 atime := Timestamp new fromOSTime:aOsTime. |
5443 atime := Timestamp new fromOSTime:aOsTime. |
5439 ]. |
5444 ]. |
5440 mtime isNil ifTrue:[ |
5445 mtime isNil ifTrue:[ |
5441 mtime := Timestamp new fromOSTime:mOsTime. |
5446 mtime := Timestamp new fromOSTime:mOsTime. |
5442 ]. |
5447 ]. |
5443 ctime isNil ifTrue:[ |
5448 ctime isNil ifTrue:[ |
5444 ctime := Timestamp new fromOSTime:cOsTime. |
5449 ctime := Timestamp new fromOSTime:cOsTime. |
5445 ]. |
5450 ]. |
5446 fileName notNil ifTrue:[ |
5451 fileName notNil ifTrue:[ |
5447 fileName := fileName asSingleByteStringIfPossible |
5452 fileName := fileName asSingleByteStringIfPossible |
5448 ]. |
5453 ]. |
5449 alternativeName notNil ifTrue:[ |
5454 alternativeName notNil ifTrue:[ |
5450 alternativeName := alternativeName asSingleByteStringIfPossible |
5455 alternativeName := alternativeName asSingleByteStringIfPossible |
5451 ]. |
5456 ]. |
5452 info := FileStatusInfo |
5457 info := FileStatusInfo |
5453 type:type |
5458 type:type |
5454 mode:mode |
5459 mode:mode |
5455 uid:uid |
5460 uid:uid |
5456 gid:gid |
5461 gid:gid |
5457 size:size |
5462 size:size |
5458 id:id |
5463 id:id |
5459 accessed:atime |
5464 accessed:atime |
5460 modified:mtime |
5465 modified:mtime |
5461 created:ctime |
5466 created:ctime |
5462 sourcePath:aPathName |
5467 sourcePath:aPathName |
5463 fullName:fileName |
5468 fullName:fileName |
5464 alternativeName:alternativeName. |
5469 alternativeName:alternativeName. |
5465 ^ info |
5470 ^ info |
5466 ]. |
5471 ]. |
5467 ^ nil |
5472 ^ nil |
5468 |
5473 |
5469 " |
5474 " |
5470 OperatingSystem linkInfoOf:'c:\windows' |
5475 OperatingSystem linkInfoOf:'c:\windows' |
5581 %{ |
5586 %{ |
5582 int ret; |
5587 int ret; |
5583 |
5588 |
5584 if (__isStringLike(aPathName)) { |
5589 if (__isStringLike(aPathName)) { |
5585 #ifdef DO_WRAP_CALLS |
5590 #ifdef DO_WRAP_CALLS |
5586 char _aPathName[MAXPATHLEN]; |
5591 char _aPathName[MAXPATHLEN]; |
5587 |
5592 |
5588 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5593 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5589 do { |
5594 do { |
5590 __threadErrno = 0; |
5595 __threadErrno = 0; |
5591 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5596 ret = STX_API_NOINT_CALL1( "GetFileAttributesA", GetFileAttributesA, _aPathName); |
5592 } while ((ret < 0) && (__threadErrno == EINTR)); |
5597 } while ((ret < 0) && (__threadErrno == EINTR)); |
5593 #else |
5598 #else |
5594 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5599 ret = GetFileAttributesA((char *) __stringVal(aPathName)); |
5595 if (ret < 0) { |
5600 if (ret < 0) { |
5596 __threadErrno = __WIN32_ERR(GetLastError()); |
5601 __threadErrno = __WIN32_ERR(GetLastError()); |
5597 } |
5602 } |
5598 #endif |
5603 #endif |
5599 if (ret >= 0) { |
5604 if (ret >= 0) { |
5600 RETURN ( __mkSmallInteger(ret) ); |
5605 RETURN ( __mkSmallInteger(ret) ); |
5601 } |
5606 } |
5602 __threadErrno = __WIN32_ERR(GetLastError()); |
5607 __threadErrno = __WIN32_ERR(GetLastError()); |
5603 RETURN (nil); |
5608 RETURN (nil); |
5604 } |
5609 } |
5605 |
5610 |
5606 if (__isUnicode16String(aPathName)) { |
5611 if (__isUnicode16String(aPathName)) { |
5607 wchar_t _wPathName[MAXPATHLEN+1]; |
5612 wchar_t _wPathName[MAXPATHLEN+1]; |
5608 int i, l; |
5613 int i, l; |
5609 |
5614 |
5610 l = __unicode16StringSize(aPathName); |
5615 l = __unicode16StringSize(aPathName); |
5611 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5616 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5612 for (i=0; i<l; i++) { |
5617 for (i=0; i<l; i++) { |
5613 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5618 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5614 } |
5619 } |
5615 _wPathName[i] = 0; |
5620 _wPathName[i] = 0; |
5616 #ifdef DO_WRAP_CALLS |
5621 #ifdef DO_WRAP_CALLS |
5617 do { |
5622 do { |
5618 __threadErrno = 0; |
5623 __threadErrno = 0; |
5619 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5624 ret = STX_API_NOINT_CALL1( "GetFileAttributesW", GetFileAttributesW, _wPathName); |
5620 } while ((ret < 0) && (__threadErrno == EINTR)); |
5625 } while ((ret < 0) && (__threadErrno == EINTR)); |
5621 #else |
5626 #else |
5622 ret = GetFileAttributesW(_wPathName); |
5627 ret = GetFileAttributesW(_wPathName); |
5623 if (ret < 0) { |
5628 if (ret < 0) { |
5624 __threadErrno = __WIN32_ERR(GetLastError()); |
5629 __threadErrno = __WIN32_ERR(GetLastError()); |
5625 } |
5630 } |
5626 #endif |
5631 #endif |
5627 if (ret >= 0) { |
5632 if (ret >= 0) { |
5628 RETURN ( __mkSmallInteger(ret) ); |
5633 RETURN ( __mkSmallInteger(ret) ); |
5629 } |
5634 } |
5630 __threadErrno = __WIN32_ERR(GetLastError()); |
5635 __threadErrno = __WIN32_ERR(GetLastError()); |
5631 RETURN (nil); |
5636 RETURN (nil); |
5632 } |
5637 } |
5633 %}. |
5638 %}. |
5634 ^ self primitiveFailed |
5639 ^ self primitiveFailed |
5635 |
5640 |
5636 " |
5641 " |
5656 Notice: if symbolic links are involved, the result may look different |
5661 Notice: if symbolic links are involved, the result may look different |
5657 from what you expect." |
5662 from what you expect." |
5658 |
5663 |
5659 %{ /* xxSTACK: 16000 */ |
5664 %{ /* xxSTACK: 16000 */ |
5660 if (__isStringLike(aPathName)) { |
5665 if (__isStringLike(aPathName)) { |
5661 char nameBuffer[MAXPATHLEN + 1 + MAXPATHLEN + 1]; |
5666 char nameBuffer[MAXPATHLEN + 1 + MAXPATHLEN + 1]; |
5662 char *pFinal; |
5667 char *pFinal; |
5663 int rslt; |
5668 int rslt; |
5664 |
5669 |
5665 #ifdef DO_WRAP_CALLS |
5670 #ifdef DO_WRAP_CALLS |
5666 char _aPathName[MAXPATHLEN]; |
5671 char _aPathName[MAXPATHLEN]; |
5667 |
5672 |
5668 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5673 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5669 do { |
5674 do { |
5670 __threadErrno = 0; |
5675 __threadErrno = 0; |
5671 rslt = STX_API_NOINT_CALL4( "GetFullPathName", GetFullPathName, _aPathName, sizeof(nameBuffer), nameBuffer, &pFinal); |
5676 rslt = STX_API_NOINT_CALL4( "GetFullPathName", GetFullPathName, _aPathName, sizeof(nameBuffer), nameBuffer, &pFinal); |
5672 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5677 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5673 #else |
5678 #else |
5674 rslt = GetFullPathName(__stringVal(aPathName), sizeof(nameBuffer), nameBuffer, &pFinal); |
5679 rslt = GetFullPathName(__stringVal(aPathName), sizeof(nameBuffer), nameBuffer, &pFinal); |
5675 #endif |
5680 #endif |
5676 |
5681 |
5677 if (rslt > 0) { |
5682 if (rslt > 0) { |
5678 /* |
5683 /* |
5679 * Attention: GetLongPathName is not available on old NT4.0/W95/W98 |
5684 * Attention: GetLongPathName is not available on old NT4.0/W95/W98 |
5680 */ |
5685 */ |
5681 static FARPROC GetLongPathName_entry = NULL; |
5686 static FARPROC GetLongPathName_entry = NULL; |
5682 #ifdef NO_NT4_0_COMPATIBILITY |
5687 #ifdef NO_NT4_0_COMPATIBILITY |
5683 GetLongPathName_entry = (FARPROC) GetLongPathName; |
5688 GetLongPathName_entry = (FARPROC) GetLongPathName; |
5684 #else |
5689 #else |
5685 if (GetLongPathName_entry == NULL) { |
5690 if (GetLongPathName_entry == NULL) { |
5686 GetLongPathName_entry = __get_kernel32_functionAddress("GetLongPathNameA"); |
5691 GetLongPathName_entry = __get_kernel32_functionAddress("GetLongPathNameA"); |
5687 } |
5692 } |
5688 #endif /* NO_NT4_0_COMPATIBILITY */ |
5693 #endif /* NO_NT4_0_COMPATIBILITY */ |
5689 |
5694 |
5690 if (GetLongPathName_entry) { |
5695 if (GetLongPathName_entry) { |
5691 #ifdef DO_WRAP_CALLS |
5696 #ifdef DO_WRAP_CALLS |
5692 do { |
5697 do { |
5693 __threadErrno = 0; |
5698 __threadErrno = 0; |
5694 rslt = STX_API_NOINT_CALL3( "GetLongPathName", GetLongPathName_entry, nameBuffer, nameBuffer, sizeof(nameBuffer)); |
5699 rslt = STX_API_NOINT_CALL3( "GetLongPathName", GetLongPathName_entry, nameBuffer, nameBuffer, sizeof(nameBuffer)); |
5695 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5700 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5696 #else |
5701 #else |
5697 rslt = (*GetLongPathName_entry)(nameBuffer, nameBuffer, sizeof(nameBuffer)); |
5702 rslt = (*GetLongPathName_entry)(nameBuffer, nameBuffer, sizeof(nameBuffer)); |
5698 #endif |
5703 #endif |
5699 } |
5704 } |
5700 } |
5705 } |
5701 if (rslt > 0) { |
5706 if (rslt > 0) { |
5702 RETURN ( __MKSTRING(nameBuffer) ); |
5707 RETURN ( __MKSTRING(nameBuffer) ); |
5703 } |
5708 } |
5704 __threadErrno = __WIN32_ERR(GetLastError()); |
5709 __threadErrno = __WIN32_ERR(GetLastError()); |
5705 RETURN (nil); |
5710 RETURN (nil); |
5706 } |
5711 } |
5707 if (__isUnicode16String(aPathName)) { |
5712 if (__isUnicode16String(aPathName)) { |
5708 wchar_t nameBuffer[MAXPATHLEN + 1 + MAXPATHLEN + 1]; |
5713 wchar_t nameBuffer[MAXPATHLEN + 1 + MAXPATHLEN + 1]; |
5709 char *pFinal; |
5714 char *pFinal; |
5710 int rslt; |
5715 int rslt; |
5711 wchar_t _aPathName[MAXPATHLEN+1]; |
5716 wchar_t _aPathName[MAXPATHLEN+1]; |
5712 int i, l; |
5717 int i, l; |
5713 |
5718 |
5714 l = __unicode16StringSize(aPathName); |
5719 l = __unicode16StringSize(aPathName); |
5715 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5720 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5716 for (i=0; i<l; i++) { |
5721 for (i=0; i<l; i++) { |
5717 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
5722 _aPathName[i] = __unicode16StringVal(aPathName)[i]; |
5718 } |
5723 } |
5719 _aPathName[i] = 0; |
5724 _aPathName[i] = 0; |
5720 |
5725 |
5721 #ifdef DO_WRAP_CALLS |
5726 #ifdef DO_WRAP_CALLS |
5722 do { |
5727 do { |
5723 __threadErrno = 0; |
5728 __threadErrno = 0; |
5724 rslt = STX_API_NOINT_CALL4( "GetFullPathNameW", GetFullPathNameW, _aPathName, MAXPATHLEN, nameBuffer, &pFinal); |
5729 rslt = STX_API_NOINT_CALL4( "GetFullPathNameW", GetFullPathNameW, _aPathName, MAXPATHLEN, nameBuffer, &pFinal); |
5725 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5730 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5726 #else |
5731 #else |
5727 rslt = GetFullPathName(_aPathName, MAXPATHLEN, nameBuffer, &pFinal); |
5732 rslt = GetFullPathName(_aPathName, MAXPATHLEN, nameBuffer, &pFinal); |
5728 #endif |
5733 #endif |
5729 if (rslt > 0) { |
5734 if (rslt > 0) { |
5730 /* |
5735 /* |
5731 * Attention: GetLongPathName is not available on old NT4.0/W95/W98 |
5736 * Attention: GetLongPathName is not available on old NT4.0/W95/W98 |
5732 */ |
5737 */ |
5733 static FARPROC GetLongPathNameW_entry = NULL; |
5738 static FARPROC GetLongPathNameW_entry = NULL; |
5734 #ifdef NO_NT4_0_COMPATIBILITY |
5739 #ifdef NO_NT4_0_COMPATIBILITY |
5735 GetLongPathNameW_entry = (FARPROC) GetLongPathNameW; |
5740 GetLongPathNameW_entry = (FARPROC) GetLongPathNameW; |
5736 #else |
5741 #else |
5737 if (GetLongPathNameW_entry == NULL) { |
5742 if (GetLongPathNameW_entry == NULL) { |
5738 GetLongPathNameW_entry = __get_kernel32_functionAddress("GetLongPathNameW"); |
5743 GetLongPathNameW_entry = __get_kernel32_functionAddress("GetLongPathNameW"); |
5739 } |
5744 } |
5740 #endif /* NO_NT4_0_COMPATIBILITY */ |
5745 #endif /* NO_NT4_0_COMPATIBILITY */ |
5741 |
5746 |
5742 if (GetLongPathNameW_entry) { |
5747 if (GetLongPathNameW_entry) { |
5743 #ifdef DO_WRAP_CALLS |
5748 #ifdef DO_WRAP_CALLS |
5744 do { |
5749 do { |
5745 __threadErrno = 0; |
5750 __threadErrno = 0; |
5746 rslt = STX_API_NOINT_CALL3( "GetLongPathNameW", GetLongPathNameW_entry, nameBuffer, nameBuffer, MAXPATHLEN); |
5751 rslt = STX_API_NOINT_CALL3( "GetLongPathNameW", GetLongPathNameW_entry, nameBuffer, nameBuffer, MAXPATHLEN); |
5747 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5752 } while ((rslt < 0) && (__threadErrno == EINTR)); |
5748 #else |
5753 #else |
5749 rslt = (*GetLongPathNameW_entry)(nameBuffer, nameBuffer, MAXPATHLEN); |
5754 rslt = (*GetLongPathNameW_entry)(nameBuffer, nameBuffer, MAXPATHLEN); |
5750 #endif |
5755 #endif |
5751 } |
5756 } |
5752 } |
5757 } |
5753 if (rslt > 0) { |
5758 if (rslt > 0) { |
5754 RETURN ( __MKU16STRING(nameBuffer) ); |
5759 RETURN ( __MKU16STRING(nameBuffer) ); |
5755 } |
5760 } |
5756 __threadErrno = __WIN32_ERR(GetLastError()); |
5761 __threadErrno = __WIN32_ERR(GetLastError()); |
5757 } |
5762 } |
5758 %}. |
5763 %}. |
5759 ^ nil |
5764 ^ nil |
5760 |
5765 |
5761 " |
5766 " |
5789 |
5794 |
5790 %{ |
5795 %{ |
5791 int ret; |
5796 int ret; |
5792 |
5797 |
5793 if (__isSmallInteger(anInteger)) { |
5798 if (__isSmallInteger(anInteger)) { |
5794 if (__isStringLike(aPathName)) { |
5799 if (__isStringLike(aPathName)) { |
5795 #ifdef DO_WRAP_CALLS |
5800 #ifdef DO_WRAP_CALLS |
5796 char _aPathName[MAXPATHLEN]; |
5801 char _aPathName[MAXPATHLEN]; |
5797 |
5802 |
5798 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5803 strncpy(_aPathName, __stringVal(aPathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
5799 do { |
5804 do { |
5800 __threadErrno = 0; |
5805 __threadErrno = 0; |
5801 ret = STX_API_NOINT_CALL2( "SetFileAttributesA", SetFileAttributesA, _aPathName, __intVal(anInteger) ); |
5806 ret = STX_API_NOINT_CALL2( "SetFileAttributesA", SetFileAttributesA, _aPathName, __intVal(anInteger) ); |
5802 } while ((ret < 0) && (__threadErrno == EINTR)); |
5807 } while ((ret < 0) && (__threadErrno == EINTR)); |
5803 #else |
5808 #else |
5804 ret = SetFileAttributesA((char *) __stringVal(aPathName), __intVal(anInteger)); |
5809 ret = SetFileAttributesA((char *) __stringVal(aPathName), __intVal(anInteger)); |
5805 if (ret < 0) { |
5810 if (ret < 0) { |
5806 __threadErrno = __WIN32_ERR(GetLastError()); |
5811 __threadErrno = __WIN32_ERR(GetLastError()); |
5807 } |
5812 } |
5808 #endif |
5813 #endif |
5809 if (ret >= 0) { |
5814 if (ret >= 0) { |
5810 RETURN ( true ); |
5815 RETURN ( true ); |
5811 } |
5816 } |
5812 __threadErrno = __WIN32_ERR(GetLastError()); |
5817 __threadErrno = __WIN32_ERR(GetLastError()); |
5813 RETURN (false); |
5818 RETURN (false); |
5814 } |
5819 } |
5815 |
5820 |
5816 if (__isUnicode16String(aPathName)) { |
5821 if (__isUnicode16String(aPathName)) { |
5817 wchar_t _wPathName[MAXPATHLEN+1]; |
5822 wchar_t _wPathName[MAXPATHLEN+1]; |
5818 int i, l; |
5823 int i, l; |
5819 |
5824 |
5820 l = __unicode16StringSize(aPathName); |
5825 l = __unicode16StringSize(aPathName); |
5821 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5826 if (l > MAXPATHLEN) l = MAXPATHLEN; |
5822 for (i=0; i<l; i++) { |
5827 for (i=0; i<l; i++) { |
5823 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5828 _wPathName[i] = __unicode16StringVal(aPathName)[i]; |
5824 } |
5829 } |
5825 _wPathName[i] = 0; |
5830 _wPathName[i] = 0; |
5826 #ifdef DO_WRAP_CALLS |
5831 #ifdef DO_WRAP_CALLS |
5827 do { |
5832 do { |
5828 __threadErrno = 0; |
5833 __threadErrno = 0; |
5829 ret = STX_API_NOINT_CALL2( "SetFileAttributesW", SetFileAttributesW, _wPathName, __intVal(anInteger) ); |
5834 ret = STX_API_NOINT_CALL2( "SetFileAttributesW", SetFileAttributesW, _wPathName, __intVal(anInteger) ); |
5830 } while ((ret < 0) && (__threadErrno == EINTR)); |
5835 } while ((ret < 0) && (__threadErrno == EINTR)); |
5831 #else |
5836 #else |
5832 ret = SetFileAttributesW(_wPathName, __intVal(anInteger)); |
5837 ret = SetFileAttributesW(_wPathName, __intVal(anInteger)); |
5833 if (ret < 0) { |
5838 if (ret < 0) { |
5834 __threadErrno = __WIN32_ERR(GetLastError()); |
5839 __threadErrno = __WIN32_ERR(GetLastError()); |
5835 } |
5840 } |
5836 #endif |
5841 #endif |
5837 if (ret >= 0) { |
5842 if (ret >= 0) { |
5838 RETURN ( true ); |
5843 RETURN ( true ); |
5839 } |
5844 } |
5840 __threadErrno = __WIN32_ERR(GetLastError()); |
5845 __threadErrno = __WIN32_ERR(GetLastError()); |
5841 RETURN (false); |
5846 RETURN (false); |
5842 } |
5847 } |
5843 } |
5848 } |
5844 %}. |
5849 %}. |
5845 ^ self primitiveFailed |
5850 ^ self primitiveFailed |
5846 ! |
5851 ! |
5847 |
5852 |
5848 setCurrentDirectory:pathName |
5853 setCurrentDirectory:pathName |
5849 pathName bitsPerCharacter == 16 ifTrue:[ |
5854 pathName bitsPerCharacter == 16 ifTrue:[ |
5850 self primSetCurrentDirectoryW:(pathName copyWith:(Character value:0)) |
5855 self primSetCurrentDirectoryW:(pathName copyWith:(Character value:0)) |
5851 ] ifFalse:[ |
5856 ] ifFalse:[ |
5852 self primSetCurrentDirectoryA:pathName |
5857 self primSetCurrentDirectoryA:pathName |
5853 ]. |
5858 ]. |
5854 |
5859 |
5855 " |
5860 " |
5856 self getCurrentDirectory |
5861 self getCurrentDirectory |
5857 self setCurrentDirectory:'C:\Users\cg\work\stx\projects' |
5862 self setCurrentDirectory:'C:\Users\cg\work\stx\projects' |
6586 global data maintained by dynamic-link libraries (DLLs) |
6591 global data maintained by dynamic-link libraries (DLLs) |
6587 may be compromised if TerminateProcess is used. |
6592 may be compromised if TerminateProcess is used. |
6588 TODO: send it a WM_QUIT instead, to allow for proper shutdown." |
6593 TODO: send it a WM_QUIT instead, to allow for proper shutdown." |
6589 |
6594 |
6590 %{ |
6595 %{ |
6591 if (__isExternalAddressLike(processHandle) ) { |
6596 if (__isExternalAddressLike(processHandleOrPid) ) { |
6592 HANDLE hProcess = _HANDLEVal(processHandle); |
6597 HANDLE hProcess = _HANDLEVal(processHandleOrPid); |
6593 |
6598 |
6594 #ifdef PROCESS1DEBUGWIN32 |
|
6595 console_printf("TerminateProcess handle: %x\n", hProcess); |
|
6596 #endif |
|
6597 if (hProcess != 0) { |
6599 if (hProcess != 0) { |
6598 TerminateProcess(hProcess, __intVal(exitCode)); |
6600 TerminateProcess( hProcess, __intVal(exitCode) ); |
6599 } else { |
6601 } |
6600 console_fprintf(stderr, "Win32OS [warning]: wrong hProcess in TerminateProcess\n"); |
6602 RETURN( true ); |
6601 } |
6603 } else if( __isSmallInteger(processHandleOrPid) ) { |
6602 } else { |
6604 HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0, __smallIntegerVal(processHandleOrPid)); |
6603 console_fprintf(stderr, "Win32OS [warning]: wrong processHandle in TerminateProcess\n"); |
6605 |
6604 } |
6606 if( hProcess != 0 ) { |
6605 %} |
6607 TerminateProcess( hProcess, __intVal(exitCode) ); |
|
6608 CloseHandle(hProcess); |
|
6609 } |
|
6610 RETURN( true ); |
|
6611 } |
|
6612 %}. |
|
6613 self primitiveFailed:#invalidParameter. |
|
6614 |
6606 |
6615 |
6607 "Modified: / 28.12.1995 / 15:05:37 / stefan" |
6616 "Modified: / 28.12.1995 / 15:05:37 / stefan" |
6608 "Modified: / 27.1.1998 / 20:05:47 / cg" |
6617 "Modified: / 27.1.1998 / 20:05:47 / cg" |
6609 ! |
6618 ! |
6610 |
6619 |
6611 terminateProcessGroup:processGroupHandle |
6620 terminateProcessGroup:processGroupHandleOrPid |
6612 "terminate a process group. |
6621 "terminate a process group. |
6613 The processes should have a chance to do some cleanup. |
6622 The processes should have a chance to do some cleanup. |
6614 WIN32: |
6623 WIN32: |
6615 The processGroup is terminated by sending it a CTRL-C |
6624 The processGroup is terminated by sending it a CTRL-C |
6616 using GenerateConsoleCtrlEvent." |
6625 using GenerateConsoleCtrlEvent." |
6617 |
6626 |
6618 %{ |
6627 | pid list | |
6619 if (__isExternalAddressLike(processGroupHandle) ) { |
6628 |
6620 HANDLE hProcessGroup = _HANDLEVal(processGroupHandle); |
6629 list := self getAllProcesses. |
6621 DWORD processGroupId; |
6630 list size == 0 ifTrue:[^ self ]. |
6622 |
6631 |
6623 if (hProcessGroup != (HANDLE)0) { |
6632 processGroupHandleOrPid isInteger ifTrue:[ |
6624 processGroupId = __intVal( ((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(processGroupHandle))->pid ); |
6633 pid := processGroupHandleOrPid |
6625 |
6634 ] ifFalse:[ |
6626 #ifdef PROCESS1DEBUGWIN32 |
6635 pid := processGroupHandleOrPid pid. |
6627 console_printf("TerminateProcessGroup processGroupHandle: %x (%d)\n", hProcessGroup, processGroupId); |
6636 ]. |
6628 #endif |
6637 list do:[:anOSProcess | |
6629 GenerateConsoleCtrlEvent(CTRL_C_EVENT, processGroupId); |
6638 ( anOSProcess parentPid == pid ) ifTrue:[ |
6630 } else { |
6639 self terminateProcess:( anOSProcess pid ). |
6631 console_fprintf(stderr, "Win32OS [warning]: wrong hProcessGroup in TerminateProcessGroup \n"); |
6640 ]. |
6632 } |
6641 ]. |
6633 } else { |
6642 |
6634 console_fprintf(stderr, "Win32OS [warning]: wrong processGroupHandle in TerminateProcessGroup \n"); |
|
6635 } |
|
6636 %} |
|
6637 ! ! |
6643 ! ! |
6638 |
6644 |
6639 !Win32OperatingSystem class methodsFor:'ipc support'! |
6645 !Win32OperatingSystem class methodsFor:'ipc support'! |
6640 |
6646 |
6641 makePipe |
6647 makePipe |
8378 int __bufferSize; |
8419 int __bufferSize; |
8379 int __useLocalBuffer = 0; |
8420 int __useLocalBuffer = 0; |
8380 unsigned int __localBuffer = 0; |
8421 unsigned int __localBuffer = 0; |
8381 |
8422 |
8382 if (__isSmallInteger(bufferOrInteger)) { |
8423 if (__isSmallInteger(bufferOrInteger)) { |
8383 __useLocalBuffer = 1; |
8424 __useLocalBuffer = 1; |
8384 __buffer = (unsigned char *)&__localBuffer; |
8425 __buffer = (unsigned char *)&__localBuffer; |
8385 __bufferSize = __smallIntegerVal(bufferOrInteger); |
8426 __bufferSize = __smallIntegerVal(bufferOrInteger); |
8386 if (__bufferSize > sizeof(INT)) |
8427 if (__bufferSize > sizeof(INT)) |
8387 __bufferSize = sizeof(INT); |
8428 __bufferSize = sizeof(INT); |
8388 } else if (__isString(bufferOrInteger)) { |
8429 } else if (__isString(bufferOrInteger)) { |
8389 __buffer = __stringVal(bufferOrInteger); |
8430 __buffer = __stringVal(bufferOrInteger); |
8390 __bufferSize = __stringSize(bufferOrInteger); |
8431 __bufferSize = __stringSize(bufferOrInteger); |
8391 } else if (__isByteArray(bufferOrInteger)) { |
8432 } else if (__isByteArray(bufferOrInteger)) { |
8392 __buffer = __byteArrayVal(bufferOrInteger); |
8433 __buffer = __byteArrayVal(bufferOrInteger); |
8393 __bufferSize = __byteArraySize(bufferOrInteger); |
8434 __bufferSize = __byteArraySize(bufferOrInteger); |
8394 } else { |
8435 } else { |
8395 goto error; |
8436 goto error; |
8396 } |
8437 } |
8397 |
8438 |
8398 if (P_RtlGenRandom == 0) { |
8439 if (P_RtlGenRandom == 0) { |
8399 HINSTANCE hAdvapi32 = LoadLibrary("advapi32.dll"); |
8440 HINSTANCE hAdvapi32 = LoadLibrary("advapi32.dll"); |
8400 // console_printf("hAdvapi32: %x\n", hAdvapi32); |
8441 // console_printf("hAdvapi32: %x\n", hAdvapi32); |
8401 if (hAdvapi32) { |
8442 if (hAdvapi32) { |
8402 P_RtlGenRandom = (BOOL (__stdcall *)(PVOID , ULONG)) |
8443 P_RtlGenRandom = (BOOL (__stdcall *)(PVOID , ULONG)) |
8403 GetProcAddress(hAdvapi32, "SystemFunction036"); |
8444 GetProcAddress(hAdvapi32, "SystemFunction036"); |
8404 // console_printf("P_RtlGenRandom: %x\n", P_RtlGenRandom); |
8445 // console_printf("P_RtlGenRandom: %x\n", P_RtlGenRandom); |
8405 if (P_RtlGenRandom == 0) { |
8446 if (P_RtlGenRandom == 0) { |
8406 goto error; |
8447 goto error; |
8407 } |
8448 } |
8408 } |
8449 } |
8409 } |
8450 } |
8410 if ((*P_RtlGenRandom)(__buffer, __bufferSize)) { |
8451 if ((*P_RtlGenRandom)(__buffer, __bufferSize)) { |
8411 if (__useLocalBuffer) { |
8452 if (__useLocalBuffer) { |
8412 RETURN(__mkSmallInteger(__localBuffer & _MAX_INT)); |
8453 RETURN(__mkSmallInteger(__localBuffer & _MAX_INT)); |
8413 } |
8454 } |
8414 RETURN (bufferOrInteger); |
8455 RETURN (bufferOrInteger); |
8415 } |
8456 } |
8416 error: ; |
8457 error: ; |
8417 %}. |
8458 %}. |
8418 self primitiveFailed. |
8459 self primitiveFailed. |
8419 ^ nil |
8460 ^ nil |
10045 |
10086 |
10046 t = __longIntVal(osSeconds); |
10087 t = __longIntVal(osSeconds); |
10047 |
10088 |
10048 /* try cache */ |
10089 /* try cache */ |
10049 { |
10090 { |
10050 OBJ lastSeconds, lastTimeInfo; |
10091 OBJ lastSeconds, lastTimeInfo; |
10051 |
10092 |
10052 lastSeconds = @global(LastTimeInfoSeconds); |
10093 lastSeconds = @global(LastTimeInfoSeconds); |
10053 if (lastSeconds |
10094 if (lastSeconds |
10054 && (__longIntVal(lastSeconds) == t) |
10095 && (__longIntVal(lastSeconds) == t) |
10055 && (@global(LastTimeInfoMilliseconds) == osMilliseconds) |
10096 && (@global(LastTimeInfoMilliseconds) == osMilliseconds) |
10056 && (@global(LastTimeInfoIsLocal) == isLocalTime) |
10097 && (@global(LastTimeInfoIsLocal) == isLocalTime) |
10057 ) { |
10098 ) { |
10058 lastTimeInfo = @global(LastTimeInfo); |
10099 lastTimeInfo = @global(LastTimeInfo); |
10059 if (lastTimeInfo != nil) { |
10100 if (lastTimeInfo != nil) { |
10060 RETURN (lastTimeInfo); |
10101 RETURN (lastTimeInfo); |
10061 } |
10102 } |
10062 } |
10103 } |
10063 } |
10104 } |
10064 |
10105 |
10065 TimetToFileTime((time_t)t, &fileTime); |
10106 TimetToFileTime((time_t)t, &fileTime); |
10066 |
10107 |
10067 if (isLocalTime == true) { |
10108 if (isLocalTime == true) { |
10068 TIME_ZONE_INFORMATION tzInfo; |
10109 TIME_ZONE_INFORMATION tzInfo; |
10069 int tzState; |
10110 int tzState; |
10070 LONGLONG longTime; |
10111 LONGLONG longTime; |
10071 |
10112 |
10072 FileTimeToLocalFileTime(&fileTime, &localFileTime); |
10113 FileTimeToLocalFileTime(&fileTime, &localFileTime); |
10073 FileTimeToSystemTime(&localFileTime, &sysTime); |
10114 FileTimeToSystemTime(&localFileTime, &sysTime); |
10074 |
10115 |
10075 longTime = ((LONGLONG)fileTime.dwHighDateTime << 32) + fileTime.dwLowDateTime; |
10116 longTime = ((LONGLONG)fileTime.dwHighDateTime << 32) + fileTime.dwLowDateTime; |
10076 longTime -= ((LONGLONG)localFileTime.dwHighDateTime << 32) + localFileTime.dwLowDateTime; |
10117 longTime -= ((LONGLONG)localFileTime.dwHighDateTime << 32) + localFileTime.dwLowDateTime; |
10077 utcOffset = __mkSmallInteger((INT)(longTime / 10000000)); |
10118 utcOffset = __mkSmallInteger((INT)(longTime / 10000000)); |
10078 |
10119 |
10079 if ((tzState = GetTimeZoneInformation(&tzInfo)) < 0) { |
10120 if ((tzState = GetTimeZoneInformation(&tzInfo)) < 0) { |
10080 reason = @symbol(getTimeZoneFailed); |
10121 reason = @symbol(getTimeZoneFailed); |
10081 goto error; |
10122 goto error; |
10082 } |
10123 } |
10083 dstOffset = __mkSmallInteger((tzInfo.Bias + tzInfo.DaylightBias) * 60); |
10124 dstOffset = __mkSmallInteger((tzInfo.Bias + tzInfo.DaylightBias) * 60); |
10084 } else { |
10125 } else { |
10085 FileTimeToSystemTime(&fileTime, &sysTime); |
10126 FileTimeToSystemTime(&fileTime, &sysTime); |
10086 utcOffset = __mkSmallInteger(0); |
10127 utcOffset = __mkSmallInteger(0); |
10087 } |
10128 } |
10088 |
10129 |
10089 hours = __mkSmallInteger(sysTime.wHour); |
10130 hours = __mkSmallInteger(sysTime.wHour); |
10090 minutes = __mkSmallInteger(sysTime.wMinute); |
10131 minutes = __mkSmallInteger(sysTime.wMinute); |
10091 seconds = __mkSmallInteger(sysTime.wSecond); |
10132 seconds = __mkSmallInteger(sysTime.wSecond); |
10450 |pid status code core| |
10491 |pid status code core| |
10451 %{ |
10492 %{ |
10452 DWORD endStatus; |
10493 DWORD endStatus; |
10453 |
10494 |
10454 if (__isExternalAddressLike(pidToWait) ) { |
10495 if (__isExternalAddressLike(pidToWait) ) { |
10455 HANDLE __pidToWait = _HANDLEVal(pidToWait); |
10496 HANDLE __pidToWait = _HANDLEVal(pidToWait); |
10456 int t; |
10497 int t; |
10457 |
10498 |
10458 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10499 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10459 console_printf("childProcessWait %x b %d\n",__pidToWait,blocking==true); |
10500 console_printf("childProcessWait %x b %d\n",__pidToWait,blocking==true); |
10460 #endif |
10501 #endif |
10461 t = (blocking==true) ? INFINITE : 0; |
10502 t = (blocking==true) ? INFINITE : 0; |
10462 |
10503 |
10463 #ifdef DO_WRAP_CALLS |
10504 #ifdef DO_WRAP_CALLS |
10464 if (t == 0) { |
10505 if (t == 0) { |
10465 /* no need for WRAP-call; does not block */ |
10506 /* no need for WRAP-call; does not block */ |
10466 endStatus = WaitForSingleObject(__pidToWait, t); |
10507 endStatus = WaitForSingleObject(__pidToWait, t); |
10467 if (endStatus < 0) { |
10508 if (endStatus < 0) { |
10468 __threadErrno = __WIN32_ERR(GetLastError()); |
10509 __threadErrno = __WIN32_ERR(GetLastError()); |
10469 } |
10510 } |
10470 } else { |
10511 } else { |
10471 do { |
10512 do { |
10472 __threadErrno = 0; |
10513 __threadErrno = 0; |
10473 endStatus = STX_API_CALL2( "WaitForSingleObject", WaitForSingleObject, __pidToWait, t); |
10514 endStatus = STX_API_CALL2( "WaitForSingleObject", WaitForSingleObject, __pidToWait, t); |
10474 } while ((endStatus < 0) && (__threadErrno == EINTR)); |
10515 } while ((endStatus < 0) && (__threadErrno == EINTR)); |
10475 } |
10516 } |
10476 #else |
10517 #else |
10477 endStatus = WaitForSingleObject(__pidToWait, t); |
10518 endStatus = WaitForSingleObject(__pidToWait, t); |
10478 if (endStatus < 0) { |
10519 if (endStatus < 0) { |
10479 __threadErrno = __WIN32_ERR(GetLastError()); |
10520 __threadErrno = __WIN32_ERR(GetLastError()); |
10480 } |
10521 } |
10481 #endif |
10522 #endif |
10482 if ( endStatus == WAIT_TIMEOUT ) { |
10523 if ( endStatus == WAIT_TIMEOUT ) { |
10483 if (blocking==true) |
10524 if (blocking==true) |
10484 status = @symbol(timeout); |
10525 status = @symbol(timeout); |
10485 else { |
10526 else { |
10486 status = @symbol(continue); |
10527 status = @symbol(continue); |
10487 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10528 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10488 console_printf("ret nil\n"); |
10529 console_printf("ret nil\n"); |
10489 #endif |
10530 #endif |
10490 RETURN(nil); |
10531 RETURN(nil); |
10491 } |
10532 } |
10492 } else { |
10533 } else { |
10493 status = @symbol(exit); |
10534 status = @symbol(exit); |
10494 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10535 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10495 console_printf("exit\n"); |
10536 console_printf("exit\n"); |
10496 #endif |
10537 #endif |
10497 if (endStatus == WAIT_OBJECT_0) { |
10538 if (endStatus == WAIT_OBJECT_0) { |
10498 DWORD exitCode; |
10539 DWORD exitCode; |
10499 |
10540 |
10500 if (GetExitCodeProcess(__pidToWait, &exitCode)) { |
10541 if (GetExitCodeProcess(__pidToWait, &exitCode)) { |
10501 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10542 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10502 console_printf("exitCode: %d\n", exitCode); |
10543 console_printf("exitCode: %d\n", exitCode); |
10503 #endif |
10544 #endif |
10504 if (exitCode == STILL_ACTIVE) { |
10545 if (exitCode == STILL_ACTIVE) { |
10505 RETURN(nil); |
10546 RETURN(nil); |
10506 } |
10547 } |
10507 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10548 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10508 console_printf("exit %d\n", exitCode); |
10549 console_printf("exit %d\n", exitCode); |
10509 #endif |
10550 #endif |
10510 code = __mkSmallInteger(exitCode); |
10551 code = __mkSmallInteger(exitCode); |
10511 } else { |
10552 } else { |
10512 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10553 #ifdef PROCESSDEBUG_CHILDPROCESSWAIT |
10513 console_printf("GetExitCodeProcess failed\n"); |
10554 console_printf("GetExitCodeProcess failed\n"); |
10514 #endif |
10555 #endif |
10515 code = __mkSmallInteger(GetLastError()); |
10556 code = __mkSmallInteger(GetLastError()); |
10516 } |
10557 } |
10517 } else { |
10558 } else { |
10518 code = __mkSmallInteger(-1); |
10559 code = __mkSmallInteger(-1); |
10519 } |
10560 } |
10520 } |
10561 } |
10521 core = false; |
10562 core = false; |
10522 pid = pidToWait; |
10563 pid = pidToWait; |
10523 } |
10564 } |
10524 %}. |
10565 %}. |
10525 |
10566 |
10526 (status isNil or:[pid isNil]) ifTrue:[ |
10567 (status isNil or:[pid isNil]) ifTrue:[ |
10527 ^ self primitiveFailed |
10568 ^ self primitiveFailed |
10528 ]. |
10569 ]. |
10529 |
10570 |
10530 "/ Transcript show:'pid: '; show:pid; show:' status: '; show:status; |
10571 "/ Transcript show:'pid: '; show:pid; show:' status: '; show:status; |
10531 "/ show:' code: '; show:code; show:' core:'; showCR:core. |
10572 "/ show:' code: '; show:code; show:' core:'; showCR:core. |
10532 |
10573 |
14807 int bufferSize; |
14848 int bufferSize; |
14808 char miniBuffer[32]; |
14849 char miniBuffer[32]; |
14809 BOOL ok; |
14850 BOOL ok; |
14810 |
14851 |
14811 if ((hFile == 0) || (hFile == INVALID_HANDLE_VALUE)) { |
14852 if ((hFile == 0) || (hFile == INVALID_HANDLE_VALUE)) { |
14812 errSym = @symbol(errorNotOpen); |
14853 errSym = @symbol(errorNotOpen); |
14813 goto bad; |
14854 goto bad; |
14814 } |
14855 } |
14815 if (! __bothSmallInteger(count, firstIndex)) { |
14856 if (! __bothSmallInteger(count, firstIndex)) { |
14816 errSym = @symbol(badArgument); |
14857 errSym = @symbol(badArgument); |
14817 goto bad; |
14858 goto bad; |
14818 } |
14859 } |
14819 cntWanted = __smallIntegerVal(count); |
14860 cntWanted = __smallIntegerVal(count); |
14820 if (cntWanted <= 0) { |
14861 if (cntWanted <= 0) { |
14821 errSym = @symbol(badCount); |
14862 errSym = @symbol(badCount); |
14822 goto bad; |
14863 goto bad; |
14823 } |
14864 } |
14824 offs = __smallIntegerVal(firstIndex) - 1; |
14865 offs = __smallIntegerVal(firstIndex) - 1; |
14825 if (offs < 0) { |
14866 if (offs < 0) { |
14826 errSym = @symbol(badOffset); |
14867 errSym = @symbol(badOffset); |
14827 goto bad; |
14868 goto bad; |
14828 } |
14869 } |
14829 |
14870 |
14830 bufferIsExternalBytes = __isExternalBytesLike(aByteBuffer); |
14871 bufferIsExternalBytes = __isExternalBytesLike(aByteBuffer); |
14831 if (! bufferIsExternalBytes) { |
14872 if (! bufferIsExternalBytes) { |
14832 if (__isByteArray(aByteBuffer)) { |
14873 if (__isByteArray(aByteBuffer)) { |
14833 bufferSize = __byteArraySize(aByteBuffer); |
14874 bufferSize = __byteArraySize(aByteBuffer); |
14834 } else if (__isString(aByteBuffer)) { // not isStringLike here ! |
14875 } else if (__isString(aByteBuffer)) { // not isStringLike here ! |
14835 bufferSize = __stringSize(aByteBuffer); |
14876 bufferSize = __stringSize(aByteBuffer); |
14836 } else { |
14877 } else { |
14837 errSym = @symbol(badBuffer); |
14878 errSym = @symbol(badBuffer); |
14838 goto bad; |
14879 goto bad; |
14839 } |
14880 } |
14840 if (bufferSize < (cntWanted + offs)) { |
14881 if (bufferSize < (cntWanted + offs)) { |
14841 errSym = @symbol(badBufferSize); |
14882 errSym = @symbol(badBufferSize); |
14842 goto bad; |
14883 goto bad; |
14843 } |
14884 } |
14844 if (cntWanted <= sizeof(miniBuffer)) { |
14885 if (cntWanted <= sizeof(miniBuffer)) { |
14845 extPtr = miniBuffer; |
14886 extPtr = miniBuffer; |
14846 } else { |
14887 } else { |
14847 extPtr = malloc(cntWanted); |
14888 extPtr = malloc(cntWanted); |
14848 mustFreeBuffer = 1; |
14889 mustFreeBuffer = 1; |
14849 } |
14890 } |
14850 } else { |
14891 } else { |
14851 OBJ sz; |
14892 OBJ sz; |
14852 |
14893 |
14853 extPtr = (char *)(__externalBytesAddress(aByteBuffer)); |
14894 extPtr = (char *)(__externalBytesAddress(aByteBuffer)); |
14854 sz = __externalBytesSize(aByteBuffer); |
14895 sz = __externalBytesSize(aByteBuffer); |
14855 if (! __isSmallInteger(sz)) { |
14896 if (! __isSmallInteger(sz)) { |
14856 errSym = @symbol(badBufferSize); |
14897 errSym = @symbol(badBufferSize); |
14857 goto bad; |
14898 goto bad; |
14858 } |
14899 } |
14859 bufferSize = __smallIntegerVal(sz); |
14900 bufferSize = __smallIntegerVal(sz); |
14860 if (bufferSize < (cntWanted + offs)) { |
14901 if (bufferSize < (cntWanted + offs)) { |
14861 errSym = @symbol(badBufferSize); |
14902 errSym = @symbol(badBufferSize); |
14862 goto bad; |
14903 goto bad; |
14863 } |
14904 } |
14864 extPtr = extPtr + offs; |
14905 extPtr = extPtr + offs; |
14865 } |
14906 } |
14866 |
14907 |
14867 do { |
14908 do { |
14868 __threadErrno = 0; |
14909 __threadErrno = 0; |
14869 ok = STX_API_NOINT_CALL5( "ReadFile", ReadFile, hFile, extPtr, cntWanted, &cntRead, 0 /* lpOverlapped */); |
14910 ok = STX_API_NOINT_CALL5( "ReadFile", ReadFile, hFile, extPtr, cntWanted, &cntRead, 0 /* lpOverlapped */); |
14870 } while(__threadErrno == EINTR); |
14911 } while(__threadErrno == EINTR); |
14871 |
14912 |
14872 if (ok == TRUE) { |
14913 if (ok == TRUE) { |
14873 if (! bufferIsExternalBytes) { |
14914 if (! bufferIsExternalBytes) { |
14874 /* copy over */ |
14915 /* copy over */ |
14875 memcpy(__byteArrayVal(aByteBuffer)+offs, extPtr, cntRead); |
14916 memcpy(__byteArrayVal(aByteBuffer)+offs, extPtr, cntRead); |
14876 if (mustFreeBuffer) { |
14917 if (mustFreeBuffer) { |
14877 free(extPtr); |
14918 free(extPtr); |
14878 } |
14919 } |
14879 } |
14920 } |
14880 RETURN (__mkSmallInteger(cntRead)); |
14921 RETURN (__mkSmallInteger(cntRead)); |
14881 } |
14922 } |
14882 errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) ); |
14923 errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) ); |
14883 |
14924 |
14884 bad: ; |
14925 bad: ; |
14885 if (mustFreeBuffer) { |
14926 if (mustFreeBuffer) { |
14886 free(extPtr); |
14927 free(extPtr); |
14887 } |
14928 } |
14888 %}. |
14929 %}. |
14889 |
14930 |
14890 errorNumber isNil ifTrue:[ |
14931 errorNumber isNil ifTrue:[ |
14891 self error:'invalid argument(s): ', errSym. |
14932 self error:'invalid argument(s): ', errSym. |
14892 ] ifFalse:[ |
14933 ] ifFalse:[ |
14893 (OperatingSystem errorHolderForNumber:errorNumber) reportError |
14934 (OperatingSystem errorHolderForNumber:errorNumber) reportError |
14894 ]. |
14935 ]. |
14895 |
14936 |
14896 " |
14937 " |
14897 |h buff n| |
14938 |h buff n| |
14898 |
14939 |
15051 int bufferSize; |
15092 int bufferSize; |
15052 char miniBuffer[32]; |
15093 char miniBuffer[32]; |
15053 BOOL ok; |
15094 BOOL ok; |
15054 |
15095 |
15055 if ((hFile == 0) || (hFile == INVALID_HANDLE_VALUE)) { |
15096 if ((hFile == 0) || (hFile == INVALID_HANDLE_VALUE)) { |
15056 errSym = @symbol(errorNotOpen); |
15097 errSym = @symbol(errorNotOpen); |
15057 goto bad; |
15098 goto bad; |
15058 } |
15099 } |
15059 if (! __bothSmallInteger(count, firstIndex)) { |
15100 if (! __bothSmallInteger(count, firstIndex)) { |
15060 errSym = @symbol(badArgument); |
15101 errSym = @symbol(badArgument); |
15061 goto bad; |
15102 goto bad; |
15062 } |
15103 } |
15063 cntWanted = __smallIntegerVal(count); |
15104 cntWanted = __smallIntegerVal(count); |
15064 if (cntWanted <= 0) { |
15105 if (cntWanted <= 0) { |
15065 errSym = @symbol(badCount); |
15106 errSym = @symbol(badCount); |
15066 goto bad; |
15107 goto bad; |
15067 } |
15108 } |
15068 offs = __smallIntegerVal(firstIndex) - 1; |
15109 offs = __smallIntegerVal(firstIndex) - 1; |
15069 if (offs < 0) { |
15110 if (offs < 0) { |
15070 errSym = @symbol(badOffset); |
15111 errSym = @symbol(badOffset); |
15071 goto bad; |
15112 goto bad; |
15072 } |
15113 } |
15073 |
15114 |
15074 bufferIsExternalBytes = __isExternalBytesLike(aByteBuffer); |
15115 bufferIsExternalBytes = __isExternalBytesLike(aByteBuffer); |
15075 if (! bufferIsExternalBytes) { |
15116 if (! bufferIsExternalBytes) { |
15076 if (__isByteArray(aByteBuffer)) { |
15117 if (__isByteArray(aByteBuffer)) { |
15077 bufferSize = __byteArraySize(aByteBuffer); |
15118 bufferSize = __byteArraySize(aByteBuffer); |
15078 } else if (__isStringLike(aByteBuffer)) { |
15119 } else if (__isStringLike(aByteBuffer)) { |
15079 bufferSize = __stringSize(aByteBuffer); |
15120 bufferSize = __stringSize(aByteBuffer); |
15080 } else { |
15121 } else { |
15081 errSym = @symbol(badBuffer); |
15122 errSym = @symbol(badBuffer); |
15082 goto bad; |
15123 goto bad; |
15083 } |
15124 } |
15084 if (bufferSize < (cntWanted + offs)) { |
15125 if (bufferSize < (cntWanted + offs)) { |
15085 errSym = @symbol(badBufferSize); |
15126 errSym = @symbol(badBufferSize); |
15086 goto bad; |
15127 goto bad; |
15087 } |
15128 } |
15088 if (cntWanted <= sizeof(miniBuffer)) { |
15129 if (cntWanted <= sizeof(miniBuffer)) { |
15089 extPtr = miniBuffer; |
15130 extPtr = miniBuffer; |
15090 } else { |
15131 } else { |
15091 extPtr = malloc(cntWanted); |
15132 extPtr = malloc(cntWanted); |
15092 mustFreeBuffer = 1; |
15133 mustFreeBuffer = 1; |
15093 } |
15134 } |
15094 memcpy(extPtr, __byteArrayVal(aByteBuffer)+offs, cntWanted); |
15135 memcpy(extPtr, __byteArrayVal(aByteBuffer)+offs, cntWanted); |
15095 } else { |
15136 } else { |
15096 extPtr = (char *)(__externalBytesAddress(aByteBuffer)); |
15137 extPtr = (char *)(__externalBytesAddress(aByteBuffer)); |
15097 bufferSize = __externalBytesSize(aByteBuffer); |
15138 bufferSize = __externalBytesSize(aByteBuffer); |
15098 if (! __isSmallInteger(bufferSize)) { |
15139 if (! __isSmallInteger(bufferSize)) { |
15099 errSym = @symbol(badBufferSize); |
15140 errSym = @symbol(badBufferSize); |
15100 goto bad; |
15141 goto bad; |
15101 } |
15142 } |
15102 bufferSize = __smallIntegerVal(bufferSize); |
15143 bufferSize = __smallIntegerVal(bufferSize); |
15103 if (bufferSize < (cntWanted + offs)) { |
15144 if (bufferSize < (cntWanted + offs)) { |
15104 errSym = @symbol(badBufferSize); |
15145 errSym = @symbol(badBufferSize); |
15105 goto bad; |
15146 goto bad; |
15106 } |
15147 } |
15107 extPtr = extPtr + offs; |
15148 extPtr = extPtr + offs; |
15108 } |
15149 } |
15109 |
15150 |
15110 do { |
15151 do { |
15111 __threadErrno = 0; |
15152 __threadErrno = 0; |
15112 ok = STX_API_NOINT_CALL5( "WriteFile", WriteFile, hFile, extPtr, cntWanted, &cntWritten, 0 /* lpOverlapped */); |
15153 ok = STX_API_NOINT_CALL5( "WriteFile", WriteFile, hFile, extPtr, cntWanted, &cntWritten, 0 /* lpOverlapped */); |
15113 } while(__threadErrno == EINTR); |
15154 } while(__threadErrno == EINTR); |
15114 |
15155 |
15115 if (ok == TRUE) { |
15156 if (ok == TRUE) { |
15116 if (mustFreeBuffer) { |
15157 if (mustFreeBuffer) { |
15117 free(extPtr); |
15158 free(extPtr); |
15118 } |
15159 } |
15119 RETURN (__mkSmallInteger(cntWritten)); |
15160 RETURN (__mkSmallInteger(cntWritten)); |
15120 } |
15161 } |
15121 errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) ); |
15162 errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) ); |
15122 |
15163 |
15123 bad: ; |
15164 bad: ; |
15124 if (mustFreeBuffer) { |
15165 if (mustFreeBuffer) { |
15125 free(extPtr); |
15166 free(extPtr); |
15126 } |
15167 } |
15127 %}. |
15168 %}. |
15128 errorNumber isNil ifTrue:[ |
15169 errorNumber isNil ifTrue:[ |
15129 self error:'invalid argument(s): ', errSym. |
15170 self error:'invalid argument(s): ', errSym. |
15130 ] ifFalse:[ |
15171 ] ifFalse:[ |
15131 (OperatingSystem errorHolderForNumber:errorNumber) reportError |
15172 (OperatingSystem errorHolderForNumber:errorNumber) reportError |
15132 ]. |
15173 ]. |
15133 |
15174 |
15134 " |
15175 " |
15135 |h buff n| |
15176 |h buff n| |
15136 |
15177 |
15626 struct addrinfo hints; |
15667 struct addrinfo hints; |
15627 struct addrinfo *info = NULL, *infop; |
15668 struct addrinfo *info = NULL, *infop; |
15628 |
15669 |
15629 memset(&hints, 0, sizeof(hints)); |
15670 memset(&hints, 0, sizeof(hints)); |
15630 if (__isSmallInteger(domain)) |
15671 if (__isSmallInteger(domain)) |
15631 hints.ai_family = __intVal(domain); |
15672 hints.ai_family = __intVal(domain); |
15632 if (__isSmallInteger(type)) |
15673 if (__isSmallInteger(type)) |
15633 hints.ai_socktype = __intVal(type); |
15674 hints.ai_socktype = __intVal(type); |
15634 if (__isSmallInteger(proto)) |
15675 if (__isSmallInteger(proto)) |
15635 hints.ai_protocol = __intVal(proto); |
15676 hints.ai_protocol = __intVal(proto); |
15636 |
15677 |
15637 do { |
15678 do { |
15638 /* must refetch in loop */ |
15679 /* must refetch in loop */ |
15639 if (hostName == nil) { |
15680 if (hostName == nil) { |
15640 __hostName = 0; |
15681 __hostName = 0; |
15641 } else if (__isStringLike(hostName)) { |
15682 } else if (__isStringLike(hostName)) { |
15642 __hostName = __stringVal(hostName); |
15683 __hostName = __stringVal(hostName); |
15643 } |
15684 } |
15644 if (serviceName == nil) { |
15685 if (serviceName == nil) { |
15645 __serviceName = 0; |
15686 __serviceName = 0; |
15646 } else if (__isStringLike(serviceName)) { |
15687 } else if (__isStringLike(serviceName)) { |
15647 __serviceName = __stringVal(serviceName); |
15688 __serviceName = __stringVal(serviceName); |
15648 } |
15689 } |
15649 |
15690 |
15650 # ifdef DO_WRAP_CALLS |
15691 # ifdef DO_WRAP_CALLS |
15651 do { |
15692 do { |
15652 __threadErrno = 0; |
15693 __threadErrno = 0; |
15653 res = STX_WSA_NOINT_CALL4( "getaddrinfo", getaddrinfo, __hostName, __serviceName, &hints, &info); |
15694 res = STX_WSA_NOINT_CALL4( "getaddrinfo", getaddrinfo, __hostName, __serviceName, &hints, &info); |
15654 } while ((res < 0) && (__threadErrno == EINTR)); |
15695 } while ((res < 0) && (__threadErrno == EINTR)); |
15655 # else |
15696 # else |
15656 __BEGIN_INTERRUPTABLE__ |
15697 __BEGIN_INTERRUPTABLE__ |
15657 ret = getaddrinfo(__hostName, __serviceName, &hints, &info); |
15698 ret = getaddrinfo(__hostName, __serviceName, &hints, &info); |
15658 __END_INTERRUPTABLE__ |
15699 __END_INTERRUPTABLE__ |
15659 # endif |
15700 # endif |
15660 } while (ret == EAI_SYSTEM && errno == EINTR); |
15701 } while (ret == EAI_SYSTEM && errno == EINTR); |
15661 if (ret != 0) { |
15702 if (ret != 0) { |
15662 switch (ret) { |
15703 switch (ret) { |
15663 case EAI_FAMILY: |
15704 case EAI_FAMILY: |
15664 error = @symbol(badProtocol); |
15705 error = @symbol(badProtocol); |
15665 break; |
15706 break; |
15666 case EAI_SOCKTYPE: |
15707 case EAI_SOCKTYPE: |
15667 error = @symbol(badSocketType); |
15708 error = @symbol(badSocketType); |
15668 break; |
15709 break; |
15669 case EAI_BADFLAGS: |
15710 case EAI_BADFLAGS: |
15670 error = @symbol(badFlags); |
15711 error = @symbol(badFlags); |
15671 break; |
15712 break; |
15672 case EAI_NONAME: |
15713 case EAI_NONAME: |
15673 error = @symbol(unknownHost); |
15714 error = @symbol(unknownHost); |
15674 break; |
15715 break; |
15675 case EAI_SERVICE: |
15716 case EAI_SERVICE: |
15676 error = @symbol(unknownService); |
15717 error = @symbol(unknownService); |
15677 break; |
15718 break; |
15678 case EAI_ADDRFAMILY : |
15719 case EAI_ADDRFAMILY : |
15679 error = @symbol(unknownHostForProtocol); |
15720 error = @symbol(unknownHostForProtocol); |
15680 break; |
15721 break; |
15681 case EAI_NODATA: |
15722 case EAI_NODATA: |
15682 error = @symbol(noAddress); |
15723 error = @symbol(noAddress); |
15683 break; |
15724 break; |
15684 case EAI_MEMORY: |
15725 case EAI_MEMORY: |
15685 error = @symbol(allocationFailure); |
15726 error = @symbol(allocationFailure); |
15686 break; |
15727 break; |
15687 case EAI_FAIL: |
15728 case EAI_FAIL: |
15688 error = @symbol(permanentFailure); |
15729 error = @symbol(permanentFailure); |
15689 break; |
15730 break; |
15690 case EAI_AGAIN: |
15731 case EAI_AGAIN: |
15691 error = @symbol(tryAgain); |
15732 error = @symbol(tryAgain); |
15692 break; |
15733 break; |
15693 case EAI_SYSTEM: |
15734 case EAI_SYSTEM: |
15694 error = @symbol(systemError); |
15735 error = @symbol(systemError); |
15695 break; |
15736 break; |
15696 default: |
15737 default: |
15697 error = @symbol(unknownError); |
15738 error = @symbol(unknownError); |
15698 } |
15739 } |
15699 errorString = __MKSTRING(gai_strerror(ret)); |
15740 errorString = __MKSTRING(gai_strerror(ret)); |
15700 goto err; |
15741 goto err; |
15701 } |
15742 } |
15702 for (cnt=0, infop=info; infop; infop=infop->ai_next) |
15743 for (cnt=0, infop=info; infop; infop=infop->ai_next) |
15703 cnt++; |
15744 cnt++; |
15704 |
15745 |
15705 result = __ARRAY_NEW_INT(cnt); |
15746 result = __ARRAY_NEW_INT(cnt); |
15706 if (result == nil) { |
15747 if (result == nil) { |
15707 error = @symbol(allocationFailure); |
15748 error = @symbol(allocationFailure); |
15708 goto err; |
15749 goto err; |
15709 } |
15750 } |
15710 for (infop=info, cnt=0; infop; infop=infop->ai_next, cnt++) { |
15751 for (infop=info, cnt=0; infop; infop=infop->ai_next, cnt++) { |
15711 OBJ o, resp; |
15752 OBJ o, resp; |
15712 |
15753 |
15713 resp = __ARRAY_NEW_INT(6); |
15754 resp = __ARRAY_NEW_INT(6); |
15714 if (resp == nil) { |
15755 if (resp == nil) { |
15715 error = @symbol(allocationFailure); |
15756 error = @symbol(allocationFailure); |
15716 goto err; |
15757 goto err; |
15717 } |
15758 } |
15718 |
15759 |
15719 __ArrayInstPtr(result)->a_element[cnt] = resp; __STORE(result, resp); |
15760 __ArrayInstPtr(result)->a_element[cnt] = resp; __STORE(result, resp); |
15720 |
15761 |
15721 __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(infop->ai_flags); |
15762 __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(infop->ai_flags); |
15722 __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(infop->ai_family); |
15763 __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(infop->ai_family); |
15723 __ArrayInstPtr(resp)->a_element[2] = __mkSmallInteger(infop->ai_socktype); |
15764 __ArrayInstPtr(resp)->a_element[2] = __mkSmallInteger(infop->ai_socktype); |
15724 __ArrayInstPtr(resp)->a_element[3] = __mkSmallInteger(infop->ai_protocol); |
15765 __ArrayInstPtr(resp)->a_element[3] = __mkSmallInteger(infop->ai_protocol); |
15725 |
15766 |
15726 __PROTECT__(resp); |
15767 __PROTECT__(resp); |
15727 o = __BYTEARRAY_NEW_INT(infop->ai_addrlen); |
15768 o = __BYTEARRAY_NEW_INT(infop->ai_addrlen); |
15728 __UNPROTECT__(resp); |
15769 __UNPROTECT__(resp); |
15729 if (o == nil) { |
15770 if (o == nil) { |
15730 error = @symbol(allocationFailure); |
15771 error = @symbol(allocationFailure); |
15731 goto err; |
15772 goto err; |
15732 } |
15773 } |
15733 memcpy(__byteArrayVal(o), infop->ai_addr, infop->ai_addrlen); |
15774 memcpy(__byteArrayVal(o), infop->ai_addr, infop->ai_addrlen); |
15734 __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o); |
15775 __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o); |
15735 |
15776 |
15736 if (infop->ai_canonname) { |
15777 if (infop->ai_canonname) { |
15737 __PROTECT__(resp); |
15778 __PROTECT__(resp); |
15738 o = __MKSTRING(infop->ai_canonname); |
15779 o = __MKSTRING(infop->ai_canonname); |
15739 __UNPROTECT__(resp); |
15780 __UNPROTECT__(resp); |
15740 if (o == nil) { |
15781 if (o == nil) { |
15741 error = @symbol(allocationFailure); |
15782 error = @symbol(allocationFailure); |
15742 goto err; |
15783 goto err; |
15743 } |
15784 } |
15744 __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); |
15785 __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); |
15745 } |
15786 } |
15746 } |
15787 } |
15747 |
15788 |
15748 err: |
15789 err: |
15749 if (info) freeaddrinfo(info); |
15790 if (info) freeaddrinfo(info); |
15750 |
15791 |
15757 char **addrpp; |
15798 char **addrpp; |
15758 int __port = 0; |
15799 int __port = 0; |
15759 int i; |
15800 int i; |
15760 |
15801 |
15761 if (__isSmallInteger(port)) { |
15802 if (__isSmallInteger(port)) { |
15762 __port = htons(__smallIntegerVal(port)); |
15803 __port = htons(__smallIntegerVal(port)); |
15763 } else if (__serviceName) { |
15804 } else if (__serviceName) { |
15764 struct servent *sp; |
15805 struct servent *sp; |
15765 char *__proto = 0; |
15806 char *__proto = 0; |
15766 |
15807 |
15767 if (__isStringLike(protoArg)) |
15808 if (__isStringLike(protoArg)) |
15768 __proto = __stringVal(protoArg); |
15809 __proto = __stringVal(protoArg); |
15769 |
15810 |
15770 sp = getservbyname(__serviceName, __proto); |
15811 sp = getservbyname(__serviceName, __proto); |
15771 if (sp == NULL) { |
15812 if (sp == NULL) { |
15772 __port = atoi(__serviceName); |
15813 __port = atoi(__serviceName); |
15773 if (__port <= 0) { |
15814 if (__port <= 0) { |
15774 errorString = @symbol(unknownService); |
15815 errorString = @symbol(unknownService); |
15775 error = __mkSmallInteger(-3); |
15816 error = __mkSmallInteger(-3); |
15776 goto err; |
15817 goto err; |
15777 } |
15818 } |
15778 __port = htons(__port); |
15819 __port = htons(__port); |
15779 } else |
15820 } else |
15780 __port = sp->s_port; |
15821 __port = sp->s_port; |
15781 } |
15822 } |
15782 |
15823 |
15783 if (__hostName) { |
15824 if (__hostName) { |
15784 # ifdef USE_H_ERRNO |
15825 # ifdef USE_H_ERRNO |
15785 do { |
15826 do { |
15786 /* must refetch in loop */ |
15827 /* must refetch in loop */ |
15787 if (hostName == nil) { |
15828 if (hostName == nil) { |
15788 __hostName = 0; |
15829 __hostName = 0; |
15789 } else if (__isStringLike(hostName)) { |
15830 } else if (__isStringLike(hostName)) { |
15790 __hostName = __stringVal(hostName); |
15831 __hostName = __stringVal(hostName); |
15791 } |
15832 } |
15792 # ifdef DO_WRAP_CALLS |
15833 # ifdef DO_WRAP_CALLS |
15793 hp = STX_WSA_NOINT_CALL1("gethostbyname", gethostbyname, __hostName); |
15834 hp = STX_WSA_NOINT_CALL1("gethostbyname", gethostbyname, __hostName); |
15794 if ((INT)hp < 0) hp = NULL; |
15835 if ((INT)hp < 0) hp = NULL; |
15795 # else |
15836 # else |
15796 /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname |
15837 /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname |
15797 * uses a static data area |
15838 * uses a static data area |
15798 */ |
15839 */ |
15799 __BEGIN_INTERRUPTABLE__ |
15840 __BEGIN_INTERRUPTABLE__ |
15800 hp = gethostbyname(__hostName); |
15841 hp = gethostbyname(__hostName); |
15801 __END_INTERRUPTABLE__ |
15842 __END_INTERRUPTABLE__ |
15802 #endif |
15843 #endif |
15803 } while ((hp == NULL) |
15844 } while ((hp == NULL) |
15804 && ( |
15845 && ( |
15805 (h_errno == TRY_AGAIN) |
15846 (h_errno == TRY_AGAIN) |
15806 || errno == EINTR |
15847 || errno == EINTR |
15807 # ifdef IRIX5_3 |
15848 # ifdef IRIX5_3 |
15808 || (errno == ECONNREFUSED) |
15849 || (errno == ECONNREFUSED) |
15809 # endif |
15850 # endif |
15810 ) |
15851 ) |
15811 ); |
15852 ); |
15812 if (hp == 0) { |
15853 if (hp == 0) { |
15813 switch (h_errno) { |
15854 switch (h_errno) { |
15814 case HOST_NOT_FOUND: |
15855 case HOST_NOT_FOUND: |
15815 errorString = @symbol(unknownHost); |
15856 errorString = @symbol(unknownHost); |
15816 break; |
15857 break; |
15817 case NO_ADDRESS: |
15858 case NO_ADDRESS: |
15818 errorString = @symbol(noAddress); |
15859 errorString = @symbol(noAddress); |
15819 break; |
15860 break; |
15820 case NO_RECOVERY: |
15861 case NO_RECOVERY: |
15821 errorString = @symbol(permanentFailure); |
15862 errorString = @symbol(permanentFailure); |
15822 break; |
15863 break; |
15823 case TRY_AGAIN: |
15864 case TRY_AGAIN: |
15824 errorString = @symbol(tryAgain); |
15865 errorString = @symbol(tryAgain); |
15825 break; |
15866 break; |
15826 default: |
15867 default: |
15827 errorString = @symbol(unknownError); |
15868 errorString = @symbol(unknownError); |
15828 break; |
15869 break; |
15829 } |
15870 } |
15830 error = __mkSmallInteger(h_errno); |
15871 error = __mkSmallInteger(h_errno); |
15831 goto err; |
15872 goto err; |
15832 } |
15873 } |
15833 # else /* !USE_H_ERRNO */ |
15874 # else /* !USE_H_ERRNO */ |
15834 hp = gethostbyname(__hostName); |
15875 hp = gethostbyname(__hostName); |
15835 if (hp == 0) { |
15876 if (hp == 0) { |
15836 errorString = @symbol(unknownHost); |
15877 errorString = @symbol(unknownHost); |
15837 error = __mkSmallInteger(-1); |
15878 error = __mkSmallInteger(-1); |
15838 goto err; |
15879 goto err; |
15839 } |
15880 } |
15840 # endif /* !USE_H_ERRNO*/ |
15881 # endif /* !USE_H_ERRNO*/ |
15841 |
15882 |
15842 if (__isSmallInteger(domain) && hp->h_addrtype != __smallIntegerVal(domain)) { |
15883 if (__isSmallInteger(domain) && hp->h_addrtype != __smallIntegerVal(domain)) { |
15843 errorString = @symbol(unknownHost); |
15884 errorString = @symbol(unknownHost); |
15844 error = __mkSmallInteger(-2); |
15885 error = __mkSmallInteger(-2); |
15845 goto err; |
15886 goto err; |
15846 } |
15887 } |
15847 |
15888 |
15848 for (cnt = 0, addrpp = hp->h_addr_list; *addrpp; addrpp++) |
15889 for (cnt = 0, addrpp = hp->h_addr_list; *addrpp; addrpp++) |
15849 cnt++; |
15890 cnt++; |
15850 addrpp = hp->h_addr_list; |
15891 addrpp = hp->h_addr_list; |
15851 } else { |
15892 } else { |
15852 cnt = 1; |
15893 cnt = 1; |
15853 } |
15894 } |
15854 |
15895 |
15855 result = __ARRAY_NEW_INT(cnt); |
15896 result = __ARRAY_NEW_INT(cnt); |
15856 if (result == nil) { |
15897 if (result == nil) { |
15857 error = @symbol(allocationFailure); |
15898 error = @symbol(allocationFailure); |
15858 goto err; |
15899 goto err; |
15859 } |
15900 } |
15860 |
15901 |
15861 for (i = 0; i < cnt; i++) { |
15902 for (i = 0; i < cnt; i++) { |
15862 OBJ o, resp; |
15903 OBJ o, resp; |
15863 struct sockaddr_in *sa; |
15904 struct sockaddr_in *sa; |
15864 |
15905 |
15865 resp = __ARRAY_NEW_INT(6); |
15906 resp = __ARRAY_NEW_INT(6); |
15866 if (resp == nil) { |
15907 if (resp == nil) { |
15867 error = @symbol(allocationFailure); |
15908 error = @symbol(allocationFailure); |
15868 goto err; |
15909 goto err; |
15869 } |
15910 } |
15870 |
15911 |
15871 __ArrayInstPtr(result)->a_element[i] = resp; __STORE(result, resp); |
15912 __ArrayInstPtr(result)->a_element[i] = resp; __STORE(result, resp); |
15872 __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(0); |
15913 __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(0); |
15873 __ArrayInstPtr(resp)->a_element[2] = type; __STORE(result, type); |
15914 __ArrayInstPtr(resp)->a_element[2] = type; __STORE(result, type); |
15874 __ArrayInstPtr(resp)->a_element[3] = proto; __STORE(result, proto); |
15915 __ArrayInstPtr(resp)->a_element[3] = proto; __STORE(result, proto); |
15875 __PROTECT__(resp); |
15916 __PROTECT__(resp); |
15876 o = __BYTEARRAY_NEW_INT(sizeof(*sa)); |
15917 o = __BYTEARRAY_NEW_INT(sizeof(*sa)); |
15877 __UNPROTECT__(resp); |
15918 __UNPROTECT__(resp); |
15878 if (o == nil) { |
15919 if (o == nil) { |
15879 error = @symbol(allocationFailure); |
15920 error = @symbol(allocationFailure); |
15880 goto err; |
15921 goto err; |
15881 } |
15922 } |
15882 __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o); |
15923 __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o); |
15883 sa = (struct sockaddr_in *)__byteArrayVal(o); |
15924 sa = (struct sockaddr_in *)__byteArrayVal(o); |
15884 sa->sin_port = __port; |
15925 sa->sin_port = __port; |
15885 |
15926 |
15886 if (__hostName) { |
15927 if (__hostName) { |
15887 sa->sin_family = hp->h_addrtype; |
15928 sa->sin_family = hp->h_addrtype; |
15888 memcpy(&sa->sin_addr, *addrpp, hp->h_length); |
15929 memcpy(&sa->sin_addr, *addrpp, hp->h_length); |
15889 __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(hp->h_addrtype); |
15930 __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(hp->h_addrtype); |
15890 if (hp->h_name) { |
15931 if (hp->h_name) { |
15891 __PROTECT__(resp); |
15932 __PROTECT__(resp); |
15892 o = __MKSTRING(hp->h_name); |
15933 o = __MKSTRING(hp->h_name); |
15893 __UNPROTECT__(resp); |
15934 __UNPROTECT__(resp); |
15894 if (o == nil) { |
15935 if (o == nil) { |
15895 error = @symbol(allocationFailure); |
15936 error = @symbol(allocationFailure); |
15896 goto err; |
15937 goto err; |
15897 } |
15938 } |
15898 __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); |
15939 __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); |
15899 } |
15940 } |
15900 addrpp++; |
15941 addrpp++; |
15901 } else{ |
15942 } else{ |
15902 __ArrayInstPtr(resp)->a_element[1] = domain; __STORE(resp, domain); |
15943 __ArrayInstPtr(resp)->a_element[1] = domain; __STORE(resp, domain); |
15903 } |
15944 } |
15904 } |
15945 } |
15905 |
15946 |
15906 err:; |
15947 err:; |
15907 # endif /* ! AI_NUMERICHOST */ |
15948 # endif /* ! AI_NUMERICHOST */ |
15908 } |
15949 } |
15910 error = @symbol(notImplemented); |
15951 error = @symbol(notImplemented); |
15911 #endif |
15952 #endif |
15912 exitPrim:; |
15953 exitPrim:; |
15913 %}. |
15954 %}. |
15914 error notNil ifTrue:[ |
15955 error notNil ifTrue:[ |
15915 |request| |
15956 |request| |
15916 request := SocketAddressInfo new |
15957 request := SocketAddressInfo new |
15917 domain:domainArg; |
15958 domain:domainArg; |
15918 type:typeArg; |
15959 type:typeArg; |
15919 protocol:protoArg; |
15960 protocol:protoArg; |
15920 canonicalName:hostName; |
15961 canonicalName:hostName; |
15921 serviceName:serviceName. |
15962 serviceName:serviceName. |
15922 ^ (HostNameLookupError new |
15963 ^ (HostNameLookupError new |
15923 parameter:error; |
15964 parameter:error; |
15924 messageText:' - ', (errorString ? error printString); |
15965 messageText:' - ', (errorString ? error printString); |
15925 request:request) raiseRequest. |
15966 request:request) raiseRequest. |
15926 ]. |
15967 ]. |
15927 1 to:result size do:[:i | |
15968 1 to:result size do:[:i | |
15928 |entry dom info| |
15969 |entry dom info| |
15929 |
15970 |
15930 info := SocketAddressInfo new. |
15971 info := SocketAddressInfo new. |
15931 entry := result at:i. |
15972 entry := result at:i. |
15932 info flags:(entry at:1). |
15973 info flags:(entry at:1). |
15933 info domain:(dom := OperatingSystem domainSymbolOf:(entry at:2)). |
15974 info domain:(dom := OperatingSystem domainSymbolOf:(entry at:2)). |
15934 info type:(OperatingSystem socketTypeSymbolOf:(entry at:3)). |
15975 info type:(OperatingSystem socketTypeSymbolOf:(entry at:3)). |
15935 info protocol:(self protocolSymbolOf:(entry at:4)). |
15976 info protocol:(self protocolSymbolOf:(entry at:4)). |
15936 info socketAddress:((SocketAddress newDomain:dom) fromBytes:(entry at:5)). |
15977 info socketAddress:((SocketAddress newDomain:dom) fromBytes:(entry at:5)). |
15937 info canonicalName:(entry at:6). |
15978 info canonicalName:(entry at:6). |
15938 result at:i put:info |
15979 result at:i put:info |
15939 ]. |
15980 ]. |
15940 ^ result |
15981 ^ result |
15941 |
15982 |
15942 " |
15983 " |
15943 self getAddressInfo:'localhost' serviceName:nil |
15984 self getAddressInfo:'localhost' serviceName:nil |
15944 domain:nil type:nil protocol:nil flags:nil |
15985 domain:nil type:nil protocol:nil flags:nil |
15945 self getAddressInfo:'localhost' serviceName:nil |
15986 self getAddressInfo:'localhost' serviceName:nil |
15946 domain:#inet type:#stream protocol:nil flags:nil |
15987 domain:#inet type:#stream protocol:nil flags:nil |
15947 self getAddressInfo:'localhost' serviceName:nil |
15988 self getAddressInfo:'localhost' serviceName:nil |
15948 domain:#inet type:#stream protocol:#tcp flags:nil |
15989 domain:#inet type:#stream protocol:#tcp flags:nil |
15949 self getAddressInfo:'localhost' serviceName:10 |
15990 self getAddressInfo:'localhost' serviceName:10 |
15950 domain:#inet type:#stream protocol:#tcp flags:nil |
15991 domain:#inet type:#stream protocol:#tcp flags:nil |
15951 self getAddressInfo:'localhost' serviceName:'10' |
15992 self getAddressInfo:'localhost' serviceName:'10' |
15952 domain:#inet type:#stream protocol:#tcp flags:nil |
15993 domain:#inet type:#stream protocol:#tcp flags:nil |
15953 self getAddressInfo:'blurb.exept.de' serviceName:nil |
15994 self getAddressInfo:'blurb.exept.de' serviceName:nil |
15954 domain:#inet type:nil protocol:nil flags:nil |
15995 domain:#inet type:nil protocol:nil flags:nil |
15955 self getAddressInfo:'1.2.3.4' serviceName:'bla' |
15996 self getAddressInfo:'1.2.3.4' serviceName:'bla' |
15956 domain:#inet type:nil protocol:nil flags:nil |
15997 domain:#inet type:nil protocol:nil flags:nil |
15957 self getAddressInfo:'localhost' serviceName:'echo' |
15998 self getAddressInfo:'localhost' serviceName:'echo' |
15958 domain:#inet type:nil protocol:nil flags:nil |
15999 domain:#inet type:nil protocol:nil flags:nil |
15959 self getAddressInfo:nil serviceName:'echo' |
16000 self getAddressInfo:nil serviceName:'echo' |
15960 domain:#inet type:nil protocol:nil flags:nil |
16001 domain:#inet type:nil protocol:nil flags:nil |
15961 self getAddressInfo:nil serviceName:nil |
16002 self getAddressInfo:nil serviceName:nil |
15962 domain:#inet type:nil protocol:nil flags:nil |
16003 domain:#inet type:nil protocol:nil flags:nil |
15963 self getAddressInfo:'www.google.de' serviceName:nil |
16004 self getAddressInfo:'www.google.de' serviceName:nil |
15964 domain:nil type:nil protocol:nil flags:nil |
16005 domain:nil type:nil protocol:nil flags:nil |
15965 self getAddressInfo:'smc1' serviceName:nil |
16006 self getAddressInfo:'smc1' serviceName:nil |
15966 domain:nil type:nil protocol:nil flags:nil |
16007 domain:nil type:nil protocol:nil flags:nil |
15967 " |
16008 " |
15968 ! |
16009 ! |
15969 |
16010 |
15970 getNameInfo:socketAddress wantHostName:wantHostName wantServiceName:wantServiceName datagram:useDatagram flags:flags |
16011 getNameInfo:socketAddress wantHostName:wantHostName wantServiceName:wantServiceName datagram:useDatagram flags:flags |
15971 "answer an Array containing the hostName and serviceName |
16012 "answer an Array containing the hostName and serviceName |