UnixFileDescriptorHandle.st
branchjv
changeset 18011 deb0c3355881
parent 17911 a99f15c5efa5
parent 14667 f6a830b971f3
child 18120 e3a375d5f6a8
--- a/UnixFileDescriptorHandle.st	Thu Dec 20 11:48:59 2012 +0000
+++ b/UnixFileDescriptorHandle.st	Sat Jan 19 01:30:00 2013 +0000
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1999 by eXept Software AG
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -9,6 +9,7 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
+
 "{ Package: 'stx:libbasic' }"
 
 OSFileHandle subclass:#UnixFileDescriptorHandle
@@ -31,7 +32,7 @@
 copyright
 "
  COPYRIGHT (c) 1999 by eXept Software AG
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -56,85 +57,86 @@
     int nInstBytes, objSize;
 
     if (! __bothSmallInteger(count, firstIndex)) {
-        goto bad;
+	goto bad;
     }
     cnt = __smallIntegerVal(count);
     offs = __smallIntegerVal(firstIndex) - 1;
 
     if (fd < 0) {
-        goto bad;
+	goto bad;
     }
     if (__isExternalBytesLike(aByteBuffer)) {
-        OBJ sz;
+	OBJ sz;
 
-        nInstBytes = 0;
-        extPtr = (char *)(__externalBytesAddress(aByteBuffer));
-        sz = __externalBytesSize(aByteBuffer);
-        if (__isSmallInteger(sz)) {
-            objSize = __smallIntegerVal(sz);
-        } else {
-            objSize = -1; /* unknown */
-        }
+	nInstBytes = 0;
+	extPtr = (char *)(__externalBytesAddress(aByteBuffer));
+	if (extPtr == NULL) goto bad;
+	sz = __externalBytesSize(aByteBuffer);
+	if (__isSmallInteger(sz)) {
+	    objSize = __smallIntegerVal(sz);
+	} else {
+	    objSize = -1; /* unknown */
+	}
     } else {
-        OBJ oClass;
-        int nInstVars;
+	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 *)0;
-        nInstVars = __smallIntegerVal(__ClassInstPtr(oClass)->c_ninstvars);
-        nInstBytes = __OBJS2BYTES__(nInstVars);
-        objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
+	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 *)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;
+	nRead = 0;
 
-        do {
-            int n;
+	do {
+	    int n;
 
-            if (extPtr) {
-                n = read(fd, extPtr+offs, cnt);
-            } else {
-                char *bp;
+	    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;
+		/*
+		 * 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);
+		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));
+	RETURN (__mkSmallInteger(nRead));
     }
-bad: ;   
+bad: ;
 %}.
     ^ self primitiveFailed
 
@@ -161,85 +163,86 @@
     int nInstBytes, objSize;
 
     if (! __bothSmallInteger(count, firstIndex)) {
-        goto bad;
+	goto bad;
     }
     cnt = __smallIntegerVal(count);
     offs = __smallIntegerVal(firstIndex) - 1;
 
     if (fd < 0) {
-        goto bad;
+	goto bad;
     }
     if (__isExternalBytesLike(aByteBuffer)) {
-        OBJ sz;
+	OBJ sz;
 
-        nInstBytes = 0;
-        extPtr = (char *)(__externalBytesAddress(aByteBuffer));
-        sz = __externalBytesSize(aByteBuffer);
-        if (__isSmallInteger(sz)) {
-            objSize = __smallIntegerVal(sz);
-        } else {
-            objSize = -1; /* unknown */
-        }
+	nInstBytes = 0;
+	extPtr = (char *)(__externalBytesAddress(aByteBuffer));
+	if (extPtr == NULL) goto bad;
+	sz = __externalBytesSize(aByteBuffer);
+	if (__isSmallInteger(sz)) {
+	    objSize = __smallIntegerVal(sz);
+	} else {
+	    objSize = -1; /* unknown */
+	}
     } else {
-        OBJ oClass;
-        int nInstVars;
+	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 *)0;
-        nInstVars = __smallIntegerVal(__ClassInstPtr(oClass)->c_ninstvars);
-        nInstBytes = __OBJS2BYTES__(nInstVars);
-        objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
+	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 *)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;
+	nWritten = 0;
 
-        do {
-            int n;
+	do {
+	    int n;
 
-            if (extPtr) {
-                n = write(fd, extPtr+offs, cnt);
-            } else {
-                char *bp;
+	    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;
+		/*
+		 * 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);
+		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));
+	RETURN (__mkSmallInteger(nWritten));
     }
-bad: ;   
+bad: ;
 %}.
     ^ self primitiveFailed
 
@@ -259,7 +262,7 @@
 
 %{
     if (__isSmallInteger(anInteger)) {
-        __externalAddressVal(self) = (OBJ)(__smallIntegerVal(anInteger));
+	__externalAddressVal(self) = (OBJ)(__smallIntegerVal(anInteger));
     }
 %}
 
@@ -275,8 +278,8 @@
     INT fd = (INT)(__externalAddressVal(self));
 
     if (fd > 0) {
-        __externalAddressVal(self) = (OBJ)-1;
-        close(fd);
+	__externalAddressVal(self) = (OBJ)-1;
+	close(fd);
     }
 %}.
 
@@ -285,12 +288,5 @@
 !UnixFileDescriptorHandle class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UnixFileDescriptorHandle.st,v 1.8 2003/08/30 12:37:09 cg Exp $'
-!
-
-version_SVN
-    ^ '$Id: UnixFileDescriptorHandle.st 10761 2012-01-19 11:46:00Z vranyj1 $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UnixFileDescriptorHandle.st,v 1.9 2013-01-17 22:37:55 cg Exp $'
 ! !
-
-
-