FileStream.st
author Claus Gittinger <cg@exept.de>
Thu, 15 Jul 1999 21:45:54 +0200
changeset 4392 26fb48f04e1b
parent 4353 7e2ec99414c7
child 4526 a42dc8e09586
permissions -rw-r--r--
comment
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
3754
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
    14
	instanceVariableNames:'pathName canPosition removeOnClose'
3231
538eee23688a FileStream OpenErrorSignal is a querySignal, ExternalStream
Stefan Vogel <sv@exept.de>
parents: 3051
diff changeset
    15
	classVariableNames:'OpenErrorSignal'
1088
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
    16
	poolDictionaries:''
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
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
%{
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
    22
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
#include <stdio.h>
437
claus
parents: 384
diff changeset
    24
#define _STDIO_H_INCLUDED_
claus
parents: 384
diff changeset
    25
3956
51f1a9a4d63f changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
    26
10
claus
parents: 5
diff changeset
    27
#include <errno.h>
437
claus
parents: 384
diff changeset
    28
#define _ERRNO_H_INCLUDED_
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    29
a27a279701f8 Initial revision
claus
parents:
diff changeset
    30
#ifdef transputer
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
# include <iocntrl.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    32
# ifndef fileno
a27a279701f8 Initial revision
claus
parents:
diff changeset
    33
   /* kludge: inmos forgot fileno */
a27a279701f8 Initial revision
claus
parents:
diff changeset
    34
#  define fileno(f)     ((f)->__file)
a27a279701f8 Initial revision
claus
parents:
diff changeset
    35
# endif
a27a279701f8 Initial revision
claus
parents:
diff changeset
    36
#else
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
# include <sys/types.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    38
# include <sys/stat.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    39
#endif
10
claus
parents: 5
diff changeset
    40
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    41
#ifdef hpux
68
59faa75185ba *** empty log message ***
claus
parents: 49
diff changeset
    42
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    43
#endif
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    44
10
claus
parents: 5
diff changeset
    45
#ifndef SEEK_SET
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
    46
# define SEEK_SET       0
10
claus
parents: 5
diff changeset
    47
#endif
claus
parents: 5
diff changeset
    48
#ifndef SEEK_CUR
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
    49
# define SEEK_CUR       1
10
claus
parents: 5
diff changeset
    50
#endif
claus
parents: 5
diff changeset
    51
#ifndef SEEK_END
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
    52
# define SEEK_END       2
10
claus
parents: 5
diff changeset
    53
#endif
claus
parents: 5
diff changeset
    54
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    55
/*
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    56
 * not all systems have off_t
2808
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    57
 * explicit add of those we know to have ...
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    58
 */
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    59
#ifdef __osf__
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    60
# define OFF_T  off_t
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    61
#endif
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    62
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    63
#ifndef OFF_T
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    64
# define OFF_T  long
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    65
#endif
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    66
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    67
#ifdef __VMS__
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    68
/*
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    69
 * get those VMS definitions ...
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    70
 */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    71
# include <rms.h>
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    72
#endif
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    73
2992
197c2c222030 win32 change
Claus Gittinger <cg@exept.de>
parents: 2974
diff changeset
    74
#ifndef WIN32
197c2c222030 win32 change
Claus Gittinger <cg@exept.de>
parents: 2974
diff changeset
    75
 extern long ftell(), lseek();
197c2c222030 win32 change
Claus Gittinger <cg@exept.de>
parents: 2974
diff changeset
    76
#endif
197c2c222030 win32 change
Claus Gittinger <cg@exept.de>
parents: 2974
diff changeset
    77
2808
3a9ce7aadad8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2796
diff changeset
    78
/*
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    79
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    80
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    81
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    82
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    83
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
    84
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
%}
173
58e9778954bc reposition
claus
parents: 159
diff changeset
    86
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
!FileStream class methodsFor:'documentation'!
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
copyright
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
 COPYRIGHT (c) 1989 by Claus Gittinger
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
	      All Rights Reserved
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
 This software is furnished under a license and may be used
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
 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
    97
 inclusion of the above copyright notice.   This software may not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
 be provided or otherwise made available to, or used by, any
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    99
 other person.  No title to or ownership of the software is
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
 hereby transferred.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
!
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
documentation
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
    This class provides access to the operating systems underlying file
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
    system (i.e. its an interface to the stdio library).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
    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
   110
    problems when a file is opened for readwrite. 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
    For best results, open files either readonly or writeonly.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   112
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   113
    Also notice, that some OperatingSystems do not fully support
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   114
    positioning a file stream.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   115
    For example, poor VMS does not allow positioning onto arbitrary
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   116
    byte boundaries if the file is a variable-record-RMS file.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   117
    (stupid enough, this is the default for textfiles as created by
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   118
     some tools ...)
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   119
    Therefore, the instance variable canPosition is set according to
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   120
    this and an error is raised, if a position: is attemted.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   121
    I know, this is ugly, but what else could we do ?
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   122
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   123
    [instance variables:]
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   124
	pathName	<String>	the files path (if known)
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   125
	canPosition	<Boolean>	positionable - read above comment
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   126
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   127
    [author:]
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   128
	Claus Gittinger
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   129
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   130
    [see also:]
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   131
	Filename DirectoryStream PipeStream Socket
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   132
"
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   133
!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   134
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   135
examples
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   136
"
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   137
  for VMS users only:
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   138
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   139
    The #openWithMode:attributes: entry allows additional RMS attributes
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   140
    to be passed in the second argument, which must be an array of strings
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   141
    as described in the 'creat' RTL Library documentation.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   142
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   143
    For example, to create a file with fixed records and recordLength of 100,
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   144
    use:
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   145
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   146
	|newFile|
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   147
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   148
	newFile := FileStream new pathName:'<nameOfFile>'.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   149
	newFile setMode:#writeonly.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   150
	newFile openWithMode:'w' attributes:#('rfm=fix' 'fsz=100').
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   151
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   152
    since all of the above is private protocol, and it is considered bad style to
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   153
    access these from user programs, we recommend subclassing FileStream as
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   154
    something like VMSFixedRecordFileStream, and redefine the instance creation
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   155
    method(s) there as appropriate. 
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   156
    This will retain VMS specifics in one place and enhance maintanability.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   157
"
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   158
! !
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   159
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   160
!FileStream class methodsFor:'initialization'!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   161
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   162
initialize
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   163
    OpenErrorSignal isNil ifTrue:[
3006
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   164
        "/
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   165
        "/ this is temporary - for now allow an openError to
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   166
        "/ be unhandled and proceed by returning a nil from the
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   167
        "/ stream creation method.
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   168
        "/ In the future, this will be a hard signal.
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   169
        "/
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   170
        OpenErrorSignal := QuerySignal new.
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   171
        OpenErrorSignal parent:(super openErrorSignal) mayProceed:true.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   172
        OpenErrorSignal nameClass:self message:#openErrorSignal.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   173
        OpenErrorSignal notifierString:'open error'.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   174
    ]
3006
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   175
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   176
    "Modified: 8.10.1997 / 11:56:39 / cg"
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   177
! !
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   178
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   179
!FileStream class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
appendingOldFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
    "return a FileStream for existing file named filename, aString.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
     The file is opened for writeonly access."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
    |newStream|
2
claus
parents: 1
diff changeset
   186
    newStream := self new pathName:filename.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
    newStream openForAppending isNil ifTrue:[^nil].
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
    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
   190
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
    newStream readLimit:(newStream size).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   192
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   193
    ^ newStream
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
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   196
appendingOldFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
    "return a FileStream for existing file named filename, aString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   198
     in aDirectory, a FileDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   199
     The file is opened for writeonly access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   202
    newStream := self new pathName:filename in:aDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   203
    newStream openForAppending isNil ifTrue:[^nil].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   204
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   205
    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
   206
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   207
    newStream readLimit:(newStream size).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   208
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   209
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   211
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
fileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
    "return a stream on file filename - if the file does not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
     already exist, create it.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   215
     The file is opened for read/write access."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   216
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
    |stream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
    stream := self oldFileNamed:filename.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   220
    stream isNil ifTrue:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   221
	stream := self newFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
    ].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   223
    ^ stream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   224
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   226
fileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
    "return a stream on file filename - if the file does not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
     already exist, create it.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   229
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   230
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   231
    |stream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   232
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   233
    stream := self oldFileNamed:filename in:aDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
    stream isNil ifTrue:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
	stream := self newFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
    ].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   237
    ^ stream
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   238
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   239
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   240
newFileForWritingNamed:filename
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   241
    "return a FileStream for new file named filename, aString.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   242
     If the file exists, it is truncated, otherwise created.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   243
     The file is opened for writeonly access."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   244
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   245
    |newStream|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   246
    newStream := self new pathName:filename.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   247
    newStream createForWriting isNil ifTrue:[^nil].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   248
    ^ newStream
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   249
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   250
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   251
newFileForWritingNamed:filename in:aDirectory
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   252
    "return a FileStream for new file named filename, aString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   253
     in aDirectory, a FileDirectory.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   254
     If the file exists, it is truncated, otherwise created.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   255
     The file is opened for writeonly access."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   256
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   257
    |newStream|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   258
    newStream := self new pathName:filename in:aDirectory.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   259
    newStream createForWriting isNil ifTrue:[^nil].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   260
    ^ newStream
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   261
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   262
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   263
newFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   264
    "return a FileStream for new file named filename, aString.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   265
     If the file exists, it is truncated, otherwise created.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   266
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   267
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   268
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
    newStream := self new pathName:filename.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
    newStream createForReadWrite isNil ifTrue:[^nil].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
    ^ newStream
3051
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   272
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   273
    "Modified: / 28.10.1997 / 14:28:08 / cg"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   274
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   275
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   276
newFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   277
    "return a FileStream for new file named filename, aString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   278
     in aDirectory, a FileDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   279
     If the file exists, it is truncated, otherwise created.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   283
    newStream := self new pathName:filename in:aDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   284
    newStream createForReadWrite isNil ifTrue:[^nil].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
    ^ newStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   288
oldFileNamed:filename
a27a279701f8 Initial revision
claus
parents:
diff changeset
   289
    "return a FileStream for existing file named filename, aString.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   290
     The file is opened for read/write access."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   291
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
    |newStream|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
a27a279701f8 Initial revision
claus
parents:
diff changeset
   294
    (OperatingSystem isReadable:filename) ifFalse:[^nil].
2
claus
parents: 1
diff changeset
   295
    newStream := self new pathName:filename.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   296
    newStream readwrite.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   297
    newStream openForReadWrite isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   298
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   299
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   300
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   301
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   302
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   303
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   304
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
a27a279701f8 Initial revision
claus
parents:
diff changeset
   306
oldFileNamed:filename in:aDirectory
a27a279701f8 Initial revision
claus
parents:
diff changeset
   307
    "return a FileStream for existing file named filename, aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   308
     in aDirectory, a FileDirectory.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   309
     The file is opened for read/write access."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   310
a27a279701f8 Initial revision
claus
parents:
diff changeset
   311
    |newStream|
2
claus
parents: 1
diff changeset
   312
    newStream := self new pathName:filename in:aDirectory.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   313
    newStream openForReadWrite isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   314
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   315
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   316
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   317
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   318
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   319
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   320
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   321
a27a279701f8 Initial revision
claus
parents:
diff changeset
   322
readonlyFileNamed:filename
a27a279701f8 Initial revision
claus
parents:
diff changeset
   323
    "return a readonly FileStream for existing file named filename, aString"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   324
a27a279701f8 Initial revision
claus
parents:
diff changeset
   325
    |newStream|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   326
a27a279701f8 Initial revision
claus
parents:
diff changeset
   327
    (OperatingSystem isReadable:filename) ifFalse:[^nil].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   328
2
claus
parents: 1
diff changeset
   329
    newStream := self new pathName:filename.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   330
    newStream openForReading isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   331
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   332
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   333
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   334
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   335
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   336
    ^ newStream
a27a279701f8 Initial revision
claus
parents:
diff changeset
   337
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   338
a27a279701f8 Initial revision
claus
parents:
diff changeset
   339
readonlyFileNamed:filename in:aDirectory
a27a279701f8 Initial revision
claus
parents:
diff changeset
   340
    "return a readonly FileStream for existing file named filename, aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   341
     in aDirectory, a FileDirectory"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   342
a27a279701f8 Initial revision
claus
parents:
diff changeset
   343
    |newStream|
2
claus
parents: 1
diff changeset
   344
    newStream := self new pathName:filename in:aDirectory.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   345
    newStream openForReading isNil ifTrue:[^nil].
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   346
"
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   347
    this is not a good idea; someone else might be appending ...
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   348
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   349
    newStream readLimit:(newStream size).
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
   350
"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   351
    ^ newStream
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   352
! !
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   353
3233
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   354
!FileStream class methodsFor:'Signal constants'!
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   355
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   356
openErrorSignal
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   357
    "return the FileStream specific openErrorSignal.
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   358
     This is different from ExternalStream>>OpenErrorSignal!!"
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   359
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   360
    ^ OpenErrorSignal
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   361
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   362
    "Created: / 28.1.1998 / 14:41:18 / stefan"
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   363
! !
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   364
4353
7e2ec99414c7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4272
diff changeset
   365
!FileStream class methodsFor:'Squeak compatibility'!
7e2ec99414c7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4272
diff changeset
   366
7e2ec99414c7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4272
diff changeset
   367
readOnlyFileNamed:filename
7e2ec99414c7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4272
diff changeset
   368
    ^ self readonlyFileNamed:filename
7e2ec99414c7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4272
diff changeset
   369
! !
7e2ec99414c7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4272
diff changeset
   370
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   371
!FileStream methodsFor:'Squeak compatibility'!
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   372
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   373
fullName
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   374
    "Squeak compatibility: return the full pathname"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   375
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   376
    ^ pathName asFilename pathName
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   377
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   378
    "Created: 17.10.1997 / 17:04:12 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   379
    "Modified: 20.10.1997 / 19:22:44 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   380
! !
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   381
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   382
!FileStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
directoryName
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   385
    "return the name of the directory I'm in as a string"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   387
    ^ pathName asFilename directoryName
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   388
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   389
a27a279701f8 Initial revision
claus
parents:
diff changeset
   390
name
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   391
    "return my name without leading direcory-path (i.e. the plain fileName)
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   392
     as a string"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   393
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   394
    ^ pathName asFilename baseName
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
a27a279701f8 Initial revision
claus
parents:
diff changeset
   397
pathName
a27a279701f8 Initial revision
claus
parents:
diff changeset
   398
    "return the pathname"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   399
a27a279701f8 Initial revision
claus
parents:
diff changeset
   400
    ^ pathName
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   401
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   402
3754
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   403
removeOnClose:aBoolean
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   404
    "set/clear the removeOnClose flag.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   405
     If set, the file will be removed when closed.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   406
     Provided mostly for OS's which do not allow an
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   407
     open file to be removed (i.e. non unixes),
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   408
     and a fileStream for a tempFile is used.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   409
     Especially, the CVS-SourceCodeManager returns
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   410
     this kind of file-handles occasionally.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   411
     This is an ST/X special feature which is not portable
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   412
     to other systems."
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   413
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   414
    removeOnClose := aBoolean
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   415
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   416
    "Modified: / 13.8.1998 / 12:10:07 / cg"
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   417
!
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   418
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   419
store:something
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   420
    "what really should this do"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   421
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   422
    self nextPutAll:something storeString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   423
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   424
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   425
!FileStream methodsFor:'error handling'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   426
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   427
openError
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   428
    "{ Pragma: +optSpace }"
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   429
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   430
    "report an error, that file open failed"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   431
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   432
    "/
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   433
    "/ for now, error on open only raises a querySignal.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   434
    "/ If its not handled, a failing open will return nil.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   435
    "/ Currently, all users of fileStream check for this
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   436
    "/ nil return value (which is a historic leftover)
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   437
    "/
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   438
    "/ This will change in one of the next ST/X releases - for
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   439
    "/ now, it is best to provide an exceptionHandler AND check the
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   440
    "/ return value. 
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   441
    "/ Sorry about that.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
    "/
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   443
    LastErrorNumber := lastErrorNumber.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   444
    super openError.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   445
    ^ nil
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   446
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
3754
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   448
!FileStream methodsFor:'instance release'!
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   449
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   450
closeFile
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   451
    "low level close - may be redefined in subclasses"
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   452
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   453
    super closeFile.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   454
    removeOnClose == true ifTrue:[
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   455
        pathName asFilename remove.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   456
    ]
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   457
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   458
    "Created: / 13.8.1998 / 12:11:22 / cg"
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   459
! !
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   460
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   461
!FileStream methodsFor:'positioning'!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   462
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   463
position
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   464
    "return the read/write position in the file -
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   465
     notice, in smalltalk indices start at 1 so begin of file is 1"
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   466
3971
aad506cdc5d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3956
diff changeset
   467
%{
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   468
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   469
    FILE *f;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   470
    long currentPosition;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   471
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   472
    if (__INST(filePointer) != nil) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   473
	f = __FILEVal(__INST(filePointer));
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   474
	do {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   475
	    if (__INST(buffered) == true) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   476
		currentPosition = ftell(f);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   477
	    } else {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   478
		currentPosition = lseek(fileno(f), 0L, SEEK_CUR);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   479
	    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   480
	} while ((currentPosition < 0) && (errno == EINTR));
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   481
	if (currentPosition >= 0) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   482
	    /*
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   483
	     * notice: Smalltalk index starts at 1
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   484
	     */
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   485
	    RETURN ( __MKSMALLINT(currentPosition + 1) );
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   486
	}
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   487
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   488
    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   489
%}.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   490
    lastErrorNumber notNil ifTrue:[^ self ioError].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   491
    filePointer isNil ifTrue:[^ self errorNotOpen].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   492
    ^ self primitiveFailed
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   493
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   494
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   495
position:newPos
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   496
    "set the read/write position in the file"
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   497
3971
aad506cdc5d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3956
diff changeset
   498
%{
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   499
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   500
    FILE *f;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   501
    long ret;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   502
    OBJ fp;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   503
    long nP;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   504
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   505
    if ((__INST(canPosition) != false) 
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   506
     || (newPos == __MKSMALLINT(1))) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   507
        if ((fp = __INST(filePointer)) != nil) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   508
	    if (__isSmallInteger(newPos)) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   509
	        f = __FILEVal(fp);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   510
	        nP = (long)__intVal(newPos);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   511
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   512
	        /*
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   513
	         * notice: Smalltalk index starts at 1
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   514
	         */
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   515
	        nP--;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   516
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   517
	        do {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   518
		    if (__INST(buffered) == true) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   519
		        ret = fseek(f, nP, SEEK_SET);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   520
		    } else {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   521
		        ret = lseek(fileno(f), nP, SEEK_SET);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   522
		    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   523
	        } while ((ret < 0) && (errno == EINTR));
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   524
	        if (ret >= 0) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   525
		    __INST(position) = newPos;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   526
		    /*
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   527
		     * just to make certain ...
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   528
		     */
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   529
		    __INST(hitEOF) = false;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   530
		    RETURN ( self );
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   531
	        }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   532
	        __INST(lastErrorNumber) = __MKSMALLINT(errno);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   533
	    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   534
	}
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   535
    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   536
%}.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   537
    canPosition == false ifTrue:[
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   538
	"/ position by rewinding & re-reading everything up-to
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   539
	"/ that point.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   540
	^ self slowPosition:newPos
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   541
    ].
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   542
    lastErrorNumber notNil ifTrue:[
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   543
	(OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   544
	    "/ invalid position
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   545
	    ^ self positionError
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   546
	].
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   547
	"/ assume I/O error
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   548
	^ self ioError
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   549
    ].
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   550
    filePointer isNil ifTrue:[^ self errorNotOpen].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   551
    ^ self primitiveFailed
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   552
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   553
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   554
setToEnd
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   555
    "set the read/write position in the file to be at the end of the file"
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   556
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   557
%{
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   558
    FILE *f;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   559
    long ret;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   560
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   561
    if (__INST(filePointer) != nil) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   562
	f = __FILEVal(__INST(filePointer));
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   563
	__INST(position) = nil;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   564
	do {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   565
	    if (__INST(buffered) == true) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   566
		ret = fseek(f, 0L, SEEK_END);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   567
	    } else {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   568
		ret = lseek(fileno(f), 0L, SEEK_END);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   569
	    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   570
	} while ((ret < 0) && (errno == EINTR));
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   571
	if (ret >= 0) {
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   572
	    RETURN ( self );
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   573
	}
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   574
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   575
    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   576
%}.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   577
    lastErrorNumber notNil ifTrue:[^ self ioError].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   578
    filePointer isNil ifTrue:[^ self errorNotOpen].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   579
    ^ self primitiveFailed
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   580
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   581
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   582
slowPosition:newPos
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   583
    "position the file by re-reading everything up-to newPos.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   584
     The effect is the same as that of #position:, but its much slower.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   585
     This is required to reposition nonPositionable streams, such
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   586
     as tape-streams or variable-record-RMS files under VMS.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   587
     Caveat:
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   588
         This should really be done transparently by the stdio library."
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   589
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   590
    |buffer amount|
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   591
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   592
    self isReadable ifFalse:[
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   593
	"/ sorry
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   594
	^ self positionError
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   595
    ].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   596
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   597
    buffer := ByteArray new:8*1024.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   598
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   599
    (position isNil "/ i.e. unknown
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   600
    or:[newPos < position]) ifTrue:[
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   601
        self reset.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   602
    ].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   603
    [position < newPos] whileTrue:[
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   604
	amount := (buffer size) min:(newPos-position).
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   605
	(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   606
	    ^ self positionError
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   607
	].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   608
    ].
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   609
    "/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   610
! !
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
   611
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   612
!FileStream methodsFor:'printing & storing'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   614
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4353
diff changeset
   615
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4353
diff changeset
   616
     The format is suitable for a human - not meant to be read back."
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   617
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   618
    aStream nextPutAll:'(a FileStream for:'.
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   619
    aStream nextPutAll:pathName printString.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   620
    aStream nextPut:$)
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   621
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   622
    "Modified: 30.7.1997 / 13:51:01 / cg"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   625
storeOn:aStream
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   626
    "append a representation of the receiver to aStream,
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   627
     from which a copy can be reconstructed later."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   628
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   629
    aStream nextPutAll:'(FileStream oldFileNamed:'.
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   630
    aStream nextPutAll:pathName storeString.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   631
    (self position ~~ 1) ifTrue:[
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   632
        aStream nextPutAll:'; position:'.
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   633
        self position storeOn:aStream
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   634
    ].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
    aStream nextPut:$)
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   636
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
   637
    "Modified: 30.7.1997 / 16:43:50 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   638
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   639
a27a279701f8 Initial revision
claus
parents:
diff changeset
   640
!FileStream methodsFor:'private'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   641
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   642
createForReadWrite
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   643
    "create/truncate the file for read/write.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   644
     If the file existed, its truncated; otherwise its created."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   645
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   646
    mode := #readwrite.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   647
    ^ self openWithMode:CreateReadWriteMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   648
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   649
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   650
createForWriting
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   651
    "create/truncate the file for writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   652
     If the file existed, its truncated; otherwise its created."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   653
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   654
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   655
    didWrite := true.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   656
    ^ self openWithMode:WriteMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   657
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   658
a27a279701f8 Initial revision
claus
parents:
diff changeset
   659
open
a27a279701f8 Initial revision
claus
parents:
diff changeset
   660
    "open the file"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   661
a27a279701f8 Initial revision
claus
parents:
diff changeset
   662
    pathName isNil ifTrue:[^nil].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   663
    (mode == #readonly) ifTrue: [
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   664
	didWrite := false.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   665
	^ self openWithMode:ReadMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   666
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   667
    (mode == #writeonly) ifTrue: [
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   668
	didWrite := true.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   669
	^ self openWithMode:WriteMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   670
    ].
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   671
    ^ self openWithMode:ReadWriteMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   672
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   673
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   674
openForAppending
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   675
    "open the file for writeonly appending to the end.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   676
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   677
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   678
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   679
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   680
    didWrite := true.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   681
    ^ self openWithMode:AppendMode
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   682
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   683
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   684
openForReadWrite
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   685
    "open the file for read/write.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   686
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   687
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   688
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   689
    mode := #readwrite.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   690
    ^ self openWithMode:ReadWriteMode
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   691
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   692
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   693
openForReading
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   694
    "open the file for readonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   695
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   696
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   697
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   698
    mode := #readonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   699
    didWrite := false.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   700
    ^ self openWithMode:ReadMode
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   701
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   702
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   703
openForWriting
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   704
    "open the file writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   705
     If the file does not exist its an error, return nil; 
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   706
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   707
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   708
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   709
    didWrite := true.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   710
    ^ self openWithMode:ReadWriteMode   "unix-io does not allow this; open for update here"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   711
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   712
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   713
openWithMode:openmode
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   714
    "open the file;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   715
     openmode is the string defining the way to open as defined by the stdio library
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   716
     (i.e. the 2nd fopen argument).
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   717
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   718
     This is a private entry, but maybe useful to open a file in a special mode,
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   719
     which is proprietrary to the operatingSystem."
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   720
     
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   721
    ^ self openWithMode:openmode attributes:nil
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   722
!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   723
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   724
openWithMode:openmode attributes:attributeSpec
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   725
    "open the file; 
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   726
     openmode is the string defining the way to open as defined by the stdio library
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   727
     (i.e. the 2nd fopen argument).
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   728
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   729
     attributeSpec is an additional argument, only used with VMS - it allows a file to
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   730
     be created as fixedRecord, variableRecord, streamLF, streamCR, ...
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   731
     In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   732
     attributes (see fopen description).
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   733
     Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   734
     This argument is ignored in UNIX & MSDOS systems.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   735
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   736
     This is a private entry, but maybe useful to open/create a file in a special mode,
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   737
     which is proprietrary to the operatingSystem."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   738
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   739
    |ok|
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   740
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   741
    filePointer notNil ifTrue:[^ self errorOpen].
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   742
    ok := false.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   743
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
   744
    FILE *f;
2763
cea404472e7c 64bit (alpha) changes
Claus Gittinger <cg@exept.de>
parents: 2161
diff changeset
   745
    FILE *fopen();
477
8710aba7876b oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents: 475
diff changeset
   746
    OBJ path, fp;
2078
0a5a557b5194 Try to collect unref files if there are no filedescriptors available.
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   747
    int pass = 0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   748
2078
0a5a557b5194 Try to collect unref files if there are no filedescriptors available.
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   749
retry:
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
   750
    path = __INST(pathName);
328
claus
parents: 255
diff changeset
   751
    if (__isNonNilObject(path) && (__qClass(path)==String)) {
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   752
#ifdef __VMS__
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   753
	do {
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   754
	    /*
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   755
	     * allow passing additional RMS arguments.
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   756
	     * stupid: DEC does not seem to offer an interface for passing a char **.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   757
	     */
2974
7e7c19f4d6d2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2963
diff changeset
   758
	    errno = 0;
7e7c19f4d6d2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2963
diff changeset
   759
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   760
	    {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   761
		if (__isArray(attributeSpec)) {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   762
		    OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   763
		    int numAttrib = 0;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   764
		    int i;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   765
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   766
		    numAttrib = __arraySize(attributeSpec);
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   767
		    for (i=0; i<numAttrib;i++) {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   768
			if (! __isString(ap[i])) {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   769
		            f = NULL;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   770
		            errno = EINVAL; /* invalid argument */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   771
			    goto getOutOfHere;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   772
			}
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   773
		    }
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   774
		    switch (numAttrib) {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   775
			case 0:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   776
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   777
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   778
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   779
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   780
			case 1:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   781
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   782
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   783
				      __stringVal(ap[0]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   784
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   785
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   786
			case 2:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   787
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   788
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   789
				      __stringVal(ap[0]), __stringVal(ap[1]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   790
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   791
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   792
			case 3:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   793
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   794
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   795
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   796
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   797
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   798
			case 4:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   799
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   800
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   801
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   802
				      __stringVal(ap[3]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   803
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   804
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   805
			case 5:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   806
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   807
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   808
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   809
				      __stringVal(ap[3]), __stringVal(ap[4]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   810
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   811
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   812
			case 6:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   813
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   814
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   815
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   816
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   817
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   818
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   819
			case 7:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   820
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   821
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   822
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   823
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   824
				      __stringVal(ap[6]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   825
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   826
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   827
			case 8:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   828
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   829
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   830
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   831
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   832
				      __stringVal(ap[6]), __stringVal(ap[7]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   833
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   834
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   835
			case 9:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   836
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   837
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   838
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   839
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   840
				      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   841
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   842
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   843
			case 10:
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   844
		            __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   845
			    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   846
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   847
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   848
				      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]),
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   849
				      __stringVal(ap[9]));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   850
			    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   851
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   852
		  	default:
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   853
			    f = NULL;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   854
			    errno = E2BIG; /* too many args */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   855
			    goto getOutOfHere;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   856
		    }
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   857
		} else if (attributeSpec != nil) {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   858
		    f = NULL;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   859
		    errno = EINVAL; /* invalid argument */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   860
		    goto getOutOfHere;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   861
		} else {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   862
	            /*
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   863
	             * create file as sequential streamLF by default.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   864
	             */
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   865
		    __BEGIN_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   866
	    	    f = fopen((char *)__stringVal(path), (char *)__stringVal(openmode), "rfm=stmlf");
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   867
		    __END_INTERRUPTABLE__
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   868
		}
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   869
	    }
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   870
	    /* must refetch - could be GC'd */
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   871
	    path = __INST(pathName);
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   872
	} while ((f == NULL) && (errno == EINTR));
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   873
#else
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   874
	do {
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   875
	    __BEGIN_INTERRUPTABLE__
3039
Claus Gittinger <cg@exept.de>
parents: 3034
diff changeset
   876
# ifdef LINUX
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   877
	    /* 
4272
43808a0d0096 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
   878
	     * LINUX may ret a non-NULL f even when interrupted.
43808a0d0096 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
   879
	     * Therefore, check errno and fake a null-ret.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   880
	     */
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   881
	    errno = 0;
2763
cea404472e7c 64bit (alpha) changes
Claus Gittinger <cg@exept.de>
parents: 2161
diff changeset
   882
	    f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode));
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   883
	    if (errno == EINTR)
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   884
		f = NULL;
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   885
# else
2763
cea404472e7c 64bit (alpha) changes
Claus Gittinger <cg@exept.de>
parents: 2161
diff changeset
   886
	    f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode));
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   887
# endif
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   888
	    __END_INTERRUPTABLE__
2817
10f114dfe605 oops - GC while being in an interrupted file-open may lead to bad path-string access
Claus Gittinger <cg@exept.de>
parents: 2811
diff changeset
   889
	    /* must refetch - could be GC'd */
10f114dfe605 oops - GC while being in an interrupted file-open may lead to bad path-string access
Claus Gittinger <cg@exept.de>
parents: 2811
diff changeset
   890
	    path = __INST(pathName);
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   891
	} while ((f == NULL) && (errno == EINTR));
3034
9b4392e92e06 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3006
diff changeset
   892
#endif
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   893
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   894
	if (f == NULL) {
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   895
	    /*
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   896
	     * If no filedescriptors available, try to finalize
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   897
	     * possibly collected fd's and try again.
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   898
	     */
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   899
	    if (pass == 0 && (errno == ENFILE || errno == EMFILE)) {
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   900
		pass = 1;
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   901
		__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   902
		__SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   903
		goto retry;
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   904
	    }
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   905
	getOutOfHere: ;
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   906
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   907
	    __INST(position) = nil;
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   908
	} else {
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   909
#ifdef __VMS__
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   910
	    /*
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   911
	     * check to see if this is positionable ...
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   912
	     */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   913
	    __INST(canPosition) = false;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   914
# ifndef _POSIX_C_SOURCE
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   915
	    {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   916
		struct stat statBuffer;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   917
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   918
		if (fstat(fileno(f), &statBuffer) >= 0) {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   919
		    switch (statBuffer.st_fab_rfm) {
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   920
                        case FAB$C_UDF: /* undefined (also stream binary)   */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   921
                        case FAB$C_VAR: /* variable length records          */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   922
                        case FAB$C_VFC: /* variable fixed control           */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   923
                        case FAB$C_STM: /* RMS-11 stream (valid only for sequen> */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   924
                        default:
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   925
			    __INST(canPosition) = false;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   926
			    break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   927
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   928
                        case FAB$C_FIX: /* fixed length records             */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   929
                        case FAB$C_STMLF: /* LF stream (valid only for sequential> */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   930
                        case FAB$C_STMCR: /* CR stream (valid only for sequential> */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   931
			    __INST(canPosition) = true;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   932
                            break;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   933
		    }
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   934
		}
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   935
	    }
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   936
# endif 
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   937
#else /* not VMS */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   938
	    __INST(canPosition) = true;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   939
#endif /* poor VMS */
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   940
2766
755c65a368eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
   941
	    __INST(filePointer) = fp = __MKOBJ((INT)f); __STORE(self, fp);
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   942
	    __INST(position) = __MKSMALLINT(1);
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   943
	    ok = true;
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   944
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   945
    }
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   946
%}.
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   947
    ok ifFalse:[
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   948
	"
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   949
	 the open failed for some reason ...
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   950
	"
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   951
	^ self openError
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   952
    ].
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   953
    buffered := true.       "default is buffered"
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
   954
    Lobby register:self.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   955
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   956
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   957
pathName:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   958
    "set the pathname"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   959
3051
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   960
    pathName := filename asString
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   961
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   962
    "Modified: / 28.10.1997 / 14:29:01 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   963
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   964
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   965
pathName:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   966
    "set the pathname starting at aDirectory, a FileDirectory"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   967
3051
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   968
    pathName := aDirectory asFilename constructString:filename
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   969
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   970
    "Modified: / 28.10.1997 / 14:28:54 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   971
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   972
a27a279701f8 Initial revision
claus
parents:
diff changeset
   973
reOpen
a27a279701f8 Initial revision
claus
parents:
diff changeset
   974
    "sent after snapin to reopen streams"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   975
173
58e9778954bc reposition
claus
parents: 159
diff changeset
   976
    |oldPos|
58e9778954bc reposition
claus
parents: 159
diff changeset
   977
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   978
    filePointer notNil ifTrue:[
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   979
	"it was open, when snapped-out"
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   980
	filePointer := nil.
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   981
	Lobby unregister:self.
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   982
	oldPos := position.
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   983
	self open.
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   984
	filePointer isNil ifTrue:[
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   985
	    "/ this happens, if after a restart, 
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   986
	    "/ the file is no longer present or accessable ..."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   987
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   988
	    (self class name , ' [warning]: could not reOpen file: ', pathName) errorPrintCR.
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   989
	] ifFalse:[
3940
2b5888b16c68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3754
diff changeset
   990
	    oldPos notNil ifTrue:[
2b5888b16c68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3754
diff changeset
   991
	        self position:oldPos.
2b5888b16c68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3754
diff changeset
   992
	    ]
2161
0472a226a714 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
   993
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   994
    ]
1088
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
   995
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2078
diff changeset
   996
    "Modified: 10.1.1997 / 17:50:51 / cg"
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   997
!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   998
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   999
setMode:aModeSymbol
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1000
    mode := aModeSymbol
31
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
  1001
! !
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
  1002
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1003
!FileStream methodsFor:'queries'!
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1004
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
  1005
fileSize
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1006
    "return the size in bytes of the file"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1007
3971
aad506cdc5d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3956
diff changeset
  1008
%{
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1009
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1010
#ifdef transputer
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1011
    FILE *f;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1012
    int size;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1013
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
  1014
    if (__INST(filePointer) != nil) {
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
  1015
	f = __FILEVal(__INST(filePointer));
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1016
	if ((size = filesize(fileno(f))) >= 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
  1017
	    RETURN ( __MKSMALLINT(size) );
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1018
	}
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1019
    }
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1020
#else
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1021
    FILE *f;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1022
    struct stat buf;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1023
    int ret;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1024
    int fd;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1025
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
  1026
    if (__INST(filePointer) != nil) {
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
  1027
	f = __FILEVal(__INST(filePointer));
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1028
	fd = fileno(f);
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1029
	do {
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1030
	    ret = fstat(fd, &buf);
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1031
	} while ((ret < 0) && (errno == EINTR));
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1032
	if (ret >= 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
  1033
	    RETURN ( __MKSMALLINT(buf.st_size) );
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1034
	}
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1088
diff changeset
  1035
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1036
    }
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1037
#endif
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1038
%}.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1039
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1040
    "could add a fall-back here:
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1041
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1042
	oldPosition := self position.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1043
	self setToEnd.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1044
	sz := self position.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1045
	self position:oldPosition.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1046
	^ sz
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1047
    "
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1048
    lastErrorNumber notNil ifTrue:[^ self ioError].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1049
    filePointer isNil ifTrue:[^ self errorNotOpen].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1050
    ^ self primitiveFailed
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1051
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1052
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1053
size
2998
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1054
    "return the size of the stream;
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1055
     thats the number of bytes of the file."
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1056
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1057
    "/ no obsoleteMethodWarning - size is ok for streams.
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1058
    "/ self obsoleteMethodWarning:'use #fileSize'.
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1059
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1060
    ^ self fileSize.
2998
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1061
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  1062
    "Modified: 4.10.1997 / 18:01:09 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1064
2
claus
parents: 1
diff changeset
  1065
!FileStream methodsFor:'testing'!
claus
parents: 1
diff changeset
  1066
claus
parents: 1
diff changeset
  1067
isFileStream
claus
parents: 1
diff changeset
  1068
    "return true, if the receiver is some kind of fileStream.
claus
parents: 1
diff changeset
  1069
     redefined from Object"
claus
parents: 1
diff changeset
  1070
claus
parents: 1
diff changeset
  1071
    ^ true
claus
parents: 1
diff changeset
  1072
! !
claus
parents: 1
diff changeset
  1073
1088
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  1074
!FileStream class methodsFor:'documentation'!
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  1075
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  1076
version
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4353
diff changeset
  1077
    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.65 1999-07-15 19:45:33 cg Exp $'
1088
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  1078
! !
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1079
FileStream initialize!