2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/msvcrt/stdio/fsopen.c
5 * PURPOSE: Checks for keyboard hits
6 * PROGRAMER: Boudewijn Dekker
10 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
12 #include <msvcrt/sys/types.h>
13 #include <msvcrt/stdio.h>
14 #include <msvcrt/io.h>
15 #include <msvcrt/fcntl.h>
16 #include <msvcrt/share.h>
17 #include <msvcrt/internal/file.h>
20 FILE * __alloc_file(void);
23 FILE* _fsopen(const char *file
, const char *mode
, int shflag
)
26 int fd
, rw
, oflags
= 0;
40 rw
= (mode
[1] == '+') || (mode
[1] && (mode
[2] == '+'));
45 oflags
= O_CREAT
| (rw
? O_RDWR
: O_WRONLY
);
48 oflags
= rw
? O_RDWR
: O_RDONLY
;
51 oflags
= O_TRUNC
| O_CREAT
| (rw
? O_RDWR
: O_WRONLY
);
62 else if (tbchar
== 'b')
65 oflags
|= (_fmode
& (O_TEXT
|O_BINARY
));
67 if ( shflag
== _SH_DENYNO
)
68 shf
= _S_IREAD
| _S_IWRITE
;
69 else if( shflag
== _SH_DENYRD
)
71 else if( shflag
== _SH_DENYRW
)
73 else if( shflag
== _SH_DENYWR
)
76 shf
= _S_IREAD
| _S_IWRITE
;
78 fd
= _open(file
, oflags
, shf
);
82 // msvcrt ensures that writes will end up at the end of file in append mode
83 // we just move the file pointer to the end of file initially
85 lseek(fd
, 0, SEEK_END
);
91 f
->_flag
= _IOREAD
| _IOWRT
;
92 else if (*mode
== 'r')
97 f
->_base
= f
->_ptr
= NULL
;
101 FILE* _wfsopen(const wchar_t *file
, const wchar_t *mode
, int shflag
)
104 int fd
, rw
, oflags
= 0;
118 rw
= (mode
[1] == L
'+') || (mode
[1] && (mode
[2] == L
'+'));
123 oflags
= O_CREAT
| (rw
? O_RDWR
: O_WRONLY
);
126 oflags
= rw
? O_RDWR
: O_RDONLY
;
129 oflags
= O_TRUNC
| O_CREAT
| (rw
? O_RDWR
: O_WRONLY
);
140 else if (tbchar
== L
'b')
143 oflags
|= (_fmode
& (O_TEXT
|O_BINARY
));
145 if ( shflag
== _SH_DENYNO
)
146 shf
= _S_IREAD
| _S_IWRITE
;
147 else if( shflag
== _SH_DENYRD
)
149 else if( shflag
== _SH_DENYRW
)
151 else if( shflag
== _SH_DENYWR
)
154 shf
= _S_IREAD
| _S_IWRITE
;
156 fd
= _wopen(file
, oflags
, shf
);
160 // msvcrt ensures that writes will end up at the end of file in append mode
161 // we just move the file pointer to the end of file initially
163 lseek(fd
, 0, SEEK_END
);
169 f
->_flag
= _IOREAD
| _IOWRT
;
170 else if (*mode
== L
'r')
175 f
->_base
= f
->_ptr
= NULL
;