OSFileHandle.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 23877 ab9bfa0f06bb
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23877
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
     1
"{ Encoding: utf8 }"
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
     2
7593
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
     3
"
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
     4
 COPYRIGHT (c) 1999 by eXept Software AG
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
     5
              All Rights Reserved
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
     6
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
     7
 This software is furnished under a license and may be used
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
     8
 only in accordance with the terms of that license and with the
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    10
 be provided or otherwise made available to, or used by, any
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    11
 other person.  No title to or ownership of the software is
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    12
 hereby transferred.
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    13
"
5409
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
    14
"{ Package: 'stx:libbasic' }"
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
    15
23877
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
    16
"{ NameSpace: Smalltalk }"
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
    17
4763
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
OSHandle subclass:#OSFileHandle
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:'ConcreteClass'
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'System-Support'
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
7593
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    25
!OSFileHandle class methodsFor:'documentation'!
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    26
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    27
copyright
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    28
"
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    29
 COPYRIGHT (c) 1999 by eXept Software AG
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    30
              All Rights Reserved
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    31
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    32
 This software is furnished under a license and may be used
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    33
 only in accordance with the terms of that license and with the
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    35
 be provided or otherwise made available to, or used by, any
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    36
 other person.  No title to or ownership of the software is
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    37
 hereby transferred.
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    38
"
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
    39
! !
4763
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
!OSFileHandle class methodsFor:'initialization'!
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
initialize
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    "initialize for the OS we are running on"
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    self initializeConcreteClass
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    "
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
     self initialize
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    "
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
!
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
initializeConcreteClass
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    "initialize for the OS we are running on"
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    OperatingSystem isMSDOSlike ifTrue:[
6289
82cf5f13d5d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5413
diff changeset
    59
        ConcreteClass := Win32FILEHandle
4763
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    ] ifFalse:[
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
        OperatingSystem isVMSlike ifTrue:[
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
            ConcreteClass := OpenVMSFileHandle
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
        ] ifFalse:[
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
            OperatingSystem isUNIXlike ifTrue:[
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
                ConcreteClass := UnixFileHandle
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
            ] ifFalse:[
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
                ConcreteClass := nil
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
            ]
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
        ]
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    ]
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    "
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
     self initializeConcreteClass
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    "
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    "Modified: 7.9.1997 / 23:32:37 / cg"
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
!
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
reinitialize
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    "initialize for the OS we are running on"
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    self initializeConcreteClass
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    "
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
     self reinitialize
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    "
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
! !
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
!OSFileHandle methodsFor:'finalization'!
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6289
diff changeset
    94
finalize
5409
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
    95
    "a filedescriptor was garbage collected - close the underlying file"
4763
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
16549
f390a82315e7 class: OSFileHandle
Claus Gittinger <cg@exept.de>
parents: 9101
diff changeset
    97
    "/ with timeout to avoid blocking in a bad pty/socket
f390a82315e7 class: OSFileHandle
Claus Gittinger <cg@exept.de>
parents: 9101
diff changeset
    98
    [
f390a82315e7 class: OSFileHandle
Claus Gittinger <cg@exept.de>
parents: 9101
diff changeset
    99
        self closeFile
f390a82315e7 class: OSFileHandle
Claus Gittinger <cg@exept.de>
parents: 9101
diff changeset
   100
    ] valueWithTimeout:30 seconds
5409
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   101
! !
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   102
5413
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   103
!OSFileHandle methodsFor:'input/output'!
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   104
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   105
readBytes:count into:aByteBuffer startingAt:startAddress
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   106
    "read count bytes into a byte-buffer;
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   107
     Return the number of bytes read (negative on error)"
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   108
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   109
    ^ self subclassResponsibility
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   110
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   111
!
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   112
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   113
writeBytes:count from:aByteBuffer startingAt:startAddress
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   114
    "write count bytes from a byte-buffer;
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   115
     Return the number of bytes written (negative on error)"
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   116
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   117
    ^ self subclassResponsibility
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   118
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   119
! !
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   120
5409
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   121
!OSFileHandle methodsFor:'release'!
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   122
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   123
close
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   124
    "close the file"
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   125
23877
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
   126
    self unregisterForFinalization.
5409
9b5890348f9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4763
diff changeset
   127
    self closeFile.
23877
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
   128
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
   129
    "Modified: / 12-03-2019 / 22:04:11 / Claus Gittinger"
5413
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   130
!
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   131
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   132
closeFile
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   133
    "close the underlying file"
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   134
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   135
    self subclassResponsibility
4e67713bf25a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5409
diff changeset
   136
4763
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
! !
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
!OSFileHandle class methodsFor:'documentation'!
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
version
23877
ab9bfa0f06bb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 16549
diff changeset
   142
    ^ '$Header$'
4763
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
! !
7593
e7550b9ef84a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6439
diff changeset
   144
16549
f390a82315e7 class: OSFileHandle
Claus Gittinger <cg@exept.de>
parents: 9101
diff changeset
   145
4763
d15c41a66ec4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
OSFileHandle initialize!