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