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);
26 FILE* _fsopen(const char *file, const char *mode, int shflag)
29 int fd, rw, oflags = 0;
43 rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
48 oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
51 oflags = rw ? O_RDWR : O_RDONLY;
54 oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
65 else if (tbchar == 'b')
68 oflags |= (_fmode & (O_TEXT|O_BINARY));
70 if ( shflag == _SH_DENYNO )
71 shf = _S_IREAD | _S_IWRITE;
72 else if( shflag == _SH_DENYRD )
74 else if( shflag == _SH_DENYRW )
76 else if( shflag == _SH_DENYWR )
79 shf = _S_IREAD | _S_IWRITE;
81 fd = _open(file, oflags, shf);
85 // msvcrt ensures that writes will end up at the end of file in append mode
86 // we just move the file pointer to the end of file initially
88 lseek(fd, 0, SEEK_END);
94 f->_flag = _IOREAD | _IOWRT;
95 else if (*mode == 'r')
100 f->_base = f->_ptr = NULL;
107 FILE* _wfsopen(const wchar_t *file, const wchar_t *mode, int shflag)
110 int fd, rw, oflags = 0;
124 rw = (mode[1] == L'+') || (mode[1] && (mode[2] == L'+'));
129 oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
132 oflags = rw ? O_RDWR : O_RDONLY;
135 oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
146 else if (tbchar == L'b')
149 oflags |= (_fmode & (O_TEXT|O_BINARY));
151 if ( shflag == _SH_DENYNO )
152 shf = _S_IREAD | _S_IWRITE;
153 else if( shflag == _SH_DENYRD )
155 else if( shflag == _SH_DENYRW )
157 else if( shflag == _SH_DENYWR )
160 shf = _S_IREAD | _S_IWRITE;
162 fd = _wopen(file, oflags, shf);
166 // msvcrt ensures that writes will end up at the end of file in append mode
167 // we just move the file pointer to the end of file initially
169 lseek(fd, 0, SEEK_END);
175 f->_flag = _IOREAD | _IOWRT;
176 else if (*mode == L'r')
181 f->_base = f->_ptr = NULL;