*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Tue, 11 Dec 2001 21:13:22 +0100
changeset 6304 c51a3d81ba5b
parent 6303 ef753226450d
child 6305 53b87502fc21
*** empty log message ***
Win32OperatingSystem.st
--- a/Win32OperatingSystem.st	Tue Dec 11 21:11:46 2001 +0100
+++ b/Win32OperatingSystem.st	Tue Dec 11 21:13:22 2001 +0100
@@ -1163,7 +1163,7 @@
 
             case ERROR_PATH_NOT_FOUND:
                 sym = @symbol(ERROR_PATH_NOT_FOUND);
-                typ = @symbol(unavailableReferentSignal);
+                typ = @symbol(nonexistentSignal);
                 break;
 
             case ERROR_TOO_MANY_OPEN_FILES:
@@ -3243,7 +3243,7 @@
         __externalAddressVal(fileHandle) = (void *)h;  
     } else {
         fileHandle = nil;
-        errorNumber = __MKSMALLINT( __WIN32_ERR(GetLastError()) );
+        errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
     }
 
 badArgument: ;
@@ -3277,7 +3277,7 @@
 !
 
 openFileForWrite:pathName
-     ^ self openFile:pathName attributes:#(#'GENERIC_WRITE')
+     ^ self openFile:pathName attributes:#(#'GENERIC_WRITE' #'OPEN_EXISTING')
 !
 
 recursiveCopyDirectory:sourcePathName to:destination
@@ -8532,7 +8532,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.103 2001-12-11 18:43:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.104 2001-12-11 20:13:22 cg Exp $'
 ! !
 
 !Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
@@ -8559,7 +8559,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.103 2001-12-11 18:43:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.104 2001-12-11 20:13:22 cg Exp $'
 ! !
 
 !Win32OperatingSystem::Win32Handle methodsFor:'io'!
@@ -8568,104 +8568,65 @@
     "read count bytes into a byte-buffer;
      Return the number of bytes read (negative on error)"
 
+    |errSym errorNumber|
+
 %{
-#if 0
     unsigned char *extPtr;
     int nRead = -1;
-    INT fd = (INT)(__externalAddressVal(self));
-    INT cnt, offs;
-    int nInstBytes, objSize;
-
-    if (! __bothSmallInteger(count, firstIndex)) {
+    HANDLE hFile = (HANDLE)(__externalAddressVal(self));
+    DWORD cntWanted, offs, cntRead;
+    int bufferSize;
+    OBJ sz;
+
+    if ((hFile == 0) || (hFile == INVALID_HANDLE_VALUE)) {
+        errSym = @symbol(errorNotOpen);
         goto bad;
     }
-    cnt = __smallIntegerVal(count);
+    if (! __bothSmallInteger(count, firstIndex)) {
+        errSym = @symbol(badArgument);
+        goto bad;
+    }
+    cntWanted = __smallIntegerVal(count);
     offs = __smallIntegerVal(firstIndex) - 1;
 
-    if (fd < 0) {
+    if (! __isExternalBytes(aByteBuffer)) {
+        errSym = @symbol(badBuffer);
         goto bad;
     }
-    if (__isExternalBytes(aByteBuffer)) {
-        OBJ sz;
-
-        nInstBytes = 0;
-        extPtr = (char *)(__externalBytesAddress(aByteBuffer));
-        sz = __externalBytesSize(aByteBuffer);
-        if (__isSmallInteger(sz)) {
-            objSize = __smallIntegerVal(sz);
-        } else {
-            objSize = -1; /* unknown */
-        }
-    } else {
-        OBJ oClass;
-        int nInstVars;
-
-        oClass = __Class(aByteBuffer);
-        switch (__smallIntegerVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-            case BYTEARRAY:
-            case WORDARRAY:
-            case LONGARRAY:
-            case SWORDARRAY:
-            case SLONGARRAY:
-            case FLOATARRAY:
-            case DOUBLEARRAY:
-                break;
-            default:
-                goto bad;
+        
+    extPtr = (char *)(__externalBytesAddress(aByteBuffer));
+    sz = __externalBytesSize(aByteBuffer);
+    if (! __isSmallInteger(sz)) {
+        errSym = @symbol(badBufferSize);
+        goto bad;
+    }
+    bufferSize = __smallIntegerVal(sz);
+
+    if ((offs >= 0)
+     && (cntWanted >= 0)
+     && (bufferSize >= (cntWanted + offs))) {
+        BOOL ok;
+
+        ok = ReadFile(hFile, extPtr+offs, cntWanted, &cntRead, 0 /* lpOverlapped */);
+        if (ok == TRUE) {
+            RETURN (__mkSmallInteger(cntRead));
         }
-        extPtr = (char *)0;
-        nInstVars = __smallIntegerVal(__ClassInstPtr(oClass)->c_ninstvars);
-        nInstBytes = __OBJS2BYTES__(nInstVars);
-        objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
-    }
-    if ((offs >= 0)
-     && (cnt >= 0)
-     && ((objSize == -1) || (objSize >= (cnt + offs)))) {
-        nRead = 0;
-
-        do {
-            int n;
-
-            if (extPtr) {
-                n = read(fd, extPtr+offs, cnt);
-            } else {
-                char *bp;
-
-                /*
-                 * on interrupt, anObject may be moved to another location.
-                 * So we recompute the byte-address here.
-                 */
-                bp = __ByteArrayInstPtr(aByteBuffer)->ba_element + nInstBytes;
-
-                n = read(fd, bp + offs, cnt);
-            }
-            if (n > 0) {
-                cnt -= n;
-                offs += n;
-                nRead += n;
-            } else {
-                if (n < 0) {
-                    if (errno == EINTR) {
-                        continue;
-                    }
-                    break;
-                }
-            }
-        } while (cnt > 0);
-
-        RETURN (__mkSmallInteger(nRead));
+        errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
     }
 bad: ;   
-#endif
 %}.
-    ^ self primitiveFailed
+
+    errorNumber isNil ifTrue:[
+        self error:'invalid argument(s): ', errSym.
+    ] ifFalse:[
+        (OperatingSystem errorHolderForNumber:errorNumber) reportError
+    ].
 
     "
      |h buff n|
 
      h := self basicNew.
-     h setFileDescriptor:0.
-     buff := ByteArray new:10. buff inspect.
+     buff := ByteArray new:10. 
      n := h readBytes:10 into:buff startingAt:1.
      Transcript show:n; space; showCR:buff.
     "
@@ -8675,97 +8636,56 @@
     "write count bytes from a byte-buffer;
      Return the number of bytes written (negative on error)"
 
+    |errSym errorNumber|
 %{
-#if 0
     unsigned char *extPtr;
     int nWritten = -1;
-    INT fd = (INT)(__externalAddressVal(self));
-    INT cnt, offs;
-    int nInstBytes, objSize;
-
-    if (! __bothSmallInteger(count, firstIndex)) {
+    HANDLE hFile = (HANDLE)(__externalAddressVal(self));
+    DWORD cntWanted, offs, cntWritten;
+    int bufferSize;
+
+    if ((hFile == 0) || (hFile == INVALID_HANDLE_VALUE)) {
+        errSym = @symbol(errorNotOpen);
         goto bad;
     }
-    cnt = __smallIntegerVal(count);
+    if (! __bothSmallInteger(count, firstIndex)) {
+        errSym = @symbol(badArgument);
+        goto bad;
+    }
+    cntWanted = __smallIntegerVal(count);
     offs = __smallIntegerVal(firstIndex) - 1;
 
-    if (fd < 0) {
+    if (! __isExternalBytes(aByteBuffer)) {
+        errSym = @symbol(badBuffer);
         goto bad;
     }
-    if (__isExternalBytes(aByteBuffer)) {
-        OBJ sz;
-
-        nInstBytes = 0;
-        extPtr = (char *)(__externalBytesAddress(aByteBuffer));
-        sz = __externalBytesSize(aByteBuffer);
-        if (__isSmallInteger(sz)) {
-            objSize = __smallIntegerVal(sz);
-        } else {
-            objSize = -1; /* unknown */
-        }
-    } else {
-        OBJ oClass;
-        int nInstVars;
-
-        oClass = __Class(aByteBuffer);
-        switch (__smallIntegerVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-            case BYTEARRAY:
-            case WORDARRAY:
-            case LONGARRAY:
-            case SWORDARRAY:
-            case SLONGARRAY:
-            case FLOATARRAY:
-            case DOUBLEARRAY:
-                break;
-            default:
-                goto bad;
+
+    extPtr = (char *)(__externalBytesAddress(aByteBuffer));
+    bufferSize = __externalBytesSize(aByteBuffer);
+    if (! __isSmallInteger(bufferSize)) {
+        errSym = @symbol(badBufferSize);
+        goto bad;
+    }
+    bufferSize = __smallIntegerVal(bufferSize);
+
+    if ((offs >= 0)
+     && (cntWanted >= 0)
+     && (bufferSize >= (cntWanted + offs))) {
+        BOOL ok;
+
+        ok = WriteFile(hFile, extPtr+offs, cntWanted, &cntWritten, 0 /* lpOverlapped */);
+        if (ok == TRUE) {
+            RETURN (__mkSmallInteger(cntWritten));
         }
-        extPtr = (char *)0;
-        nInstVars = __smallIntegerVal(__ClassInstPtr(oClass)->c_ninstvars);
-        nInstBytes = __OBJS2BYTES__(nInstVars);
-        objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
-    }
-    if ((offs >= 0)
-     && (cnt >= 0)
-     && ((objSize == -1) || (objSize >= (cnt + offs)))) {
-        nWritten = 0;
-
-        do {
-            int n;
-
-            if (extPtr) {
-                n = write(fd, extPtr+offs, cnt);
-            } else {
-                char *bp;
-
-                /*
-                 * on interrupt, anObject may be moved to another location.
-                 * So we recompute the byte-address here.
-                 */
-                bp = __ByteArrayInstPtr(aByteBuffer)->ba_element + nInstBytes;
-
-                n = write(fd, bp + offs, cnt);
-            }
-            if (n > 0) {
-                cnt -= n;
-                offs += n;
-                nWritten += n;
-            } else {
-                if (n < 0) {
-                    if (errno == EINTR) {
-                        continue;
-                    }
-                    break;
-                }
-            }
-        } while (cnt > 0);
-
-        RETURN (__mkSmallInteger(nWritten));
+        errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
     }
 bad: ;   
-#endif
 %}.
-    ^ self primitiveFailed
+    errorNumber isNil ifTrue:[
+        self error:'invalid argument(s): ', errSym.
+    ] ifFalse:[
+        (OperatingSystem errorHolderForNumber:errorNumber) reportError
+    ].
 
     "
      |h buff n|
@@ -8801,6 +8721,6 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.103 2001-12-11 18:43:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.104 2001-12-11 20:13:22 cg Exp $'
 ! !
 Win32OperatingSystem initialize!