FileStream.st
author convert-repo
Thu, 05 Jul 2018 03:33:35 +0000
changeset 23197 823c765c176d
parent 23166 787731fd16e1
child 23429 58f5170cac48
permissions -rw-r--r--
update tags
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22944
0f5a7faced80 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22732
diff changeset
     1
"{ Encoding: utf8 }"
0f5a7faced80 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22732
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
    14
"{ Package: 'stx:libbasic' }"
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
    15
17309
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
    16
"{ NameSpace: Smalltalk }"
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
    17
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
ExternalStream subclass:#FileStream
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
    19
	instanceVariableNames:'pathName canPosition removeOnClose'
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
    20
	classVariableNames:'UserInitiatedFileSaveQuerySignal'
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
    21
	poolDictionaries:''
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
    22
	category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
216
a8abff749575 *** empty log message ***
claus
parents: 173
diff changeset
    25
!FileStream primitiveDefinitions!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
%{
17078
f3ded8a6f9d9 include os defss
Claus Gittinger <cg@exept.de>
parents: 16577
diff changeset
    27
#include "stxOSDefs.h"
f3ded8a6f9d9 include os defss
Claus Gittinger <cg@exept.de>
parents: 16577
diff changeset
    28
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
    29
#undef String
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
    30
#undef Character
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
    31
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    32
#include <stdio.h>
437
claus
parents: 384
diff changeset
    33
#define _STDIO_H_INCLUDED_
claus
parents: 384
diff changeset
    34
10
claus
parents: 5
diff changeset
    35
#include <errno.h>
437
claus
parents: 384
diff changeset
    36
#define _ERRNO_H_INCLUDED_
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
a27a279701f8 Initial revision
claus
parents:
diff changeset
    38
#ifdef transputer
a27a279701f8 Initial revision
claus
parents:
diff changeset
    39
# include <iocntrl.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    40
# ifndef fileno
a27a279701f8 Initial revision
claus
parents:
diff changeset
    41
   /* kludge: inmos forgot fileno */
a27a279701f8 Initial revision
claus
parents:
diff changeset
    42
#  define fileno(f)     ((f)->__file)
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
    43
# endif
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    44
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    45
#else /* not transputer */
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    46
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    47
# include <sys/types.h>
a27a279701f8 Initial revision
claus
parents:
diff changeset
    48
# include <sys/stat.h>
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    49
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    50
#endif /* not transputer */
10
claus
parents: 5
diff changeset
    51
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    52
#ifdef hpux
68
59faa75185ba *** empty log message ***
claus
parents: 49
diff changeset
    53
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
42
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    54
#endif
e33491f6f260 *** empty log message ***
claus
parents: 31
diff changeset
    55
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    56
#ifdef __VMS__
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    57
# include <rms.h>
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    58
#endif
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    59
14635
aa0d74813208 Add __ before STX_String, STX_Character
Stefan Vogel <sv@exept.de>
parents: 14633
diff changeset
    60
#define String  __STX_String
aa0d74813208 Add __ before STX_String, STX_Character
Stefan Vogel <sv@exept.de>
parents: 14633
diff changeset
    61
#define Character __STX_Character
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
    62
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
    63
#ifdef __win32__
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    64
# define NO_STDIO
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
    65
# if defined(__i386__) || defined(__x86__)
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    66
#  define _X86_
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    67
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    68
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    69
# undef INT
10345
f6d031b8edcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10342
diff changeset
    70
# undef UINT
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    71
# undef Array
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    72
# undef Number
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    73
# undef Method
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    74
# undef Point
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    75
# undef Rectangle
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    76
# undef Block
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    77
# undef Time
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    78
# undef Date
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
    79
# undef Set
5910
10a06503f787 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5493
diff changeset
    80
# undef Signal
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
    81
# undef Delay
5910
10a06503f787 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5493
diff changeset
    82
# undef Context
9025
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
    83
# undef Message
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
    84
# undef Process
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
    85
# undef Processor
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
    86
# undef String
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
    87
# undef Character
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    88
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    89
# define NOATOM
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    90
# define NOGDICAPMASKS
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    91
# define NOMETAFILE
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    92
# define NOMINMAX
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    93
//# define NOOPENFILE
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    94
# define NOSOUND
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    95
# define NOWH
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    96
//# define NOCOMM
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    97
# define NOKANJI
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    98
# define NOCRYPT
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
    99
//# define NOMCX
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   100
# define WIN32_LEAN_AND_MEAN
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   101
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   102
# include <windows.h>
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   103
14633
d123ac34e915 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
   104
# if 1 // defined(__MINGW64__)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   105
#  include <fcntl.h>
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   106
# endif
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   107
10450
bb40b56ed6b6 Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents: 10407
diff changeset
   108
# if defined(__BORLANDC__)
bb40b56ed6b6 Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents: 10407
diff changeset
   109
#  include <io.h>
bb40b56ed6b6 Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents: 10407
diff changeset
   110
# else
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   111
#  define lseek _lseek
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   112
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   113
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   114
# ifdef __DEF_Array
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   115
#  define Array __DEF_Array
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   116
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   117
# ifdef __DEF_Number
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   118
#  define Number __DEF_Number
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   119
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   120
# ifdef __DEF_Method
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   121
#  define Method __DEF_Method
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   122
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   123
# ifdef __DEF_Point
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   124
#  define Point __DEF_Point
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   125
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   126
# ifdef __DEF_Block
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   127
#  define Block __DEF_Block
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   128
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   129
# ifdef __DEF_Time
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   130
#  define Time __DEF_Time
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   131
# endif
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   132
# ifdef __DEF_Date
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   133
#  define Date __DEF_Date
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   134
# endif
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   135
# ifdef __DEF_Set
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   136
#  define Set __DEF_Set
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   137
# endif
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   138
# ifdef __DEF_Signal
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   139
#  define Signal __DEF_Signal
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   140
# endif
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   141
# ifdef __DEF_Delay
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   142
#  define Delay __DEF_Delay
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4910
diff changeset
   143
# endif
5910
10a06503f787 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5493
diff changeset
   144
# ifdef __DEF_Context
10a06503f787 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5493
diff changeset
   145
#  define Context __DEF_Context
10a06503f787 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5493
diff changeset
   146
# endif
9025
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   147
# ifdef __DEF_Message
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   148
#  define Message __DEF_Message
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   149
# endif
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   150
# ifdef __DEF_Process
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   151
#  define Process __DEF_Process
e9fff455ecfb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   152
# endif
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   153
# ifdef __DEF_Processor
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   154
#  define Processor __DEF_Processor
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   155
# endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   156
# ifdef __DEF_String
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   157
#  define String __DEF_String
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   158
# endif
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   159
# ifdef __DEF_Character
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   160
#  define Character __DEF_Character
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   161
# endif
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   162
14644
e5f19ef20dcd mingw changes
Claus Gittinger <cg@exept.de>
parents: 14635
diff changeset
   163
# define INT  STX_INT
e5f19ef20dcd mingw changes
Claus Gittinger <cg@exept.de>
parents: 14635
diff changeset
   164
# define UINT STX_UINT
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   165
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   166
# if 0
6259
164d7efc1eb2 api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents: 6244
diff changeset
   167
# ifndef DO_WRAP_CALLS
6267
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   168
#  define STX_C_CALL0(__nm__, __f__)                            __f__((__a1__))
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   169
#  define STX_C_CALL1(__nm__, __f__, __a1__)                    __f__((__a1__))
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   170
#  define STX_C_CALL2(__nm__, __f__, __a1__, __a2__)            __f__((__a1__), (__a2__))
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   171
#  define STX_C_CALL3(__nm__, __f__, __a1__, __a2__, __a3__)    __f__((__a1__), (__a2__), (__a3__))
6259
164d7efc1eb2 api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents: 6244
diff changeset
   172
# else
6267
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   173
#  define STX_C_CALL0(__nm__, __f__)                            __STX_C_CALL0(__nm__, (void*)__f__)
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   174
#  define STX_C_CALL1(__nm__, __f__, __a1__)                    __STX_C_CALL1(__nm__, (void*)__f__, (void*)(__a1__))
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   175
#  define STX_C_CALL2(__nm__, __f__, __a1__, __a2__)            __STX_C_CALL2(__nm__, (void*)__f__, (void*)(__a1__), (void*)(__a2__))
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
   176
#  define STX_C_CALL3(__nm__, __f__, __a1__, __a2__, __a3__)    __STX_C_CALL3(__nm__, (void*)__f__, (void*)(__a1__), (void*)(__a2__), (void*)(__a3__))
6259
164d7efc1eb2 api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents: 6244
diff changeset
   177
# endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14578
diff changeset
   178
# endif
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   179
6259
164d7efc1eb2 api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents: 6244
diff changeset
   180
/* #  define HFILE HANDLE */
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   181
#  define HFILE FILE *
6259
164d7efc1eb2 api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents: 6244
diff changeset
   182
/* #  define fileno(f) f */
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   183
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   184
#else /* not __win32__ */
7970
2ae69eb663eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7965
diff changeset
   185
# define HFILE FILE *
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   186
#endif /* ! __win32__ */
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
   187
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
   188
//#define DO_WRAP_CALL_FSEEK
14853
63ffca691137 fseek does not need a WRAP_CALL (I hope)
Claus Gittinger <cg@exept.de>
parents: 14848
diff changeset
   189
7570
15dfed16d0e4 *** empty log message ***
penk
parents: 7379
diff changeset
   190
#include "stxOSDefs.h"
15dfed16d0e4 *** empty log message ***
penk
parents: 7379
diff changeset
   191
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   192
#ifndef SEEK_SET
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   193
# define SEEK_SET       0
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   194
#endif
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   195
#ifndef SEEK_CUR
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   196
# define SEEK_CUR       1
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   197
#endif
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   198
#ifndef SEEK_END
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   199
# define SEEK_END       2
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 9025
diff changeset
   200
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   201
%}
173
58e9778954bc reposition
claus
parents: 159
diff changeset
   202
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   203
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   204
!FileStream class methodsFor:'documentation'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   205
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   206
copyright
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   207
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   208
 COPYRIGHT (c) 1989 by Claus Gittinger
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   209
	      All Rights Reserved
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   210
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   211
 This software is furnished under a license and may be used
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
 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
   213
 inclusion of the above copyright notice.   This software may not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
 be provided or otherwise made available to, or used by, any
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   215
 other person.  No title to or ownership of the software is
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   216
 hereby transferred.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   220
documentation
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   221
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
    This class provides access to the operating systems underlying file
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   223
    system (i.e. its an interface to the stdio library).
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   224
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
    Notice, that on some systems, the standard I/O library has performance
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
   226
    problems when a file is opened for readwrite.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
    For best results, open files either readonly or writeonly.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   228
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   229
    Also notice, that some OperatingSystems do not fully support
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   230
    positioning a file stream.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   231
    For example, poor VMS does not allow positioning onto arbitrary
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   232
    byte boundaries if the file is a variable-record-RMS file.
15480
9a4e6bbb20d5 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15479
diff changeset
   233
    (stupid enough, this is the default for textfiles as created by some tools ...)
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   234
    Therefore, the instance variable canPosition is set according to
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   235
    this and an error is raised, if a position: is attemted.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   236
    I know, this is ugly, but what else could we do ?
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   237
    Late note: who cares for VMS these days?
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
   238
	       (and how much useless effort has been put in the past,
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
   239
		to support lousy operating systems?)
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   240
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   241
    [instance variables:]
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
   242
	pathName        <String>        the file's path (if known)
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
   243
	canPosition     <Boolean>       positionable - read above comment
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   244
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   245
    [author:]
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
   246
	Claus Gittinger
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   247
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   248
    [see also:]
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
   249
	Filename DirectoryStream PipeStream Socket
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   250
"
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   251
!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   252
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   253
examples
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   254
"
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   255
  for VMS users only:
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   256
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   257
    The #openWithMode:attributes: entry allows additional RMS attributes
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   258
    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
   259
    as described in the 'creat' RTL Library documentation.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   260
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   261
    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
   262
    use:
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   263
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   264
	|newFile|
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   265
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   266
	newFile := FileStream new pathName:'<nameOfFile>'.
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   267
	newFile setMode:#writeonly.
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   268
	newFile openWithMode:'w' attributes:#('rfm=fix' 'fsz=100').
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   269
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   270
    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
   271
    access these from user programs, we recommend subclassing FileStream as
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   272
    something like VMSFixedRecordFileStream, and redefine the instance creation
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
   273
    method(s) there as appropriate.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   274
    This will retain VMS specifics in one place and enhance maintanability.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   275
"
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
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   278
!FileStream class methodsFor:'initialization'!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   279
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   280
initialize
7379
3eba1d6dd8d3 Raise an error when open fails
Stefan Vogel <sv@exept.de>
parents: 7298
diff changeset
   281
    UserInitiatedFileSaveQuerySignal isNil ifTrue:[
7965
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   282
	"/
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   283
	"/ this is temporary - for now allow an openError to
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   284
	"/ be unhandled and proceed by returning a nil from the
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   285
	"/ stream creation method.
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   286
	"/ In the future, this will be a hard signal.
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   287
	"/ THE FUTURE IS NOW!!!!
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   288
	"/
7379
3eba1d6dd8d3 Raise an error when open fails
Stefan Vogel <sv@exept.de>
parents: 7298
diff changeset
   289
"/        OpenErrorSignal := QuerySignal new.
3eba1d6dd8d3 Raise an error when open fails
Stefan Vogel <sv@exept.de>
parents: 7298
diff changeset
   290
"/        OpenErrorSignal parent:(super openErrorSignal) mayProceed:true.
3eba1d6dd8d3 Raise an error when open fails
Stefan Vogel <sv@exept.de>
parents: 7298
diff changeset
   291
"/        OpenErrorSignal nameClass:self message:#openErrorSignal.
3eba1d6dd8d3 Raise an error when open fails
Stefan Vogel <sv@exept.de>
parents: 7298
diff changeset
   292
"/        OpenErrorSignal notifierString:'open error'.
4907
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   293
7965
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   294
	UserInitiatedFileSaveQuerySignal := QuerySignal new defaultAnswer:true.
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   295
	UserInitiatedFileSaveQuerySignal nameClass:self message:#userInitiatedFileSaveQuerySignal.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   296
    ]
3006
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   297
b3530950854a use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents: 2998
diff changeset
   298
    "Modified: 8.10.1997 / 11:56:39 / cg"
2921
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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   301
!FileStream class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   302
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
appendingOldFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
    "return a FileStream for existing file named filename, aString.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
     The file is opened for writeonly access."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   306
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   307
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   308
    |newStream|
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   309
2
claus
parents: 1
diff changeset
   310
    newStream := self new pathName:filename.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   311
    ^ newStream openForAppending.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   312
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   313
    "
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   314
     FileStream appendingOldFileNamed:'adasdasasd'
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   315
    "
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
appendingOldFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   319
    "return a FileStream for existing file named filename, aString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
     in aDirectory, a FileDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
     The file is opened for writeonly access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
    newStream := self new pathName:filename in:aDirectory.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   325
    ^ newStream openForAppending.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   326
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   327
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
fileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   329
    "return a stream on file filename - if the file does not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
     already exist, create it.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   331
     The file is opened for read/write access."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   332
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   333
    [
7965
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   334
	^ self oldFileNamed:filename.
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   335
    ] on:self openErrorSignal do:[:ex| ].
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   337
    ^ self newFileNamed:filename
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
fileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
    "return a stream on file filename - if the file does not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   342
     already exist, create it.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   343
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   344
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   345
    [
7965
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   346
	^ self oldFileNamed:filename in:aDirectory.
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   347
    ] on:self openErrorSignal do:[:ex| ].
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   348
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   349
    ^ self newFileNamed:filename in:aDirectory
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   350
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   351
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   352
newFileForWritingNamed:filename
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   353
    "return a FileStream for new file named filename, aString.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   354
     If the file exists, it is truncated, otherwise created.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   355
     The file is opened for writeonly access."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   356
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   357
    |newStream|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   358
    newStream := self new pathName:filename.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   359
    ^ newStream createForWriting.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   360
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   361
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   362
newFileForWritingNamed:filename in:aDirectory
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   363
    "return a FileStream for new file named filename, aString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   364
     in aDirectory, a FileDirectory.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   365
     If the file exists, it is truncated, otherwise created.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   366
     The file is opened for writeonly access."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   367
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   368
    |newStream|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   369
    newStream := self new pathName:filename in:aDirectory.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   370
    ^ newStream createForWriting.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   371
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   372
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   373
newFileNamed:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   374
    "return a FileStream for new file named filename, aString.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   375
     If the file exists, it is truncated, otherwise created.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   376
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   377
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   378
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   379
    newStream := self new pathName:filename.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   380
    ^ newStream createForReadWrite.
3051
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   381
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   382
    "Modified: / 28.10.1997 / 14:28:08 / cg"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   383
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   384
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   385
newFileNamed:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   386
    "return a FileStream for new file named filename, aString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   387
     in aDirectory, a FileDirectory.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   388
     If the file exists, it is truncated, otherwise created.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   389
     The file is opened for read/write access."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   390
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   391
    |newStream|
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   392
    newStream := self new pathName:filename in:aDirectory.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   393
    ^ newStream createForReadWrite.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   394
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   395
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   396
newTemporary
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   397
    "create atomically a new file and return the file stream - use this for temporary files.
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   398
     The created file has the name '/tmp/stxtmp_xx_nn' where xx is our
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   399
     unix process id, and nn is a unique number, incremented with every call to this method.
23045
774a133e168c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22944
diff changeset
   400
     If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set,
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   401
     its value defines the temp directory."
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   402
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   403
    ^ self newTemporaryIn:Filename tempDirectory
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   404
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   405
    "
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   406
     FileStream newTemporary
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   407
     FileStream newTemporary
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   408
    "
23045
774a133e168c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22944
diff changeset
   409
774a133e168c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22944
diff changeset
   410
    "Modified (comment): / 31-05-2018 / 09:58:04 / Claus Gittinger"
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   411
!
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   412
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   413
newTemporaryIn:aDirectoryOrNil
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   414
    "create atomically a new file and return the file stream - use this for temporary files.
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   415
     The created file is in aDirectoryPrefix and named 'stxtmp_xx_nn',
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   416
     where xx is our unix process id, and nn is a unique number, incremented
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   417
     with every call to this method."
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   418
22944
0f5a7faced80 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22732
diff changeset
   419
    ^ self newTemporaryIn:aDirectoryOrNil nameTemplate:(Filename tempFileNameTemplate)
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   420
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   421
    "temp files in '/tmp':
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   422
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   423
     FileStream newTemporary
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   424
    "
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   425
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   426
    "temp files somewhere
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   427
     (not recommended - use above since it can be controlled via shell variables):
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   428
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   429
     FileStream newTemporaryIn:'/tmp'
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   430
     FileStream newTemporaryIn:'/tmp'
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   431
     FileStream newTemporaryIn:'/usr/tmp'
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   432
     FileStream newTemporaryIn:'/'
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   433
    "
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   434
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   435
    "a local temp file:
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   436
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   437
     FileStream newTemporaryIn:''
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   438
     FileStream newTemporaryIn:nil
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   439
     FileStream newTemporaryIn:'.'
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   440
     FileStream newTemporaryIn:('source' asFilename)
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   441
    "
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   442
!
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   443
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   444
newTemporaryIn:aDirectoryOrNil nameTemplate:template
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   445
    "create atomically a new file and return the file stream - use this for temporary files.
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   446
     The created file is in aDirectoryOrNil and named after the given template,
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   447
     in which %1 and %2 are expanded to the unix process id, and a unique number, incremented
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   448
     with every call to this method respectively.
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   449
     See also: #newTemporary which looks for a good temp directory."
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   450
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   451
    |nameString random prevRandom prevNameString newTempFilename stream|
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   452
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   453
    [
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   454
	prevRandom := random.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   455
	prevNameString := nameString.
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   456
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   457
	"Use random numbers in order to improve the security
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   458
	 by making the generated names less predictable"
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   459
	[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   460
	    random := RandomGenerator nextLettersOrDigits:4.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   461
	] doWhile:[random = prevRandom].
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   462
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   463
	nameString := template bindWith:(OperatingSystem getProcessId) with:random.
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   464
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   465
	aDirectoryOrNil isNil ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   466
	    newTempFilename := nameString.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   467
	] ifFalse:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   468
	    newTempFilename := aDirectoryOrNil asFilename constructString:nameString.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   469
	].
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   470
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   471
	[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   472
	    stream := self open:newTempFilename withMode:#(CREATE_NEW GENERIC_READ_WRITE).
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   473
	] on:OpenError do:[:ex|
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   474
	   ex errorCategory ~~ #existingReferentSignal ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   475
		"some fundamental error, raise exception"
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   476
		ex reject.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   477
	    ].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   478
	    prevNameString = nameString ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   479
		"no more names - probably a bad template"
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   480
		ex reject.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   481
	    ].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   482
	    "file exists, retry another one"
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   483
	].
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   484
    ] doWhile:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   485
	stream isNil and:[prevNameString ~= nameString]   "/ if namestring didn't change, the template is bad
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   486
    ].
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   487
    ^ stream
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   488
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   489
    "temp files in '/tmp':
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   490
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   491
	FileStream newTemporaryIn:'/tmp' asFilename nameTemplate:'foo%1_%2'
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   492
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   493
     This must fail on the second try:
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   494
	FileStream newTemporaryIn:'/tmp' asFilename nameTemplate:'foo'
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
   495
	FileStream newTemporaryIn:'c:\temp' asFilename nameTemplate:'foo'
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   496
    "
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   497
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   498
    "temp files somewhere
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   499
     (not recommended - use above since it can be controlled via shell variables):
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   500
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   501
     FileStream newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   502
     FileStream newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   503
     FileStream newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   504
     FileStream newTemporaryIn:'/'        nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   505
    "
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   506
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   507
    "a local temp file:
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   508
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   509
     FileStream newTemporaryIn:''             nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   510
     FileStream newTemporaryIn:nil            nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   511
     FileStream newTemporaryIn:'.'            nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   512
     FileStream newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2'
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   513
    "
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   514
!
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   515
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   516
newTemporaryIn:aDirectoryOrNil withSuffix:aSuffixString
15469
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   517
    "create atomically a new file and return the file stream - use this for temporary files.
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   518
     The created file is in aDirectoryPrefix and named 'stxtmp_xx_nn',
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   519
     where xx is our unix process id, and nn is a unique number, incremented
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   520
     with every call to this method."
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   521
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   522
    ^ self
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   523
	newTemporaryIn:aDirectoryOrNil
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   524
	nameTemplate:(Filename tempFileNameTemplate asFilename
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   525
					withSuffix:aSuffixString) asString
15469
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   526
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   527
    "
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   528
     FileStream newTemporaryWithSuffix:'txt'
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   529
     FileStream newTemporaryIn:'/tmp' withSuffix:'txt'
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   530
    "
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   531
!
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   532
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   533
newTemporaryWithSuffix:aString
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   534
    "create atomically a new file and return the file stream - use this for temporary files.
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   535
     The created file has the name '/tmp/stxtmp_xx_nn' where xx is our
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   536
     unix process id, and nn is a unique number, incremented with every call to this method.
23045
774a133e168c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22944
diff changeset
   537
     If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set,
15469
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   538
     its value defines the temp directory."
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   539
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   540
    ^ self newTemporaryIn:Filename tempDirectory withSuffix:aString
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   541
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   542
    "
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   543
     FileStream newTemporaryWithSuffix:'txt'
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   544
    "
23045
774a133e168c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22944
diff changeset
   545
774a133e168c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22944
diff changeset
   546
    "Modified (comment): / 31-05-2018 / 09:58:01 / Claus Gittinger"
15469
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   547
!
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   548
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   549
oldFileNamed:filename
a27a279701f8 Initial revision
claus
parents:
diff changeset
   550
    "return a FileStream for existing file named filename, aString.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   551
     The file is opened for read/write access.
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   552
     Raises an error if the file does not exist."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   553
a27a279701f8 Initial revision
claus
parents:
diff changeset
   554
    |newStream|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   555
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   556
"/ We can do the following, but is is an extra OS-systemcall:
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   557
"/    (OperatingSystem isReadable:filename) ifFalse:[^ self new openError].
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   558
2
claus
parents: 1
diff changeset
   559
    newStream := self new pathName:filename.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   560
    newStream readwrite.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   561
    ^ newStream openForReadWrite.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   562
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   563
    "
15489
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   564
     '/tmp/dAsGiBtEsNiChT' asFilename remove.
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   565
     FileStream oldFileNamed:'/tmp/dAsGiBtEsNiChT'
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   566
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   567
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   568
a27a279701f8 Initial revision
claus
parents:
diff changeset
   569
oldFileNamed:filename in:aDirectory
a27a279701f8 Initial revision
claus
parents:
diff changeset
   570
    "return a FileStream for existing file named filename, aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   571
     in aDirectory, a FileDirectory.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   572
     The file is opened for read/write access.
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   573
     Raises an error if the file does not exist."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   574
a27a279701f8 Initial revision
claus
parents:
diff changeset
   575
    |newStream|
2
claus
parents: 1
diff changeset
   576
    newStream := self new pathName:filename in:aDirectory.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   577
    ^ newStream openForReadWrite.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   578
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   579
    "
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   580
     FileStream oldFileNamed:'dAsGiBtEsNiChT' in:'/'
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   581
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   582
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   583
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   584
open:aFilenameString withMode:anArrayOrString
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   585
    "The argument de
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   586
     The file is opened for read/write access."
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   587
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   588
    |stream|
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   589
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   590
    stream := self new pathName:aFilenameString.
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   591
    stream
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   592
	readwrite;        "/ assume read/write mode, but this depends on the args
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   593
	openWithMode:anArrayOrString attributes:nil.
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   594
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   595
    ^ stream
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   596
!
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
   597
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
readonlyFileNamed:filename
20157
98d5b57a7576 #OTHER by mawalch
mawalch
parents: 20096
diff changeset
   599
    "Return a readonly FileStream for existing file named filename, a String.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   600
     Raises an error if the file does not exist."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   601
a27a279701f8 Initial revision
claus
parents:
diff changeset
   602
    |newStream|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   603
20157
98d5b57a7576 #OTHER by mawalch
mawalch
parents: 20096
diff changeset
   604
"/ We can do the following, but it is an extra system call:
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   605
"/    (OperatingSystem isReadable:filename) ifFalse:[^ self new openError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   606
2
claus
parents: 1
diff changeset
   607
    newStream := self new pathName:filename.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   608
    ^ newStream openForReading.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   609
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   610
    "
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
   611
     FileStream readonlyFileNamed:'dAsGiBtEsNiChT'
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   612
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   613
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   614
a27a279701f8 Initial revision
claus
parents:
diff changeset
   615
readonlyFileNamed:filename in:aDirectory
a27a279701f8 Initial revision
claus
parents:
diff changeset
   616
    "return a readonly FileStream for existing file named filename, aString
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   617
     in aDirectory, a fileName or string instance representing a directory.
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   618
     Raises an error if the file does not exist."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   619
a27a279701f8 Initial revision
claus
parents:
diff changeset
   620
    |newStream|
2
claus
parents: 1
diff changeset
   621
    newStream := self new pathName:filename in:aDirectory.
8508
68cd95545196 Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents: 8472
diff changeset
   622
    ^ newStream openForReading.
7827
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   623
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   624
    "
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   625
     FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/'
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   626
     FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/' asFilename
4f2f905d1c93 comment
Claus Gittinger <cg@exept.de>
parents: 7570
diff changeset
   627
    "
159
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   628
! !
514c749165c3 *** empty log message ***
claus
parents: 92
diff changeset
   629
7298
9b3c69eb2c5d category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   630
!FileStream class methodsFor:'Compatibility-ANSI'!
6586
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   631
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   632
write:filename
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   633
    "return a FileStream for new file named filename, aString.
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   634
     If the file exists, it is truncated, otherwise created.
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   635
     The file is opened for read/write access.
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   636
     Same as newFileNamed: for ANSI compatibilily"
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   637
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   638
    ^ self newFileNamed:filename
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   639
! !
0c9731524c07 added for ansi compatibiliy
penk
parents: 6488
diff changeset
   640
7298
9b3c69eb2c5d category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   641
!FileStream class methodsFor:'Compatibility-Dolphin'!
6244
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   642
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   643
read:filename text:text
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   644
    "return a readonly FileStream for the existing file named filename, aString.
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   645
     If the argument, text is false, the stream is setup to read binary bytes,
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   646
     if false, it reads characters."
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   647
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   648
    |s|
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   649
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   650
    s := self readOnlyFileNamed:filename.
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   651
    text ifTrue:[
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   652
	s text
6244
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   653
    ] ifFalse:[
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   654
	s binary
6244
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   655
    ].
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   656
    ^ s
6474
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   657
!
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   658
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   659
write:filename mode:modeSymbol
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   660
    "return a writable FileStream for the file named filename, aString.
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   661
     The modeSymbol controls how the file is opened; currently supported are:
7965
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   662
	#append
6474
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   663
    "
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   664
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   665
    modeSymbol == #append ifTrue:[
7965
fe275967a21c win32: do not pass pointers into OBJMEM to api calls
ca
parents: 7883
diff changeset
   666
	^ self appendingOldFileNamed:filename
6474
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   667
    ].
7091
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   668
    "/ self openErrorSignal is a Notification. This will change..
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   669
    "/ We want to raise a real error here
b399f3d19084 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7053
diff changeset
   670
    super openErrorSignal raiseRequestErrorString:' - unsupported mode'.
6474
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   671
    ^ nil
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   672
!
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   673
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   674
write:filename text:textModeBoolean
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   675
    "return a writable FileStream for the file named filename, aString.
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   676
     If the argument, text is false, the stream is setup to write binary bytes,
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   677
     if false, it writes characters."
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   678
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   679
    |s|
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   680
6475
64529b4dc41b dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6474
diff changeset
   681
    s := self newFileNamed:filename.
6474
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   682
    s notNil ifTrue:[
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   683
	textModeBoolean ifTrue:[
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   684
	    s text
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   685
	] ifFalse:[
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   686
	    s binary
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
   687
	]
6474
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   688
    ].
92a666c5b104 dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6464
diff changeset
   689
    ^ s
6244
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   690
! !
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   691
7298
9b3c69eb2c5d category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   692
!FileStream class methodsFor:'Compatibility-Squeak'!
5186
ed0c5597034f category renamining
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
   693
19638
9ca7425d4ef2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19363
diff changeset
   694
fileIn:aPath
9ca7425d4ef2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19363
diff changeset
   695
    aPath asFilename fileIn
9ca7425d4ef2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19363
diff changeset
   696
!
9ca7425d4ef2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19363
diff changeset
   697
16109
0e7d694bfc7a class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15620
diff changeset
   698
forceNewFileNamed:filename
0e7d694bfc7a class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15620
diff changeset
   699
    "return a writing FileStream for new file named filename, aString.
16113
411bfb1ec52c class: FileStream
Claus Gittinger <cg@exept.de>
parents: 16109
diff changeset
   700
     If it already exists, it is overwritten silently."
16109
0e7d694bfc7a class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15620
diff changeset
   701
0e7d694bfc7a class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15620
diff changeset
   702
    ^ self newFileNamed:filename
0e7d694bfc7a class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15620
diff changeset
   703
!
0e7d694bfc7a class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15620
diff changeset
   704
5186
ed0c5597034f category renamining
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
   705
readOnlyFileNamed:filename
6244
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   706
    "return a readonly FileStream for the existing file named filename, aString."
48163a4cd89e dolphin support
Claus Gittinger <cg@exept.de>
parents: 6170
diff changeset
   707
5186
ed0c5597034f category renamining
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
   708
    ^ self readonlyFileNamed:filename
23165
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   709
!
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   710
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   711
readOnlyFileNamed:filename do:aBlock
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   712
    "open a readonly stream on filename and evaluate aBlock with it.
23166
787731fd16e1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23165
diff changeset
   713
     Return the value from aBlock.        
23165
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   714
     Ensures that the stream is closed afterwards"
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   715
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   716
    ^ filename asFilename readingFileDo:aBlock
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   717
0a6eb6d342d8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23045
diff changeset
   718
    "Created: / 01-07-2018 / 12:45:19 / Claus Gittinger"
5186
ed0c5597034f category renamining
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
   719
! !
ed0c5597034f category renamining
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
   720
7298
9b3c69eb2c5d category
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   721
!FileStream class methodsFor:'Compatibility-VW'!
6170
c00688d17b16 + #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents: 5910
diff changeset
   722
c00688d17b16 + #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents: 5910
diff changeset
   723
badArgumentsSignal
c00688d17b16 + #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents: 5910
diff changeset
   724
    ^ Error
c00688d17b16 + #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents: 5910
diff changeset
   725
! !
c00688d17b16 + #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents: 5910
diff changeset
   726
3233
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   727
!FileStream class methodsFor:'Signal constants'!
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   728
4907
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   729
userInitiatedFileSaveQuerySignal
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   730
    "return the query signal, which is raised before a user-initiated
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   731
     file-save / file-saveAs operation is performed.
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   732
     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
   733
     written to.
21751
b7dd1744373d #DOCUMENTATION by mawalch
mawalch
parents: 21623
diff changeset
   734
     The default signal here returns true, which will grant the save.
4907
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   735
     End-user applications may want to catch this signal,
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   736
     and only return true for certain directories."
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   737
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   738
    ^ UserInitiatedFileSaveQuerySignal
0b09209a95c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4526
diff changeset
   739
21751
b7dd1744373d #DOCUMENTATION by mawalch
mawalch
parents: 21623
diff changeset
   740
    "Modified (comment): / 16-05-2017 / 18:13:28 / mawalch"
3233
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   741
! !
1d29ae45b333 Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3231
diff changeset
   742
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7100
diff changeset
   743
!FileStream methodsFor:'Compatibility-Squeak'!
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   744
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   745
fullName
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   746
    "Squeak compatibility: return the full pathname"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   747
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   748
    ^ pathName asFilename pathName
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   749
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   750
    "Created: 17.10.1997 / 17:04:12 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   751
    "Modified: 20.10.1997 / 19:22:44 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   752
! !
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   753
15489
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   754
!FileStream methodsFor:'access rights'!
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   755
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   756
accessRights
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   757
    "return the access rights of the file as opaque data
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   758
     (SmallInteger in unix/linux)"
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   759
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   760
    ^ OperatingSystem accessModeOfFd:self fileDescriptor.
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   761
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   762
    "
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   763
      'Make.proto' asFilename readingFileDo:[:s|
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
   764
	  s accessRights
15489
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   765
      ]
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   766
    "
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   767
!
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   768
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   769
accessRights:opaqueData
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   770
    "set the access rights of the file to opaqueData,
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   771
     which is normally retrieved by Filename>>#accessRights
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   772
     or FileStreamm>>#accessRights."
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   773
21237
d2ad73cbbee4 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21004
diff changeset
   774
    (OperatingSystem changeAccessModeOfFd:self fileHandle to:opaqueData) ifFalse:[
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   775
	OperatingSystem accessDeniedErrorSignal
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   776
	    raiseRequestWith:self
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   777
	    errorString:(' - cannot change access rights: ' , self pathName).
15489
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   778
    ].
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   779
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   780
    "
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   781
      'Make.proto' asFilename readingFileDo:[:s|
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   782
	  s accessRights:s accessRights
15489
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   783
      ]
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   784
    "
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   785
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   786
    "
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   787
      '/' asFilename readingFileDo:[:s|
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   788
	  s accessRights:s accessRights
15489
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   789
      ]
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   790
    "
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   791
! !
6b39f710c80d class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15486
diff changeset
   792
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   793
!FileStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   794
17309
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
   795
asFilename
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
   796
    "return the file name"
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
   797
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
   798
    ^ pathName asFilename
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
   799
!
cbe100c27478 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17151
diff changeset
   800
22570
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   801
baseName
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   802
    "return my name without leading direcory-path (i.e. the plain fileName)
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   803
     as a string"
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   804
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   805
    ^ pathName asFilename baseName
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   806
!
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   807
12950
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   808
contentsOfEntireFile
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   809
    "ST-80 compatibility: return contents as a String (or byteArray, if in binary mode).
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   810
     See also #contents, which returns the lines as stringCollection for text files."
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   811
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   812
    position == 0 ifTrue:[
13778
8e34483d10dd MAXPATHLEN cleanup;
Claus Gittinger <cg@exept.de>
parents: 13051
diff changeset
   813
	^ self next:(self fileSize)
12950
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   814
    ].
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   815
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   816
    ^ super contentsOfEntireFile
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   817
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   818
    "Created: / 18-07-2010 / 22:17:49 / cg"
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   819
!
5a6dbcf1a274 added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 12711
diff changeset
   820
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   821
directoryName
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   822
    "return the name of the directory I'm in as a string"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   823
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   824
    ^ pathName asFilename directoryName
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   825
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   826
11437
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
   827
fileName
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
   828
    "return the file name - same as pathName for compatibility with
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
   829
     other smalltalks"
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
   830
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
   831
    ^ pathName asFilename
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
   832
!
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
   833
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   834
name
22570
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   835
    "return my path name as a string"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   836
22570
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   837
    "/ ^ self baseName
5a714ab80207 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22151
diff changeset
   838
    ^ self pathName
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   839
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   840
a27a279701f8 Initial revision
claus
parents:
diff changeset
   841
pathName
a27a279701f8 Initial revision
claus
parents:
diff changeset
   842
    "return the pathname"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   843
a27a279701f8 Initial revision
claus
parents:
diff changeset
   844
    ^ pathName
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   845
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   846
3754
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   847
removeOnClose:aBoolean
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   848
    "set/clear the removeOnClose flag.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   849
     If set, the file will be removed when closed.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   850
     Provided mostly for OS's which do not allow an
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   851
     open file to be removed (i.e. non unixes),
12207
cb911af5184f comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents: 11813
diff changeset
   852
     when a fileStream for a tempFile is used.
3754
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   853
     Especially, the CVS-SourceCodeManager returns
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   854
     this kind of file-handles occasionally.
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   855
     This is an ST/X special feature which is not portable
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   856
     to other systems."
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   857
15475
763fdc270fb8 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15474
diff changeset
   858
    removeOnClose := aBoolean.
18781
58f9cf53b2ae #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18651
diff changeset
   859
    self reRegisterForFinalization.
3754
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   860
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   861
    "Modified: / 13.8.1998 / 12:10:07 / cg"
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   862
!
e281b9479361 added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents: 3233
diff changeset
   863
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   864
store:something
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   865
    "what really should this do"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   866
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   867
    self nextPutAll:something storeString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   868
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   869
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   870
!FileStream methodsFor:'error handling'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   871
12687
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   872
openError:errorNumber
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   873
    "report an error, that file open failed"
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   874
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   875
    "This has changed from previous releases:
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   876
     in earlier versions of ST/X, failed file open operations
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   877
     returned nil - now, an error is raised.
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   878
     The old behavior is simulated by providing an exception
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   879
     handler, which proceeds with nil:
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   880
13778
8e34483d10dd MAXPATHLEN cleanup;
Claus Gittinger <cg@exept.de>
parents: 13051
diff changeset
   881
	OpenError ignoreIn:[
8e34483d10dd MAXPATHLEN cleanup;
Claus Gittinger <cg@exept.de>
parents: 13051
diff changeset
   882
	    'old code expecting nil return values on errors when doing an open'.
12687
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   883
13778
8e34483d10dd MAXPATHLEN cleanup;
Claus Gittinger <cg@exept.de>
parents: 13051
diff changeset
   884
	    ('/dasGIBtEsbeStimmtNiChT' asFilename readStream) isNil ifTrue:[
8e34483d10dd MAXPATHLEN cleanup;
Claus Gittinger <cg@exept.de>
parents: 13051
diff changeset
   885
		self warn:'open failed'.
8e34483d10dd MAXPATHLEN cleanup;
Claus Gittinger <cg@exept.de>
parents: 13051
diff changeset
   886
	    ].
8e34483d10dd MAXPATHLEN cleanup;
Claus Gittinger <cg@exept.de>
parents: 13051
diff changeset
   887
	]
12687
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   888
    "
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   889
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   890
    "{ Pragma: +optSpace }"
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   891
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   892
    LastErrorNumber := errorNumber.
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   893
    ^ super openError:errorNumber.
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   894
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   895
    "
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   896
     '/dasGIBtEsbeStimmtNiChT' asFilename readStream
db30e2741635 added: #openError:
Stefan Vogel <sv@exept.de>
parents: 12675
diff changeset
   897
    "
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   898
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   899
15469
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   900
!FileStream methodsFor:'finalization'!
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   901
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   902
executor
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   903
    |executor|
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   904
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   905
    executor := super executor.
18985
3dc624c18346 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18784
diff changeset
   906
    "keep the pathname for any FileStream"
3dc624c18346 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18784
diff changeset
   907
    executor setPathName:pathName removeOnClose:removeOnClose.
15469
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   908
    ^ executor
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   909
! !
93ba2e2700b0 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15462
diff changeset
   910
20367
e59fe9911b4a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20157
diff changeset
   911
8362
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   912
!FileStream methodsFor:'misc functions'!
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   913
8768
Claus Gittinger <cg@exept.de>
parents: 8627
diff changeset
   914
copyToEndInto:outStream bufferSize:bufferSize
8362
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   915
    "copy the data into another stream."
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   916
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   917
    |pos n nWritten|
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   918
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   919
    "the sendfile() system call currently (2004-05-07) handles only descriptors that
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   920
     support mmap-like operations as from-fd.
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   921
     Therefore, this method is reimplemented here (from ExternalStream)"
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   922
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   923
    outStream isExternalStream ifTrue:[
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   924
	pos := self position.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   925
	n := self size - pos.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   926
	nWritten := OperatingSystem
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   927
			copyFromFd:self fileHandle
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   928
			toFd:outStream fileHandle
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   929
			startIndex:pos
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   930
			count:n.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   931
	nWritten > 0 ifTrue:[
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   932
	    self position:pos+nWritten.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   933
	].
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   934
	nWritten = n ifTrue:[
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   935
	    ^ self
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
   936
	].
8362
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   937
    ].
8768
Claus Gittinger <cg@exept.de>
parents: 8627
diff changeset
   938
    ^ super copyToEndInto:outStream bufferSize:bufferSize.
8362
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   939
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   940
    "
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   941
     |in out|
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   942
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   943
     in := 'Makefile' asFilename readStream.
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   944
     out := Stdout.
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   945
     in copyToEndInto:out.
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   946
     in close.
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
   947
    "
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   948
!
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   949
17151
2b1e0d36cd6f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17144
diff changeset
   950
syncFileSystem
2b1e0d36cd6f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17144
diff changeset
   951
    "sync the filesystem containing this FileStream"
2b1e0d36cd6f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17144
diff changeset
   952
2b1e0d36cd6f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17144
diff changeset
   953
    OperatingSystem syncFileSystem:handle.
2b1e0d36cd6f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17144
diff changeset
   954
!
2b1e0d36cd6f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17144
diff changeset
   955
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   956
truncateTo:newSize
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   957
    "truncate the underlying OS file to newSize.
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   958
     Warning: this may not be implemented on all platforms."
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   959
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   960
%{
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   961
#ifdef HAS_FTRUNCATE
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   962
    OBJ fp = __INST(handle);
16373
9b9827530bf4 Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents: 16369
diff changeset
   963
    FILE *f;
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   964
    off_t truncateSize;
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   965
16373
9b9827530bf4 Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents: 16369
diff changeset
   966
    if ((fp != nil) && (__INST(mode) != @symbol(readonly))) {
22151
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   967
        if (__isSmallInteger(newSize)) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   968
            truncateSize = __intVal(newSize);
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   969
            if (truncateSize < 0) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   970
                goto getOutOfHere;
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   971
            }
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   972
        } else {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   973
            truncateSize = __signedLongIntVal(newSize);
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   974
            if (truncateSize < 0) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   975
                goto getOutOfHere;
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   976
            }
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   977
            if (truncateSize == 0) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   978
                if (sizeof(truncateSize) == 8) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   979
                    if (__signedLong64IntVal(newSize, &truncateSize) == 0 || truncateSize < 0) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   980
                        goto getOutOfHere;
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   981
                    }
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   982
                } else {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   983
                    goto getOutOfHere;
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   984
                }
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   985
            }
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   986
        }
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   987
22151
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   988
        f = __FILEVal(fp);
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   989
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   990
        if (__INST(buffered) == true) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   991
            fflush(f);
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   992
            fseek(f, 0L, SEEK_END); /* needed in stdio */
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   993
        }
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   994
        ftruncate(fileno(f), truncateSize);
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
   995
22151
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   996
        // oops - must also position
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   997
        if (__INST(buffered) == true) {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   998
            fseek(f, truncateSize, SEEK_SET);
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
   999
        } else {
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1000
            lseek(fileno(f), truncateSize, SEEK_SET);
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1001
        }
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1002
        __INST(position) = newSize; __STORE(self, newSize);
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1003
        
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1004
        RETURN (self);
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1005
    }
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1006
getOutOfHere: ;
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1007
#endif
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1008
%}.
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1009
    handle isNil ifTrue:[self errorNotOpen. ^ self].
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1010
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1011
    newSize < 0 ifTrue:[
22151
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1012
        self error:'wrong arg'.
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1013
    ].
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1014
    self errorUnsupportedOperation
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1015
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1016
    "
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1017
     |f s|
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1018
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1019
     f := 'testTTTT' asFilename.
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1020
     s := f writeStream.
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1021
     s next:1000 put:$a.
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1022
     s truncateTo:100.
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1023
     s close.
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1024
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1025
     Transcript showCR:(f fileSize).
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1026
     f remove.
16369
a938f5cbc31d Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents: 16298
diff changeset
  1027
    "
22151
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1028
b8987fce8273 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21751
diff changeset
  1029
    "Modified: / 02-08-2017 / 09:44:32 / cg"
8362
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
  1030
! !
e17d9ffb6fa8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8063
diff changeset
  1031
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1032
!FileStream methodsFor:'positioning'!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1033
15620
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1034
position
7053
13e04c48e23c prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
  1035
    "return the read/write position in the file"
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1036
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1037
    |error|
3971
aad506cdc5d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3956
diff changeset
  1038
%{
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  1039
    HFILE f;
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
  1040
    off_t currentPosition;
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1041
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1042
    if (__INST(handle) != nil) {
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1043
	do {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1044
	    f = __FILEVal(__INST(handle));
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1045
#ifdef __win32__
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1046
	    __threadErrno = 0;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1047
	    if (__INST(buffered) == true) {
6333
9682533bce75 win32 fixes
Claus Gittinger <cg@exept.de>
parents: 6267
diff changeset
  1048
# if 0
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1049
		currentPosition = STX_C_CALL1( "ftell", ftell, f);
6333
9682533bce75 win32 fixes
Claus Gittinger <cg@exept.de>
parents: 6267
diff changeset
  1050
# else
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1051
		currentPosition = ftell(f);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1052
		__threadErrno = errno;
6333
9682533bce75 win32 fixes
Claus Gittinger <cg@exept.de>
parents: 6267
diff changeset
  1053
# endif
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1054
	    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1055
		OBJ rA = __INST(readAhead);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1056
		off_t offs = 0;
6333
9682533bce75 win32 fixes
Claus Gittinger <cg@exept.de>
parents: 6267
diff changeset
  1057
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1058
		if (rA != nil) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1059
		    __INST(readAhead) = nil;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1060
		    offs = -1;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1061
		}
6333
9682533bce75 win32 fixes
Claus Gittinger <cg@exept.de>
parents: 6267
diff changeset
  1062
# if 0
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1063
		currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR);
6333
9682533bce75 win32 fixes
Claus Gittinger <cg@exept.de>
parents: 6267
diff changeset
  1064
# else
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1065
		currentPosition = lseek(fileno(f), offs, SEEK_CUR);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1066
		__threadErrno = errno;
6333
9682533bce75 win32 fixes
Claus Gittinger <cg@exept.de>
parents: 6267
diff changeset
  1067
# endif
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1068
	    }
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1069
#else /* !__win32__ */
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1070
	    if (__INST(buffered) == true) {
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1071
#ifdef _LFS_LARGEFILE
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1072
		currentPosition = ftello(f);
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1073
#else
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1074
		currentPosition = ftell(f);
8039
6ef0379296cc #position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents: 8034
diff changeset
  1075
#endif /* ! _LFS_LARGEFILE */
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1076
	    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1077
		currentPosition = lseek(fileno(f), (off_t)0, SEEK_CUR);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1078
	    }
8039
6ef0379296cc #position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents: 8034
diff changeset
  1079
#endif /* !WIN32 */
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1080
	} while ((currentPosition < 0) && (__threadErrno == EINTR));
6267
10016cc16511 pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents: 6259
diff changeset
  1081
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1082
	if (currentPosition >= 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1083
	    OBJ rslt;
7872
634e73a5cdd9 preps for 64bit positions
Claus Gittinger <cg@exept.de>
parents: 7871
diff changeset
  1084
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1085
	    if (sizeof(currentPosition) == 8) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1086
		rslt = __MKINT64 (&currentPosition);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1087
	    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1088
		rslt = __MKINT(currentPosition);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1089
	    }
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1090
	    RETURN ( rslt );
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1091
	}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1092
	error = __mkSmallInteger(__threadErrno);
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1093
    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1094
%}.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1095
    error notNil ifTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1096
	lastErrorNumber := error.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1097
	^ self ioError:error.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1098
    ].
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1099
    handle isNil ifTrue:[^ self errorNotOpen].
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1100
    ^ self primitiveFailed
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1101
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1102
15620
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1103
position:newPos
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1104
    "set the read/write position in the file"
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1105
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1106
    |rslt error|
3971
aad506cdc5d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3956
diff changeset
  1107
%{
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  1108
    HFILE f;
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1109
    long ret;
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1110
    OBJ fp;
7871
5c357f1ba0c9 preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents: 7870
diff changeset
  1111
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1112
    if ((__INST(canPosition) != false) || (newPos == __mkSmallInteger(0))) {
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1113
	if ((fp = __INST(handle)) != nil) {
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1114
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1115
#if defined(_LFS_LARGE_FILE) && !defined(__win32__)
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1116
# define FSEEK fseeko
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1117
	    off_t nP;
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1118
#else
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1119
#define FSEEK fseek
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1120
	    long nP;
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1121
#endif
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1122
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1123
	    if (__isSmallInteger(newPos)) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1124
		nP = __intVal(newPos);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1125
		if (nP < 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1126
		    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1127
		    goto getOutOfHere;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1128
		}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1129
	    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1130
		nP = __signedLongIntVal(newPos);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1131
		if (nP < 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1132
		    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1133
		    goto getOutOfHere;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1134
		}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1135
		if (nP == 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1136
		    if (sizeof(nP) == 8) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1137
			if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1138
			    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1139
			    goto getOutOfHere;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1140
			}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1141
		    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1142
			__INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1143
			goto getOutOfHere;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1144
		    }
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1145
		}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1146
	    }
7871
5c357f1ba0c9 preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents: 7870
diff changeset
  1147
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1148
	    f = __FILEVal(fp);
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  1149
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1150
	    do {
14853
63ffca691137 fseek does not need a WRAP_CALL (I hope)
Claus Gittinger <cg@exept.de>
parents: 14848
diff changeset
  1151
#if defined(DO_WRAP_CALL_FSEEK)
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1152
		__threadErrno = 0;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1153
		if (__INST(buffered) == true) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1154
		    ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1155
		} else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1156
		    __INST(readAhead) = nil;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1157
		    ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1158
		}
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  1159
#else
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1160
		if (__INST(buffered) == true) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1161
		    ret = FSEEK(f, nP, SEEK_SET);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1162
		} else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1163
		    ret = lseek(fileno(f), nP, SEEK_SET);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1164
		}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1165
		__threadErrno = errno;
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  1166
#endif
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1167
	    } while ((ret < 0) && (__threadErrno == EINTR));
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1168
	    if (ret >= 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1169
		__INST(position) = newPos; __STORE(self, newPos);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1170
		/*
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1171
		 * just to make certain ...
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1172
		 */
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1173
		__INST(hitEOF) = false;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1174
		RETURN ( self );
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1175
	    }
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1176
	    error = __mkSmallInteger(__threadErrno);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1177
	}
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1178
    }
7871
5c357f1ba0c9 preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents: 7870
diff changeset
  1179
    getOutOfHere: ;
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1180
#undef FSEEK
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1181
%}.
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1182
    canPosition == false ifTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1183
	"/ position by rewinding & re-reading everything up-to
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1184
	"/ that point.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1185
	^ self slowPosition:newPos
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1186
    ].
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1187
    error notNil ifTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1188
	lastErrorNumber := error.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1189
	(OperatingSystem errorSymbolForNumber:error) == #EINVAL ifTrue:[
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1190
	    "/ invalid position
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1191
	    ^ self positionError.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1192
	].
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1193
	"/ assume I/O error
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1194
	^ self ioError:error.
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2936
diff changeset
  1195
    ].
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1196
    handle isNil ifTrue:[^ self errorNotOpen].
7871
5c357f1ba0c9 preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents: 7870
diff changeset
  1197
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1198
    rslt := self positionFile:handle position:newPos.
5493
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  1199
    rslt >= 0 ifTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1200
	position := newPos.
5493
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  1201
    ] ifFalse:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1202
	hitEOF := true.
5493
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  1203
    ]
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1204
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1205
11437
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1206
reset
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1207
    "additionaly to setting the position to the beginning of the file,
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1208
     re-open a previously closed file. This behavior is compatible
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1209
     with other Smalltalk dialects"
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1210
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1211
    handle isNil ifTrue:[
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1212
	"reopen the file"
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1213
	mode == #readonly ifTrue: [
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1214
	    self openForReading
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1215
	] ifFalse:[mode == #writeonly ifTrue: [
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1216
	    self openForWriting.
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1217
	] ifFalse:[
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1218
	    self openForReadWrite.
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1219
	]].
11437
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1220
    ] ifFalse:[
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1221
	super reset.
11437
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1222
    ].
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1223
!
7869fd22df88 #reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents: 11290
diff changeset
  1224
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1225
setToEnd
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1226
    "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
  1227
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1228
    |error|
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1229
%{
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  1230
    HFILE f;
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1231
    off_t ret;
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1232
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1233
    if (__INST(handle) != nil) {
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1234
	f = __FILEVal(__INST(handle));
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1235
	__INST(position) = nil;    /* i.e. unknown */
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1236
	do {
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1237
#ifdef __win32__
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1238
	    __threadErrno = 0;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1239
	    if (__INST(buffered) == true) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1240
		ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1241
	    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1242
		__INST(readAhead) = nil;
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1243
		ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1244
	    }
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  1245
#else
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1246
	    if (__INST(buffered) == true) {
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1247
# ifdef _LFS_LARGE_FILE
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1248
		ret = fseeko(f, (off_t)0, SEEK_END);
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1249
# else
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1250
		ret = fseek(f, 0L, SEEK_END);
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1251
# endif
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1252
	    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1253
		ret = lseek(fileno(f), (off_t)0, SEEK_END);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1254
	    }
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  1255
#endif
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1256
	} while ((ret < 0) && (__threadErrno == EINTR));
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1257
	if (ret >= 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1258
	    RETURN ( self );
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1259
	}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1260
	error = __mkSmallInteger(__threadErrno);
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1261
    }
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1262
%}.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1263
    error notNil ifTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1264
	lastErrorNumber := error.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1265
	self ioError:error.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1266
	^ self.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1267
    ].
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1268
    handle isNil ifTrue:[^ self errorNotOpen].
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1269
    ^ self primitiveFailed
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1270
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1271
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1272
slowPosition:newPos
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1273
    "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
  1274
     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
  1275
     This is required to reposition nonPositionable streams, such
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1276
     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
  1277
     Caveat:
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1278
	 This should really be done transparently by the stdio library."
15620
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1279
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1280
    |buffer amount pos0Based|
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1281
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1282
    self isReadable ifFalse:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1283
	"/ sorry
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1284
	^ self positionError
15620
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1285
    ].
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1286
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1287
    buffer := ByteArray new:8*1024.
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1288
15620
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1289
    (position isNil "/ i.e. unknown
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1290
    or:[newPos < (pos0Based := self position)]) ifTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1291
	self reset.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1292
	pos0Based := self position.
15620
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1293
    ].
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1294
    [pos0Based < newPos] whileTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1295
	amount := (buffer size) min:(newPos-pos0Based).
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1296
	(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1297
	    ^ self positionError
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1298
	].
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  1299
	pos0Based := self position.
15620
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1300
    ].
264cf9877dda class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15573
diff changeset
  1301
    "/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR.
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1302
! !
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  1303
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1304
!FileStream methodsFor:'printing & storing'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1305
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1306
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4353
diff changeset
  1307
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4353
diff changeset
  1308
     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
  1309
10354
8de4bf3f28e8 changed #printOn:
Stefan Vogel <sv@exept.de>
parents: 10345
diff changeset
  1310
    aStream nextPutAll:self className,'(for: '.
8de4bf3f28e8 changed #printOn:
Stefan Vogel <sv@exept.de>
parents: 10345
diff changeset
  1311
    pathName printOn:aStream.
8de4bf3f28e8 changed #printOn:
Stefan Vogel <sv@exept.de>
parents: 10345
diff changeset
  1312
    aStream nextPut:$).
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
  1313
10354
8de4bf3f28e8 changed #printOn:
Stefan Vogel <sv@exept.de>
parents: 10345
diff changeset
  1314
    "
10450
bb40b56ed6b6 Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents: 10407
diff changeset
  1315
	'/' asFilename readStream printString
10354
8de4bf3f28e8 changed #printOn:
Stefan Vogel <sv@exept.de>
parents: 10345
diff changeset
  1316
    "
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1317
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1318
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1319
storeOn:aStream
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
  1320
    "append a representation of the receiver to aStream,
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
  1321
     from which a copy can be reconstructed later."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
  1322
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1323
    aStream nextPutAll:'(FileStream oldFileNamed:'.
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
  1324
    aStream nextPutAll:pathName storeString.
15360
7bf49766c324 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 14853
diff changeset
  1325
    (self position ~~ 0) ifTrue:[
15542
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
  1326
	aStream nextPutAll:'; position:'.
3a22ba499a82 open non-inheritable
Claus Gittinger <cg@exept.de>
parents: 15489
diff changeset
  1327
	self position storeOn:aStream
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1328
    ].
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1329
    aStream nextPut:$)
2811
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
  1330
21136662e8f1 dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents: 2808
diff changeset
  1331
    "Modified: 30.7.1997 / 16:43:50 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1332
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1333
18784
82b13911ae7b #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18781
diff changeset
  1334
!FileStream protectedMethodsFor:'private'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1335
8471
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1336
closeFile
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1337
    "low level close - may be redefined in subclasses.
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1338
     Don't send this message, send #close instead"
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1339
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1340
    super closeFile.
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1341
    removeOnClose == true ifTrue:[
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1342
	pathName asFilename remove.
8471
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1343
    ]
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1344
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1345
    "Created: / 13.8.1998 / 12:11:22 / cg"
18784
82b13911ae7b #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18781
diff changeset
  1346
! !
82b13911ae7b #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18781
diff changeset
  1347
82b13911ae7b #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18781
diff changeset
  1348
!FileStream methodsFor:'private'!
8471
e061e503bf03 Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents: 8362
diff changeset
  1349
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1350
createForReadWrite
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1351
    "create/truncate the file for read/write.
20921
cc986f069175 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20412
diff changeset
  1352
     If the file existed, it's truncated; otherwise it's created."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1353
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1354
    mode := #readwrite.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1355
    ^ self openWithMode:CreateReadWriteMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1356
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1357
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1358
createForWriting
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1359
    "create/truncate the file for writeonly.
20921
cc986f069175 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20412
diff changeset
  1360
     If the file existed, it's truncated; otherwise it's created."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1361
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1362
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1363
    didWrite := true.
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1364
    ^ self openWithMode:WriteMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1365
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1366
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1367
openFile:pathName withMode:openmode attributes:attributeSpec
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1368
    "open the file;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1369
     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
  1370
     (i.e. the 2nd fopen argument).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1371
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1372
     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
  1373
     be created as fixedRecord, variableRecord, streamLF, streamCR, ...
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1374
     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
  1375
     attributes (see fopen description).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1376
     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
  1377
     This argument is ignored in UNIX & MSDOS systems.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1378
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1379
     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
  1380
     which is proprietrary to the operatingSystem."
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1381
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1382
    |wasBlocked encodedPathName error|
14578
bc436b9a1ee3 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 14439
diff changeset
  1383
bc436b9a1ee3 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 14439
diff changeset
  1384
    encodedPathName := OperatingSystem encodePath:pathName.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1385
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1386
%{
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1387
    HFILE f = NULL;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1388
    int pass = 0;
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1389
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1390
    if (!__isNonNilObject(encodedPathName)
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1391
	|| !(__isStringLike(openmode) || __isArrayLike(openmode)))
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1392
	    goto badArgument;
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1393
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1394
retry:
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1395
#ifdef __VMS__
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1396
      if (__isStringLike(encodedPathName)) {
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1397
	do {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1398
	    /*
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1399
	     * allow passing additional RMS arguments.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1400
	     * stupid: DEC does not seem to offer an interface for passing a char **.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1401
	     */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1402
	    __threadErrno = 0;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1403
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1404
	    {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1405
		if (__isArrayLike(attributeSpec)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1406
		    OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1407
		    int numAttrib = 0;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1408
		    int i;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1409
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1410
		    numAttrib = __arraySize(attributeSpec);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1411
		    for (i=0; i<numAttrib;i++) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1412
			if (! __isStringLike(ap[i])) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1413
			    __threadErrno = EINVAL; /* invalid argument */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1414
			    goto getOutOfHere;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1415
			}
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1416
		    }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1417
		    switch (numAttrib) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1418
			case 0:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1419
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1420
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1421
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1422
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1423
			case 1:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1424
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1425
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1426
				      __stringVal(ap[0]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1427
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1428
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1429
			case 2:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1430
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1431
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1432
				      __stringVal(ap[0]), __stringVal(ap[1]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1433
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1434
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1435
			case 3:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1436
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1437
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1438
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1439
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1440
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1441
			case 4:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1442
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1443
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1444
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1445
				      __stringVal(ap[3]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1446
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1447
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1448
			case 5:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1449
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1450
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1451
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1452
				      __stringVal(ap[3]), __stringVal(ap[4]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1453
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1454
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1455
			case 6:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1456
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1457
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1458
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1459
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1460
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1461
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1462
			case 7:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1463
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1464
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1465
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1466
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1467
				      __stringVal(ap[6]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1468
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1469
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1470
			case 8:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1471
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1472
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1473
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1474
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1475
				      __stringVal(ap[6]), __stringVal(ap[7]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1476
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1477
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1478
			case 9:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1479
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1480
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1481
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1482
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1483
				      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1484
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1485
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1486
			case 10:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1487
			    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1488
			    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1489
				      __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1490
				      __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1491
				      __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]),
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1492
				      __stringVal(ap[9]));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1493
			    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1494
			    break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1495
			default:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1496
			    __threadErrno = E2BIG; /* too many args */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1497
			    goto getOutOfHere;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1498
		    }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1499
		} else if (attributeSpec != nil) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1500
		    __threadErrno = EINVAL; /* invalid argument */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1501
		    goto getOutOfHere;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1502
		} else {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1503
		    /*
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1504
		     * create file as sequential streamLF by default.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1505
		     */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1506
		    __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1507
		    f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf");
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1508
		    __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1509
		}
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1510
	    }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1511
	} while ((f == NULL) && (__threadErrno == EINTR));
11290
4226ed9c9a94 unicode filenames
Claus Gittinger <cg@exept.de>
parents: 10450
diff changeset
  1512
      }
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1513
#else /* not VMS */
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1514
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1515
# ifdef __win32__
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1516
    {
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1517
	  DWORD share = 0, access = 0, create = 0, attr = 0;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1518
	  char * __openmode;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1519
	  HANDLE handle;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1520
	  SECURITY_ATTRIBUTES sa;
11290
4226ed9c9a94 unicode filenames
Claus Gittinger <cg@exept.de>
parents: 10450
diff changeset
  1521
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1522
	  if (__isStringLike(openmode)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1523
	      share = FILE_SHARE_READ|FILE_SHARE_WRITE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1524
	      __openmode = __stringVal(openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1525
	      if (strcmp(__openmode, "rb") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1526
		  access = GENERIC_READ;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1527
		  create = OPEN_EXISTING;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1528
	      } else if (strcmp(__openmode, "rb+") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1529
		  access = GENERIC_READ | GENERIC_WRITE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1530
		  create = OPEN_EXISTING;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1531
	      } else if (strcmp(__openmode, "wb") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1532
		  access = GENERIC_WRITE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1533
		  create = CREATE_ALWAYS;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1534
	      } else if (strcmp(__openmode, "wb+") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1535
		  access = GENERIC_READ | GENERIC_WRITE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1536
		  create = CREATE_ALWAYS;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1537
	      } else if (strcmp(__openmode, "ab") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1538
		  access = FILE_APPEND_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1539
				STANDARD_RIGHTS_WRITE|SYNCHRONIZE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1540
		  create = OPEN_ALWAYS;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1541
	      } else if (strcmp(__openmode, "ab+") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1542
		  access = GENERIC_READ |FILE_APPEND_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1543
				STANDARD_RIGHTS_WRITE|SYNCHRONIZE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1544
		  create = OPEN_ALWAYS;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1545
	      } else {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1546
		  console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n");
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1547
	      }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1548
	  } else if (__isArrayLike(openmode)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1549
	      OBJ *ap = __arrayVal(openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1550
	      int numAttrib = __arraySize(openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1551
	      int i;
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1552
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1553
	      __openmode = "rb+";
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1554
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1555
	      for (i=0; i<numAttrib; i++) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1556
		  OBJ attrSym = ap[i];
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1557
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1558
		  if (attrSym == @symbol(FILE_SHARE_READ)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1559
		      share |= FILE_SHARE_READ;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1560
		  } else if (attrSym == @symbol(FILE_SHARE_WRITE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1561
		      share |= FILE_SHARE_WRITE;
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1562
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1563
		  } else if (attrSym == @symbol(GENERIC_READ)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1564
		      access |= GENERIC_READ;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1565
		  } else if (attrSym == @symbol(GENERIC_WRITE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1566
		      access |= GENERIC_WRITE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1567
		  } else if (attrSym == @symbol(GENERIC_READ_WRITE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1568
		      access |= GENERIC_READ|GENERIC_WRITE;
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1569
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1570
		  } else if (attrSym == @symbol(CREATE_NEW)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1571
		      create |= CREATE_NEW;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1572
		  } else if (attrSym == @symbol(CREATE_ALWAYS)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1573
		      create |= CREATE_ALWAYS;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1574
		  } else if (attrSym == @symbol(OPEN_EXISTING)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1575
		      create |= OPEN_EXISTING;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1576
		  } else if (attrSym == @symbol(OPEN_ALWAYS)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1577
		      create |= OPEN_ALWAYS;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1578
		  } else if (attrSym == @symbol(TRUNCATE_EXISTING)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1579
		      create |= TRUNCATE_EXISTING;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1580
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1581
		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_HIDDEN)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1582
		      attr |= FILE_ATTRIBUTE_HIDDEN;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1583
		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1584
		      attr |= FILE_ATTRIBUTE_READONLY;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1585
		  } else if (attrSym == @symbol(FILE_FLAG_WRITE_THROUGH)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1586
		      attr |= FILE_FLAG_WRITE_THROUGH;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1587
		  } else if (attrSym == @symbol(FILE_FLAG_SEQUENTIAL_SCAN)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1588
		      attr |= FILE_FLAG_SEQUENTIAL_SCAN;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1589
		  } else if (attrSym == @symbol(FILE_FLAG_DELETE_ON_CLOSE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1590
		      attr |= FILE_FLAG_DELETE_ON_CLOSE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1591
		  } else if (!__isSymbol(attrSym) && __isStringLike(attrSym)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1592
		      __openmode = __stringVal(attrSym);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1593
		  } else {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1594
		      console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n");
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1595
		  }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1596
	      }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1597
	  }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1598
	  if (create == 0) {
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1599
//              argumentError = @symbol(missingCreateMode);
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1600
	      goto badArgument;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1601
	  }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1602
	  if (attr == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1603
	      attr = FILE_ATTRIBUTE_NORMAL;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1604
	  }
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1605
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1606
	  /*
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1607
	   * create security attributes - make handle inheritable by subprocesses
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1608
	   */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1609
	  memset(&sa, 0, sizeof (sa));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1610
	  sa.nLength = sizeof( sa );
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1611
	  // sa.bInheritHandle = TRUE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1612
	  sa.bInheritHandle = FALSE;
12630
c6151f8f6854 changed: #openFile:withMode:attributes:
Stefan Vogel <sv@exept.de>
parents: 12467
diff changeset
  1613
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1614
	  if (__isStringLike(pathName)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1615
		char _aPathName[MAXPATHLEN];
11290
4226ed9c9a94 unicode filenames
Claus Gittinger <cg@exept.de>
parents: 10450
diff changeset
  1616
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1617
		strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1618
		do {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1619
		    __threadErrno = 0;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1620
		    handle = STX_API_NOINT_CALL7( "CreateFileA", CreateFileA, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1621
		    if (__threadErrno == EINTR) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1622
			handle = INVALID_HANDLE_VALUE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1623
		    }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1624
		} while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1625
	  } else if (__isUnicode16String(pathName)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1626
		wchar_t _aPathName[MAXPATHLEN+1];
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1627
		int i, l;
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1628
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1629
		l = __unicode16StringSize(pathName);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1630
		if (l > MAXPATHLEN) l = MAXPATHLEN;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1631
		for (i=0; i<l; i++) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1632
		    _aPathName[i] = __unicode16StringVal(pathName)[i];
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1633
		}
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1634
		_aPathName[i] = 0;
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1635
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1636
		do {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1637
		    __threadErrno = 0;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1638
		    handle = STX_API_NOINT_CALL7( "CreateFileW", CreateFileW, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1639
		    if (__threadErrno == EINTR) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1640
			handle = INVALID_HANDLE_VALUE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1641
		    }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1642
		} while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR));
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1643
	  }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1644
	  if (handle != INVALID_HANDLE_VALUE) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1645
	      int fd;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1646
	      extern void __stxWrapApiEnterCritical(), __stxWrapApiLeaveCritical();
12692
6150a8d7c87e changed: #openFile:withMode:attributes:
Stefan Vogel <sv@exept.de>
parents: 12687
diff changeset
  1647
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1648
	      __stxWrapApiEnterCritical();
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1649
	      fd = _open_osfhandle((long)handle, O_BINARY);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1650
	      if (fd < 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1651
		  if (__threadErrno == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1652
		      // no more file descriptors
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1653
		      __threadErrno = EMFILE;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1654
		  }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1655
		  CloseHandle(handle);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1656
	      } else {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1657
		  f = fdopen(fd, __openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1658
	      }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1659
	      __stxWrapApiLeaveCritical();
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1660
	  }  else {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1661
	    __threadErrno = __WIN32_ERR(GetLastError());
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1662
	  }
11290
4226ed9c9a94 unicode filenames
Claus Gittinger <cg@exept.de>
parents: 10450
diff changeset
  1663
      }
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1664
# else /* not WIN32 */
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1665
14578
bc436b9a1ee3 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 14439
diff changeset
  1666
      if (__isStringLike(encodedPathName)) {
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1667
	  int accessMode = 0666;        // default access mode of fopen(), relies on umask()
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1668
	  int flags = 0;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1669
	  int fd;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1670
	  char * __openmode;
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1671
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1672
	  if (__isStringLike(openmode)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1673
	      __openmode = __stringVal(openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1674
	      if (strcmp(__openmode, "r") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1675
		  flags = O_RDONLY;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1676
	      } else if (strcmp(__openmode, "r+") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1677
		  flags = O_RDWR;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1678
	      } else if (strcmp(__openmode, "w") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1679
		  flags = O_WRONLY | O_CREAT | O_TRUNC;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1680
	      } else if (strcmp(__openmode, "w+") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1681
		  flags = O_RDWR | O_CREAT | O_TRUNC;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1682
	      } else if (strcmp(__openmode, "a") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1683
		  flags = O_WRONLY | O_CREAT | O_APPEND;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1684
	      } else if (strcmp(__openmode, "a+") == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1685
		  flags = O_RDWR | O_CREAT| O_APPEND;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1686
	      } else {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1687
		  console_fprintf(stderr, "UNIXOS [warning]: unsupported open mode\n");
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1688
	      }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1689
	  } else if (__isArrayLike(openmode)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1690
	      OBJ *ap = __arrayVal(openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1691
	      int numAttrib = __arraySize(openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1692
	      int i;
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1693
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1694
	      __openmode = "r+";
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1695
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1696
	      for (i=0; i<numAttrib; i++) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1697
		  OBJ attrSym = ap[i];
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1698
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1699
		  if (attrSym == @symbol(FILE_SHARE_READ)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1700
		      // ignore
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1701
		  } else if (attrSym == @symbol(FILE_SHARE_WRITE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1702
		     // ignore
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1703
		  } else if (attrSym == @symbol(GENERIC_READ)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1704
		      flags |= O_RDONLY;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1705
		      __openmode = "r";
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1706
		  } else if (attrSym == @symbol(GENERIC_WRITE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1707
		      flags |= O_WRONLY;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1708
		      __openmode = "w";
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1709
		  } else if (attrSym == @symbol(GENERIC_READ_WRITE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1710
		      flags |= O_RDWR;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1711
		      __openmode = "r+";
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1712
		  } else if (attrSym == @symbol(CREATE_NEW)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1713
		      flags |= O_CREAT|O_EXCL;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1714
		      accessMode = 0600;     // simulate mkstemp()
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1715
		  } else if (attrSym == @symbol(CREATE_ALWAYS)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1716
		      flags |= O_CREAT|O_TRUNC;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1717
		  } else if (attrSym == @symbol(OPEN_EXISTING)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1718
		      // nothing to be set
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1719
		  } else if (attrSym == @symbol(OPEN_ALWAYS)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1720
		      flags |= O_CREAT;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1721
		  } else if (attrSym == @symbol(TRUNCATE_EXISTING)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1722
		      flags |= O_TRUNC;
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1723
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1724
		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_HIDDEN)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1725
		      // ignore
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1726
		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1727
		      accessMode &= 0444;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1728
		  } else if (attrSym == @symbol(FILE_FLAG_WRITE_THROUGH)) {
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1729
#ifdef O_DIRECT
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1730
		      flags |= O_DIRECT;
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1731
#endif
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1732
		  } else if (attrSym == @symbol(FILE_FLAG_SEQUENTIAL_SCAN)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1733
		      // ignore
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1734
		  } else if (attrSym == @symbol(FILE_FLAG_DELETE_ON_CLOSE)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1735
		      // ignore;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1736
		  } else if (!__isSymbol(attrSym) && __isStringLike(attrSym)) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1737
		      __openmode = __stringVal(attrSym);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1738
		  } else {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1739
		      console_fprintf(stderr, "UNIXOS [warning]: unsupported open mode\n");
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1740
		  }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1741
	      }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1742
	  }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1743
	  do {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1744
	      __BEGIN_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1745
	      fd = open((char *) __stringVal(encodedPathName), flags, accessMode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1746
	      __END_INTERRUPTABLE__
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1747
	  } while ((fd < 0) && (__threadErrno == EINTR));
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1748
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1749
	  if (fd >= 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1750
	      __threadErrno = 0;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1751
	      f = fdopen(fd, __openmode);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1752
	      if (f == NULL) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1753
		  close(fd);            // fdopen failed, close before retry.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1754
	      }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1755
	  }
11290
4226ed9c9a94 unicode filenames
Claus Gittinger <cg@exept.de>
parents: 10450
diff changeset
  1756
      }
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1757
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1758
# endif /* not WIN32 */
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1759
#endif /* not VMS */
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1760
15462
daed379229a2 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 15360
diff changeset
  1761
11290
4226ed9c9a94 unicode filenames
Claus Gittinger <cg@exept.de>
parents: 10450
diff changeset
  1762
    if (f == NULL) {
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1763
	/*
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1764
	 * If no filedescriptors available, try to finalize
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1765
	 * possibly collected fd's and try again.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1766
	 */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1767
	if ((__threadErrno == ENFILE || __threadErrno == EMFILE) && pass == 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1768
	    pass = 1;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1769
	    __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1770
	    __SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1771
	    goto retry;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1772
	}
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1773
    badArgument:
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1774
    getOutOfHere:
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1775
	error = __mkSmallInteger(__threadErrno);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1776
	__INST(position) = nil;
11290
4226ed9c9a94 unicode filenames
Claus Gittinger <cg@exept.de>
parents: 10450
diff changeset
  1777
    } else {
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1778
#ifdef __VMS__
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1779
	/*
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1780
	 * check to see if this is positionable ...
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1781
	 */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1782
	__INST(canPosition) = false;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1783
# ifndef _POSIX_C_SOURCE
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1784
	{
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1785
	    struct stat statBuffer;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1786
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1787
	    if (fstat(fileno(f), &statBuffer) >= 0) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1788
		switch (statBuffer.st_fab_rfm) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1789
		    case FAB$C_UDF: /* undefined (also stream binary)   */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1790
		    case FAB$C_VAR: /* variable length records          */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1791
		    case FAB$C_VFC: /* variable fixed control           */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1792
		    case FAB$C_STM: /* RMS-11 stream (valid only for sequen) */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1793
		    default:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1794
			__INST(canPosition) = false;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1795
			break;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1796
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1797
		    case FAB$C_FIX: /* fixed length records             */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1798
		    case FAB$C_STMLF: /* LF stream (valid only for sequential) */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1799
		    case FAB$C_STMCR: /* CR stream (valid only for sequential) */
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1800
			__INST(canPosition) = true;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1801
			break;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1802
		}
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1803
	    }
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1804
	}
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1805
# endif
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1806
#else /* not VMS */
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1807
	__INST(canPosition) = true;
11812
fae9f7c22dbd Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents: 11454
diff changeset
  1808
#endif /* not VMS */
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1809
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1810
	if (@global(FileOpenTrace) == true) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1811
	    console_fprintf(stderr, "fopen %s [FileStream] -> %"_lx_"\n", __stringVal(pathName), (INT)f);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1812
	}
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1813
	if (f != NULL) {
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1814
	    OBJ fp;
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1815
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1816
	    wasBlocked = __BLOCKINTERRUPTS();
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1817
#if 0
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1818
	    // The original code was:
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1819
	    __INST(handle) = fp = __MKEXTERNALADDRESS(f); __STORE(self, fp);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1820
	    // but for that, gcc generates wrong code, which loads self (volatile) into
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1821
	    // a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1822
	    // That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1823
	    // object.
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1824
#else
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1825
	    fp = __MKEXTERNALADDRESS(f);
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1826
	    __INST(handle) = fp;
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1827
	    __STORE(self, fp);
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1828
#endif
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1829
	}
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1830
    }
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1831
%}.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1832
    error notNil ifTrue:[
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1833
	lastErrorNumber := error.
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1834
	^ self openError:error.
8034
716b32d832bf raise condition interrupt: interrupt between creation and lobby
ca
parents: 7970
diff changeset
  1835
    ].
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1836
    handle isNil ifTrue:[
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1837
	^ self openError:0.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1838
    ].
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1839
20096
18e793f4cb78 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
  1840
    buffered := true.   "default is buffered"
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1841
    position := 0.
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1842
    handleType := #filePointer.
18781
58f9cf53b2ae #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18651
diff changeset
  1843
    self registerForFinalization.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  1844
    wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts].
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1845
    ^ handle
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1846
!
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5204
diff changeset
  1847
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1848
openForAppending
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1849
    "open the file for writeonly appending to the end.
20921
cc986f069175 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20412
diff changeset
  1850
     If the file does not exist, raise OpenError;
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1851
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1852
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1853
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1854
    didWrite := true.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1855
    ^ self openWithMode:AppendMode
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1856
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1857
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1858
openForReadWrite
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1859
    "open the file for read/write.
20921
cc986f069175 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20412
diff changeset
  1860
     If the file does not exist, raise OpenError;
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1861
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1862
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1863
    mode := #readwrite.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1864
    ^ self openWithMode:ReadWriteMode
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1865
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1866
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1867
openForReading
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1868
    "open the file for readonly.
20921
cc986f069175 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20412
diff changeset
  1869
     If the file does not exist, raise OpenError;
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1870
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1871
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1872
    mode := #readonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1873
    didWrite := false.
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1874
    ^ self openWithMode:ReadMode
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1875
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1876
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1877
openForWriting
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1878
    "open the file writeonly. The contents of the file is preserved.
20921
cc986f069175 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20412
diff changeset
  1879
     If the file does not exist, raise OpenError;
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1880
     otherwise return the receiver."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1881
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1882
    mode := #writeonly.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1883
    didWrite := true.
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1884
    "we must not truncate the file!! So do not use WriteMode"
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1885
    ^ self openWithMode:ReadWriteMode
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1886
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1887
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1888
openWithMode:openmode
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1889
    "open the file;
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1890
     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
  1891
     (i.e. the 2nd fopen argument).
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1892
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1893
     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
  1894
     which is proprietrary to the operatingSystem."
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1895
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1896
    ^ self openWithMode:openmode attributes:nil
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1897
!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1898
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1899
openWithMode:openmode attributes:attributeSpec
8627
5a86b95bebbb gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents: 8604
diff changeset
  1900
    "open the file;
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1901
     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
  1902
     (i.e. the 2nd fopen argument).
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1903
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1904
     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
  1905
     be created as fixedRecord, variableRecord, streamLF, streamCR, ...
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1906
     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
  1907
     attributes (see fopen description).
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1908
     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
  1909
     This argument is ignored in UNIX & MSDOS systems.
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1910
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1911
     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
  1912
     which is proprietrary to the operatingSystem."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1913
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1914
    handle notNil ifTrue:[^ self errorAlreadyOpen].
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1915
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1916
    handle := self openFile:pathName withMode:openmode attributes:attributeSpec.
17144
5aa46b24fa21 class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17078
diff changeset
  1917
    handle isNil ifTrue:[
21623
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1918
	"this happens, if proceeding from an OpenError raised in #openFile..."
0fd2de531f9a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21473
diff changeset
  1919
	^ nil.
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1920
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1921
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1922
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1923
pathName:filename
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1924
    "set the pathname"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1925
3051
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  1926
    pathName := filename asString
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  1927
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  1928
    "Modified: / 28.10.1997 / 14:29:01 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1929
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1930
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1931
pathName:filename in:aDirectory
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1932
    "set the pathname starting at aDirectory, a FileDirectory"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1933
3051
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  1934
    pathName := aDirectory asFilename constructString:filename
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  1935
29d10c26d6a3 allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
  1936
    "Modified: / 28.10.1997 / 14:28:54 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1937
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1938
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1939
reOpen
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1940
    "USERS WILL NEVER INVOKE THIS METHOD
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1941
     sent after snapin to reopen streams."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1942
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  1943
    handle notNil ifTrue:[
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1944
	"it was open, when snapped-out"
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1945
	handle := nil.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1946
	self unregisterForFinalization.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1947
	pathName isNil ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1948
	    ^ self.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1949
	].
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1950
	[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1951
	    |oldPos|
173
58e9778954bc reposition
claus
parents: 159
diff changeset
  1952
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1953
	    "should take care of appending files and open them for
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1954
	     append / position them to the end"
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1955
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1956
	    oldPos := position.
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1957
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1958
	    mode == #readonly ifTrue: [
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1959
		self openForReading
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1960
	    ] ifFalse:[mode == #writeonly ifTrue: [
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1961
		self openForWriting.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1962
	    ] ifFalse:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1963
		self openForReadWrite.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1964
	    ]].
8604
3079fcbdecb2 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 8575
diff changeset
  1965
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1966
	    oldPos notNil ifTrue:[
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1967
		self position:oldPos.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1968
	    ]
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1969
	] on:OpenError do:[:ex|
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1970
	    "this happens, if after a restart,
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1971
	     the file is no longer present or accessible ..."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1972
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1973
	    (self class name , ' [warning]: could not reopen file: ', pathName) errorPrintCR.
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19638
diff changeset
  1974
	].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1975
    ]
1088
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  1976
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2078
diff changeset
  1977
    "Modified: 10.1.1997 / 17:50:51 / cg"
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1978
!
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1979
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1980
setMode:aModeSymbol
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  1981
    mode := aModeSymbol
15479
7f6fdc8ff911 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15475
diff changeset
  1982
!
7f6fdc8ff911 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15475
diff changeset
  1983
7f6fdc8ff911 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15475
diff changeset
  1984
setPathName:pathNameString removeOnClose:aBoolean
7f6fdc8ff911 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15475
diff changeset
  1985
    pathName := pathNameString.
7f6fdc8ff911 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 15475
diff changeset
  1986
    removeOnClose := aBoolean.
31
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
  1987
! !
75f2b9f78be2 *** empty log message ***
claus
parents: 13
diff changeset
  1988
10395
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1989
!FileStream methodsFor:'private fileIn'!
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1990
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1991
fileInNotifying:notifiedLoader passChunk:passChunk
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1992
    "central method to file in from the receiver, i.e. read chunks and evaluate them -
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1993
     return the value of the last chunk.
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1994
     Someone (which is usually some codeView) is notified of errors."
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1995
21459
afc01857037e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21237
diff changeset
  1996
    ^ self fileInNotifying:notifiedLoader passChunk:passChunk inDirectory:(self fileName directory).
afc01857037e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21237
diff changeset
  1997
afc01857037e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21237
diff changeset
  1998
    "Modified: / 16-02-2017 / 11:28:21 / stefan"
10395
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  1999
! !
62fd9eba5c4b Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 10354
diff changeset
  2000
2921
f42da059311e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2001
!FileStream methodsFor:'queries'!
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2002
17603
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2003
collectionSize
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2004
    "common stream protocol: return the size of the stream;
20412
aee4d28b38c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20370
diff changeset
  2005
     that's the number of bytes of the file."
17603
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2006
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2007
    ^ self fileSize.
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2008
!
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2009
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
  2010
fileSize
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2011
    "return the size in bytes of the file"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2012
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  2013
    |error|
3971
aad506cdc5d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3956
diff changeset
  2014
%{
4910
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  2015
    HFILE f;
33b0edbb1920 merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents: 4907
diff changeset
  2016
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2017
#ifdef transputer
7874
5e0319ca5e60 stats filesize can be up-to 32bit now.
Claus Gittinger <cg@exept.de>
parents: 7872
diff changeset
  2018
    unsigned int size;
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2019
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  2020
    if (__INST(handle) != nil) {
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2021
	f = __FILEVal(__INST(handle));
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2022
	if ((size = filesize(fileno(f))) >= 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2023
	    RETURN ( __MKUINT(size) );
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2024
	}
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2025
    }
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2026
#else
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2027
    struct stat buf;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2028
    int ret;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2029
    int fd;
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2030
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  2031
    if (__INST(handle) != nil) {
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2032
	f = __FILEVal(__INST(handle));
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2033
	fd = fileno(f);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2034
	do {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2035
	    ret = fstat(fd, &buf);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2036
	} while ((ret < 0) && (__threadErrno == EINTR));
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2037
	if (ret >= 0) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2038
	    OBJ rslt;
7883
1039acd0624b Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents: 7874
diff changeset
  2039
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2040
	    if (sizeof(buf.st_size) == 8) {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2041
		rslt = __MKINT64(&buf.st_size);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2042
	    } else {
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2043
		rslt = __MKINT(buf.st_size);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2044
	    }
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2045
	    RETURN(rslt);
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2046
	}
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2047
	error = __mkSmallInteger(__threadErrno);
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2048
    }
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2049
#endif
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2050
%}.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2051
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2052
    "could add a fall-back here:
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2053
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2054
	oldPosition := self position.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2055
	self setToEnd.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2056
	sz := self position.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2057
	self position:oldPosition.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2058
	^ sz
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2059
    "
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  2060
    error notNil ifTrue:[
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2061
	lastErrorNumber := error.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2062
	self ioError:error.
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2063
	^ self.
16298
5fd8d5ceab59 Fix error processing
Stefan Vogel <sv@exept.de>
parents: 16113
diff changeset
  2064
    ].
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  2065
    handle isNil ifTrue:[^ self errorNotOpen].
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2066
    ^ self primitiveFailed
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  2067
!
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  2068
13051
e50451e3a086 added: #isDirectory
Stefan Vogel <sv@exept.de>
parents: 12950
diff changeset
  2069
isDirectory
e50451e3a086 added: #isDirectory
Stefan Vogel <sv@exept.de>
parents: 12950
diff changeset
  2070
    ^ OperatingSystem isDirectory:pathName
e50451e3a086 added: #isDirectory
Stefan Vogel <sv@exept.de>
parents: 12950
diff changeset
  2071
!
e50451e3a086 added: #isDirectory
Stefan Vogel <sv@exept.de>
parents: 12950
diff changeset
  2072
14093
a1b853b10448 added: #isEmpty
Stefan Vogel <sv@exept.de>
parents: 13778
diff changeset
  2073
isEmpty
a1b853b10448 added: #isEmpty
Stefan Vogel <sv@exept.de>
parents: 13778
diff changeset
  2074
    "common stream protocol: are there no bytes in the file?"
a1b853b10448 added: #isEmpty
Stefan Vogel <sv@exept.de>
parents: 13778
diff changeset
  2075
a1b853b10448 added: #isEmpty
Stefan Vogel <sv@exept.de>
parents: 13778
diff changeset
  2076
    ^ self fileSize == 0.
a1b853b10448 added: #isEmpty
Stefan Vogel <sv@exept.de>
parents: 13778
diff changeset
  2077
!
a1b853b10448 added: #isEmpty
Stefan Vogel <sv@exept.de>
parents: 13778
diff changeset
  2078
17603
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2079
remainingSize
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2080
    "return the number of remaining elements in the streamed collection."
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2081
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2082
    ^ self fileSize - self position.
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2083
!
d87df1b3568f class: FileStream
Stefan Vogel <sv@exept.de>
parents: 17309
diff changeset
  2084
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  2085
size
11454
b451c165163a comment
Stefan Vogel <sv@exept.de>
parents: 11437
diff changeset
  2086
    "common stream protocol: return the size of the stream;
20412
aee4d28b38c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20370
diff changeset
  2087
     that's the number of bytes of the file."
2998
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  2088
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  2089
    ^ self fileSize.
2998
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  2090
930360fb3f12 #size is not really obsolete
Claus Gittinger <cg@exept.de>
parents: 2992
diff changeset
  2091
    "Modified: 4.10.1997 / 18:01:09 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2092
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2093
5493
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  2094
!FileStream methodsFor:'rel5 protocol'!
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  2095
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 12207
diff changeset
  2096
positionFile:handle position:newPos
5493
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  2097
    "for migration to rel5 only"
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  2098
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  2099
    self primitiveFailed
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  2100
! !
4efa5b89498b rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5439
diff changeset
  2101
2
claus
parents: 1
diff changeset
  2102
!FileStream methodsFor:'testing'!
claus
parents: 1
diff changeset
  2103
claus
parents: 1
diff changeset
  2104
isFileStream
claus
parents: 1
diff changeset
  2105
    "return true, if the receiver is some kind of fileStream.
claus
parents: 1
diff changeset
  2106
     redefined from Object"
claus
parents: 1
diff changeset
  2107
claus
parents: 1
diff changeset
  2108
    ^ true
claus
parents: 1
diff changeset
  2109
! !
claus
parents: 1
diff changeset
  2110
1088
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  2111
!FileStream class methodsFor:'documentation'!
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  2112
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  2113
version
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2114
    ^ '$Header$'
12207
cb911af5184f comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents: 11813
diff changeset
  2115
!
cb911af5184f comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents: 11813
diff changeset
  2116
cb911af5184f comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents: 11813
diff changeset
  2117
version_CVS
18651
36567dd3b8d1 printf of INTs
Claus Gittinger <cg@exept.de>
parents: 17603
diff changeset
  2118
    ^ '$Header$'
1088
989f0e510a32 nicer message
Claus Gittinger <cg@exept.de>
parents: 857
diff changeset
  2119
! !
6798
cc084e7ecc88 checkin from browser
penk
parents: 6586
diff changeset
  2120
15360
7bf49766c324 class: FileStream
Claus Gittinger <cg@exept.de>
parents: 14853
diff changeset
  2121
2936
5cce0f2166d9 OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents: 2921
diff changeset
  2122
FileStream initialize!