FileStream.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 02:51:19 +0100
changeset 613 0af19c3594fc
parent 530 07d0bce293c9
child 857 867a121f68ee
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
ExternalStream subclass:#FileStream
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    14
	 instanceVariableNames:'pathName'
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    15
	 classVariableNames:''
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    16
	 poolDictionaries:''
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    17
	 category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
216
a8abff749575 *** empty log message ***
claus
parents: 173
diff changeset
    20
!FileStream primitiveDefinitions!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
#include <stdio.h>
437
claus
parents: 384
diff changeset
    23
#define _STDIO_H_INCLUDED_
claus
parents: 384
diff changeset
    24
10
claus
parents: 5
diff changeset
    25
#include <errno.h>
437
claus
parents: 384
diff changeset
    26
#define _ERRNO_H_INCLUDED_
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
#ifdef transputer
a27a279701f8 Initial revision
claus
parents:
diff changeset
    29
# include <iocntrl.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    30
# ifndef fileno
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
   /* kludge: inmos forgot fileno */
a27a279701f8 Initial revision
claus
parents:
diff changeset
    32
#  define fileno(f)     ((f)->__file)
a27a279701f8 Initial revision
claus
parents:
diff changeset
    33
# endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
    34
#else
a27a279701f8 Initial revision
claus
parents:
diff changeset
    35
# include <sys/types.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    36
# include <sys/stat.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
#endif
10
claus
parents: 5
diff changeset
    38
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    39
#ifdef hpux
68
59faa75185ba *** empty log message ***
claus
parents: 49
diff changeset
    40
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    41
#endif
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    42
10
claus
parents: 5
diff changeset
    43
#ifndef SEEK_SET
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
    44
# define SEEK_SET       0
10
claus
parents: 5
diff changeset
    45
#endif
claus
parents: 5
diff changeset
    46
#ifndef SEEK_CUR
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
    47
# define SEEK_CUR       1
10
claus
parents: 5
diff changeset
    48
#endif
claus
parents: 5
diff changeset
    49
#ifndef SEEK_END
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
    50
# define SEEK_END       2
10
claus
parents: 5
diff changeset
    51
#endif
claus
parents: 5
diff changeset
    52
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    53
/*
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    54
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    55
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    56
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    57
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    58
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    59
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    60
%}
173
58e9778954bc reposition
claus
parents: 159
diff changeset
    61
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    63
!FileStream class methodsFor:'documentation'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    64
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    65
copyright
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    66
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    67
 COPYRIGHT (c) 1989 by Claus Gittinger
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    68
	      All Rights Reserved
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    69
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
 This software is furnished under a license and may be used
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
 only in accordance with the terms of that license and with the
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
 inclusion of the above copyright notice.   This software may not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    73
 be provided or otherwise made available to, or used by, any
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    74
 other person.  No title to or ownership of the software is
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    75
 hereby transferred.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    77
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    78
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
documentation
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
    This class provides access to the operating systems underlying file
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    82
    system (i.e. its an interface to the stdio library).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
    Notice, that on some systems, the standard I/O library has performance
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    85
    problems when a file is opened for readwrite. 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    86
    For best results, open files either readonly or writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
version
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.29 1995-11-23 01:50:48 cg Exp $'
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
!FileStream class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
appendingOldFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
    "return a FileStream for existing file named filename, aString.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
     The file is opened for writeonly access."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    99
a27a279701f8 Initial revision
claus
parents:
diff changeset
   100
    |newStream|
2
claus
parents: 1
diff changeset
   101
    newStream := self new pathName:filename.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
    newStream openForAppending isNil ifTrue:[^nil].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
    this is not a good idea; I might like to read the written stuff ...
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   106
    newStream readLimit:(newStream size).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
    ^ newStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
appendingOldFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
    "return a FileStream for existing file named filename, aString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
     in aDirectory, a FileDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
     The file is opened for writeonly access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
    newStream := self new pathName:filename in:aDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
    newStream openForAppending isNil ifTrue:[^nil].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
    this is not a good idea; I might like to read the written stuff ...
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
    newStream readLimit:(newStream size).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
fileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   128
    "return a stream on file filename - if the file does not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
     already exist, create it.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   130
     The file is opened for read/write access."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   132
    |stream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   133
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   134
    stream := self oldFileNamed:filename.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   135
    stream isNil ifTrue:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   136
	stream := self newFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   137
    ].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   138
    ^ stream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   139
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   140
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   141
fileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   142
    "return a stream on file filename - if the file does not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   143
     already exist, create it.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   144
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   145
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   146
    |stream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   147
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   148
    stream := self oldFileNamed:filename in:aDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   149
    stream isNil ifTrue:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
	stream := self newFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   151
    ].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   152
    ^ stream
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   155
newFileForWritingNamed:filename
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   156
    "return a FileStream for new file named filename, aString.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   157
     If the file exists, it is truncated, otherwise created.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   158
     The file is opened for writeonly access."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   159
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   160
    |newStream|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   161
    newStream := self new pathName:filename.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   162
    newStream createForWriting isNil ifTrue:[^nil].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   163
    ^ newStream
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   164
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   165
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   166
newFileForWritingNamed:filename in:aDirectory
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   167
    "return a FileStream for new file named filename, aString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   168
     in aDirectory, a FileDirectory.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   169
     If the file exists, it is truncated, otherwise created.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   170
     The file is opened for writeonly access."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   171
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   172
    |newStream|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   173
    newStream := self new pathName:filename in:aDirectory.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   174
    newStream createForWriting isNil ifTrue:[^nil].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   175
    ^ newStream
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   176
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   177
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
newFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
    "return a FileStream for new file named filename, aString.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
     If the file exists, it is truncated, otherwise created.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   184
    newStream := self new pathName:filename.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
    newStream createForReadWrite isNil ifTrue:[^nil].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
    ^ newStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   188
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   189
newFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   190
    "return a FileStream for new file named filename, aString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
     in aDirectory, a FileDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   192
     If the file exists, it is truncated, otherwise created.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   193
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   196
    newStream := self new pathName:filename in:aDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
    newStream createForReadWrite isNil ifTrue:[^nil].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   198
    ^ newStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   199
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   201
oldFileNamed:filename
a27a279701f8 Initial revision
claus
parents:
diff changeset
   202
    "return a FileStream for existing file named filename, aString.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   203
     The file is opened for read/write access."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   204
a27a279701f8 Initial revision
claus
parents:
diff changeset
   205
    |newStream|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   206
a27a279701f8 Initial revision
claus
parents:
diff changeset
   207
    (OperatingSystem isReadable:filename) ifFalse:[^nil].
2
claus
parents: 1
diff changeset
   208
    newStream := self new pathName:filename.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   209
    newStream readwrite.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
    newStream openForReadWrite isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   211
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   212
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   213
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   214
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   215
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   216
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   217
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   218
a27a279701f8 Initial revision
claus
parents:
diff changeset
   219
oldFileNamed:filename in:aDirectory
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
    "return a FileStream for existing file named filename, aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   221
     in aDirectory, a FileDirectory.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   222
     The file is opened for read/write access."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
a27a279701f8 Initial revision
claus
parents:
diff changeset
   224
    |newStream|
2
claus
parents: 1
diff changeset
   225
    newStream := self new pathName:filename in:aDirectory.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   226
    newStream openForReadWrite isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   227
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   228
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   229
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   230
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   231
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   233
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   234
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
readonlyFileNamed:filename
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
    "return a readonly FileStream for existing file named filename, aString"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   237
a27a279701f8 Initial revision
claus
parents:
diff changeset
   238
    |newStream|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   239
a27a279701f8 Initial revision
claus
parents:
diff changeset
   240
    (OperatingSystem isReadable:filename) ifFalse:[^nil].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   241
2
claus
parents: 1
diff changeset
   242
    newStream := self new pathName:filename.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   243
    newStream openForReading isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   244
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   245
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   246
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   248
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   249
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   250
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   251
a27a279701f8 Initial revision
claus
parents:
diff changeset
   252
readonlyFileNamed:filename in:aDirectory
a27a279701f8 Initial revision
claus
parents:
diff changeset
   253
    "return a readonly FileStream for existing file named filename, aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   254
     in aDirectory, a FileDirectory"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   255
a27a279701f8 Initial revision
claus
parents:
diff changeset
   256
    |newStream|
2
claus
parents: 1
diff changeset
   257
    newStream := self new pathName:filename in:aDirectory.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   258
    newStream openForReading isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   259
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   260
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   261
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   263
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
    ^ newStream
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   265
! !
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   266
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
!FileStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   268
a27a279701f8 Initial revision
claus
parents:
diff changeset
   269
directoryName
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
    "return the name of the directory I'm in"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   271
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
    |path lastIndex index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
    path := pathName.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
    lastIndex := 0.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
    index := path indexOf:$/.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
    [index ~~ 0] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   278
	lastIndex := index.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   279
	index := path indexOf:$/ startingAt:(index + 1)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   281
    (lastIndex == 0) ifTrue:[^ '.'].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
    (lastIndex == 1) ifTrue:[^ '/'].
31
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
   283
    ^ path copyTo:(lastIndex - 1)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   285
a27a279701f8 Initial revision
claus
parents:
diff changeset
   286
name
a27a279701f8 Initial revision
claus
parents:
diff changeset
   287
    "return my name without leading direcory-path"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   288
a27a279701f8 Initial revision
claus
parents:
diff changeset
   289
    |lastIndex index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   290
a27a279701f8 Initial revision
claus
parents:
diff changeset
   291
    lastIndex := 1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
    [true] whileTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   293
	index := pathName indexOf:$/ startingAt:lastIndex.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   294
	(index == 0) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   295
	    ^ pathName copyFrom:lastIndex
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   296
	].
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   297
	lastIndex := index + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   298
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   299
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   300
a27a279701f8 Initial revision
claus
parents:
diff changeset
   301
pathName
a27a279701f8 Initial revision
claus
parents:
diff changeset
   302
    "return the pathname"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   303
a27a279701f8 Initial revision
claus
parents:
diff changeset
   304
    ^ pathName
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
store:something
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
    "what really should this do"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
    self nextPutAll:something storeString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
!FileStream methodsFor:'error handling'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   314
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
openError
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
    "report an error, that file open failed"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
    "/
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   319
    "/ for now, do not raise any signal (see super>>openError).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
    "/ Its not yet handled anywhere. Instead, senders of open
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
    "/ check for nil return value (which is a historic leftover)
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
    "/
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    LastErrorNumber := lastErrorNumber.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
    ^ nil.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   327
!FileStream methodsFor:'printing & storing'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   329
printOn:aStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
    aStream nextPutAll:'(a FileStream for:'.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
    aStream nextPutAll:pathName.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
    aStream nextPut:$)
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   333
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   334
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
storeOn:aStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
    aStream nextPutAll:'(FileStream oldFileNamed:'.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
    aStream nextPutAll:pathName.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
    (self position ~~ 1) ifTrue:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
	aStream nextPutAll:'; position:'.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
	self position storeOn:aStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
    ].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   342
    aStream nextPut:$)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   343
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   344
a27a279701f8 Initial revision
claus
parents:
diff changeset
   345
!FileStream methodsFor:'private'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   346
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   347
createForReadWrite
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   348
    "create/truncate the file for read/write.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   349
     If the file existed, its truncated; otherwise its created."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   350
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   351
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   352
    mode := #readwrite.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   353
    ^ self openWithMode:'w+'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   354
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   355
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
createForWriting
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   357
    "create/truncate the file for writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   358
     If the file existed, its truncated; otherwise its created."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   359
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   361
    didWrite := true.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   362
    ^ self openWithMode:'w'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   363
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
a27a279701f8 Initial revision
claus
parents:
diff changeset
   365
open
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
    "open the file"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
a27a279701f8 Initial revision
claus
parents:
diff changeset
   368
    pathName isNil ifTrue:[^nil].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   369
    (mode == #readonly) ifTrue: [
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   370
	didWrite := false.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   371
	^ self openWithMode:'r'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   372
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   373
    (mode == #writeonly) ifTrue: [
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   374
	didWrite := true.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   375
	^ self openWithMode:'w'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   376
    ].
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   377
    ^ self openWithMode:'r+'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   378
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   379
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   380
openForAppending
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   381
    "open the file for writeonly appending to the end.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   382
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   383
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   384
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   385
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   386
    didWrite := true.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   387
    ^ self openWithMode:'a+'
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   388
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   389
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   390
openForReadWrite
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   391
    "open the file for read/write.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   392
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   393
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   394
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   395
    mode := #readwrite.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   396
    ^ self openWithMode:'r+'
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   397
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   398
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   399
openForReading
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   400
    "open the file for readonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   401
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   402
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   403
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   404
    mode := #readonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   405
    didWrite := false.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   406
    ^ self openWithMode:'r'
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   407
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   408
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   409
openForWriting
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   410
    "open the file writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   411
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   412
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   413
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   414
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   415
    didWrite := true.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   416
    ^ self openWithMode:'r+'   "unix-io does not allow this; open for update here"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   417
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   418
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   419
openWithMode:openmode
a27a279701f8 Initial revision
claus
parents:
diff changeset
   420
    "open the file; openmode is the string defining the way to open"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   421
a27a279701f8 Initial revision
claus
parents:
diff changeset
   422
    |retVal|
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   423
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   424
    filePointer notNil ifTrue:[^ self errorOpen].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   425
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
   426
    FILE *f;
477
8710aba7876b oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents: 475
diff changeset
   427
    OBJ path, fp;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   429
    path = _INST(pathName);
328
claus
parents: 255
diff changeset
   430
    if (__isNonNilObject(path) && (__qClass(path)==String)) {
480
1f49378d506d open interruptable (required for example, when named pipes are opened)
Claus Gittinger <cg@exept.de>
parents: 477
diff changeset
   431
	__BEGIN_INTERRUPTABLE__
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   432
	do {
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   433
#ifdef LINUX
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   434
	    /* LINUX returns a non-NULL f even when interrupted */
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   435
	    errno = 0;
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   436
	    f = (FILE *) fopen((char *) _stringVal(path), (char *) _stringVal(openmode));
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   437
	    if (errno == EINTR)
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   438
		f = NULL;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   439
#else
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   440
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   441
	    f = (FILE *) fopen((char *) _stringVal(path), (char *) _stringVal(openmode));
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   442
#endif
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   443
	} while ((f == NULL) && (errno == EINTR));
480
1f49378d506d open interruptable (required for example, when named pipes are opened)
Claus Gittinger <cg@exept.de>
parents: 477
diff changeset
   444
	__END_INTERRUPTABLE__
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   445
	if (f == NULL) {
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   446
	    _INST(lastErrorNumber) = _MKSMALLINT(errno);
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   447
	    _INST(position) = nil;
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   448
	} else {
477
8710aba7876b oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents: 475
diff changeset
   449
	    _INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp);
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   450
	    _INST(position) = _MKSMALLINT(1);
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   451
	    retVal = self;
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   452
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   453
    }
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   454
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   455
    retVal notNil ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   456
	buffered := true.       "default is buffered"
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   457
	Lobby register:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   458
    ].
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   459
    lastErrorNumber notNil ifTrue:[
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   460
	"
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   461
	 the open failed for some reason ...
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   462
	"
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   463
	^ self openError
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   464
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   465
    ^ retVal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   466
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   467
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   468
pathName:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   469
    "set the pathname"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   470
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   471
    pathName := filename
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   472
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   473
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   474
pathName:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   475
    "set the pathname starting at aDirectory, a FileDirectory"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   476
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   477
    ((filename at:1) == $/) ifTrue:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   478
	"filename may not start with a '/'"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   479
	pathName := nil
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   480
    ] ifFalse:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   481
	pathName := aDirectory pathName.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   482
	(pathName endsWith:'/') ifFalse:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   483
	    pathName := pathName , '/'
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   484
	].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   485
	pathName := pathName , filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   486
    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   487
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   488
a27a279701f8 Initial revision
claus
parents:
diff changeset
   489
reOpen
a27a279701f8 Initial revision
claus
parents:
diff changeset
   490
    "sent after snapin to reopen streams"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   491
173
58e9778954bc reposition
claus
parents: 159
diff changeset
   492
    |oldPos|
58e9778954bc reposition
claus
parents: 159
diff changeset
   493
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   494
    filePointer notNil ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   495
	"it was open, when snapped-out"
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   496
	filePointer := nil.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   497
	Lobby unregister:self.
173
58e9778954bc reposition
claus
parents: 159
diff changeset
   498
	oldPos := position.
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   499
	self open.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   500
	filePointer isNil ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   501
	    "this happens, if after a restart, the file is no longer accessable ..."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   502
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   503
	    ('could not reopen file: ', pathName) errorPrintNL.
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   504
	] ifFalse:[
173
58e9778954bc reposition
claus
parents: 159
diff changeset
   505
	    self position:oldPos.
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   506
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   507
    ]
31
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
   508
! !
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
   509
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
   510
!FileStream methodsFor:'queries'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   511
a27a279701f8 Initial revision
claus
parents:
diff changeset
   512
position
a27a279701f8 Initial revision
claus
parents:
diff changeset
   513
    "return the read/write position in the file -
31
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
   514
     notice, in smalltalk indices start at 1 so begin of file is 1"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   515
a27a279701f8 Initial revision
claus
parents:
diff changeset
   516
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   517
a27a279701f8 Initial revision
claus
parents:
diff changeset
   518
    FILE *f;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   519
    long currentPosition;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   520
a27a279701f8 Initial revision
claus
parents:
diff changeset
   521
    if (_INST(filePointer) != nil) {
475
b57530aa1b0a use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
   522
	f = __FILEVal(_INST(filePointer));
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   523
	do {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   524
	    if (_INST(buffered) == true) {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   525
		currentPosition = (long) ftell(f);
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   526
	    } else {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   527
		currentPosition = (long) lseek(fileno(f), 0L, SEEK_CUR);
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   528
	    }
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   529
	} while ((currentPosition < 0) && (errno == EINTR));
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   530
	if (currentPosition >= 0) {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   531
	    /*
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   532
	     * notice: Smalltalk index starts at 1
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   533
	     */
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   534
	    RETURN ( _MKSMALLINT(currentPosition + 1) );
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   535
	}
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   536
	_INST(lastErrorNumber) = _MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   537
    }
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   538
%}.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   539
    lastErrorNumber notNil ifTrue:[^ self ioError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   540
    filePointer isNil ifTrue:[^ self errorNotOpen].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   541
    ^ self primitiveFailed
a27a279701f8 Initial revision
claus
parents:
diff changeset
   542
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   543
a27a279701f8 Initial revision
claus
parents:
diff changeset
   544
position:newPos
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
    "set the read/write position in the file"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   548
a27a279701f8 Initial revision
claus
parents:
diff changeset
   549
    FILE *f;
10
claus
parents: 5
diff changeset
   550
    int ret;
249
claus
parents: 223
diff changeset
   551
    OBJ fp;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   552
249
claus
parents: 223
diff changeset
   553
    if ((fp = _INST(filePointer)) != nil) {
claus
parents: 223
diff changeset
   554
	if (__isSmallInteger(newPos)) {
475
b57530aa1b0a use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
   555
	    f = __FILEVal(fp);
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   556
	    /*
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   557
	     * notice: Smalltalk index starts at 1
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   558
	     */
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   559
	    do {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   560
		if (_INST(buffered) == true) {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   561
		    ret = fseek(f, (long) (_intVal(newPos) - 1), SEEK_SET);
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   562
		} else {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   563
		    ret = (long) lseek(fileno(f), (long)(_intVal(newPos) - 1), SEEK_SET);
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   564
		}
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   565
	    } while ((ret < 0) && (errno == EINTR));
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   566
	    if (ret >= 0) {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   567
		_INST(position) = newPos;
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   568
		/*
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   569
		 * just to make certain ...
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   570
		 */
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   571
		_INST(hitEOF) = false;
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   572
		RETURN ( self );
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   573
	    }
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   574
	    _INST(lastErrorNumber) = _MKSMALLINT(errno);
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   575
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   576
    }
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   577
%}.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   578
    lastErrorNumber notNil ifTrue:[^ self ioError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   579
    filePointer isNil ifTrue:[^ self errorNotOpen].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   580
    ^ self primitiveFailed
a27a279701f8 Initial revision
claus
parents:
diff changeset
   581
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   582
a27a279701f8 Initial revision
claus
parents:
diff changeset
   583
setToEnd
a27a279701f8 Initial revision
claus
parents:
diff changeset
   584
    "set the read/write position in the file to be at the end of the file"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   585
a27a279701f8 Initial revision
claus
parents:
diff changeset
   586
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
   587
    FILE *f;
10
claus
parents: 5
diff changeset
   588
    int ret;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   589
49
f1c2d75f2eb6 *** empty log message ***
claus
parents: 42
diff changeset
   590
    if (_INST(filePointer) != nil) {
475
b57530aa1b0a use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
   591
	f = __FILEVal(_INST(filePointer));
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   592
	_INST(position) = nil;
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   593
	do {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   594
	    if (_INST(buffered) == true) {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   595
		ret = fseek(f, 0L, SEEK_END);
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   596
	    } else {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   597
		ret = (long)lseek(fileno(f), 0L, SEEK_END);
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   598
	    }
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   599
	} while ((ret < 0) && (errno == EINTR));
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   600
	if (ret >= 0) {
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   601
	    RETURN ( self );
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   602
	}
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   603
	_INST(lastErrorNumber) = _MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   604
    }
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   605
%}.
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   606
    lastErrorNumber notNil ifTrue:[^ self ioError].
49
f1c2d75f2eb6 *** empty log message ***
claus
parents: 42
diff changeset
   607
    filePointer isNil ifTrue:[^ self errorNotOpen].
f1c2d75f2eb6 *** empty log message ***
claus
parents: 42
diff changeset
   608
    DemoMode ifTrue:[^ self warn:'no save in Demo mode'].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   609
    ^ self primitiveFailed
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   610
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   611
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   612
size
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   613
    "return the size in bytes of the file"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   614
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   615
%{  /* NOCONTEXT */
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   616
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   617
#ifdef transputer
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   618
    FILE *f;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   619
    int size;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   620
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   621
    if (_INST(filePointer) != nil) {
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   622
	f = __FILEVal(_INST(filePointer));
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
	if ((size = filesize(fileno(f))) >= 0) {
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
	    RETURN ( _MKSMALLINT(size) );
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   625
	}
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   626
    }
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   627
#else
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   628
    FILE *f;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   629
    struct stat buf;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   630
    int ret;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   631
    int fd;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   632
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   633
    if (_INST(filePointer) != nil) {
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   634
	f = __FILEVal(_INST(filePointer));
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
	fd = fileno(f);
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   636
	do {
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   637
	    ret = fstat(fd, &buf);
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   638
	} while ((ret < 0) && (errno == EINTR));
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   639
	if (ret >= 0) {
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   640
	    RETURN ( _MKSMALLINT(buf.st_size) );
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   641
	}
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   642
	_INST(lastErrorNumber) = _MKSMALLINT(errno);
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   643
    }
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   644
#endif
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   645
%}.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   646
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   647
    "could add a fall-back here:
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   648
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   649
	oldPosition := self position.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   650
	self setToEnd.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   651
	sz := self position.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   652
	self position:oldPosition.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   653
	^ sz
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   654
    "
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   655
    lastErrorNumber notNil ifTrue:[^ self ioError].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   656
    filePointer isNil ifTrue:[^ self errorNotOpen].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   657
    ^ self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   658
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   659
2
claus
parents: 1
diff changeset
   660
!FileStream methodsFor:'testing'!
claus
parents: 1
diff changeset
   661
claus
parents: 1
diff changeset
   662
isFileStream
claus
parents: 1
diff changeset
   663
    "return true, if the receiver is some kind of fileStream.
claus
parents: 1
diff changeset
   664
     redefined from Object"
claus
parents: 1
diff changeset
   665
claus
parents: 1
diff changeset
   666
    ^ true
claus
parents: 1
diff changeset
   667
! !
claus
parents: 1
diff changeset
   668