1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/***
*fopen.c - open a file
*
* Copyright (c) 1985-1991, Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines fopen() and _fsopen() - open a file as a stream and open a file
* with a specified sharing mode as a stream
*
*Revision History:
* 09-02-83 RN initial version
* 04-13-87 JCR added const to declarations
* 11-01-87 JCR Multi-thread support
* 12-11-87 JCR Added "_LOAD_DS" to declaration
* 05-31-88 PHG Merged DLL and normal versions
* 11-14-88 GJF Added _fsopen().
* 02-15-90 GJF Fixed copyright and indents
* 03-19-90 GJF Replaced _LOAD_DS with _CALLTYPE1, added #include
* <cruntime.h> and removed #include <register.h>.
* 07-23-90 SBM Replaced <assertm.h> by <assert.h>
* 10-02-90 GJF New-style function declarators.
* 01-21-91 GJF ANSI naming.
* 03-26-92 DJM POSIX support
*
*******************************************************************************/
#include <cruntime.h>
#include <stdio.h>
#include <share.h>
#include <assert.h>
#include <internal.h>
#include <os2dll.h>
#include <file2.h>
/***
*FILE *_fsopen(file, mode, shflag) - open a file
*
*Purpose:
* Opens the file specified as a stream. mode determines file mode:
* "r": read "w": write "a": append
* "r+": read/write "w+": open empty for read/write
* "a+": read/append
* Append "t" or "b" for text and binary mode. shflag determines the
* sharing mode. Values are the same as for sopen().
*
*Entry:
* char *file - file name to open
* char *mode - mode of file access
*
*Exit:
* returns pointer to stream
* returns NULL if fails
*
*Exceptions:
*
*******************************************************************************/
FILE * _CALLTYPE1 _fsopen (
const char *file,
const char *mode
#ifndef _POSIX_
,int shflag
#endif
)
{
REG1 FILE *stream;
REG2 FILE *retval;
assert(file != NULL);
assert(*file != '\0');
assert(mode != NULL);
assert(*mode != '\0');
/* Get a free stream */
/* [NOTE: _getstream() returns a locked stream.] */
if ((stream = _getstream()) == NULL)
return(NULL);
/* open the stream */
#ifdef _POSIX_
retval = _openfile(file,mode, stream);
#else
retval = _openfile(file,mode,shflag,stream);
#endif
/* unlock stream and return. */
_unlock_str(_iob_index(stream));
return(retval);
}
/***
*FILE *fopen(file, mode) - open a file
*
*Purpose:
* Opens the file specified as a stream. mode determines file mode:
* "r": read "w": write "a": append
* "r+": read/write "w+": open empty for read/write
* "a+": read/append
* Append "t" or "b" for text and binary mode
*
*Entry:
* char *file - file name to open
* char *mode - mode of file access
*
*Exit:
* returns pointer to stream
* returns NULL if fails
*
*Exceptions:
*
*******************************************************************************/
FILE * _CALLTYPE1 fopen (
const char *file,
const char *mode
)
{
#ifdef _POSIX_
return( _fsopen(file, mode) );
#else
return( _fsopen(file, mode, _SH_DENYNO) );
#endif
}
|