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