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