ReactOS  r76032
file.c File Reference
#include <precomp.h>
#include "wine/unicode.h"
#include <sys/utime.h>
#include <direct.h>
Include dependency graph for file.c:

Go to the source code of this file.

Classes

struct  ioinfo
 
struct  file_crit
 

Macros

#define _IOCOMMIT   0x4000
 
#define WX_OPEN   0x01
 
#define WX_ATEOF   0x02
 
#define WX_READNL   0x04 /* read started with \n */
 
#define WX_READEOF   0x04 /* like ATEOF, but for underlying file rather than buffer */
 
#define WX_PIPE   0x08
 
#define WX_READCR   0x08 /* underlying file is at \r */
 
#define WX_DONTINHERIT   0x10
 
#define WX_APPEND   0x20
 
#define WX_TTY   0x40
 
#define WX_TEXT   0x80
 
#define EF_UTF8   0x01
 
#define EF_UTF16   0x02
 
#define EF_UNK_UNICODE   0x08
 
#define MSVCRT_MAX_FILES   2048
 
#define MSVCRT_FD_BLOCK_SIZE   32
 
#define MSVCRT_INTERNAL_BUFSIZ   4096
 
#define LOCK_FILES()   do { EnterCriticalSection(&MSVCRT_file_cs); } while (0)
 
#define UNLOCK_FILES()   do { LeaveCriticalSection(&MSVCRT_file_cs); } while (0)
 

Functions

int__p__fmode (void)
 
int__p___mb_cur_max (void)
 
static ioinfoget_ioinfo_nolock (int fd)
 
static ioinfoget_ioinfo (int fd)
 
static FILEmsvcrt_get_file (int i)
 
static BOOL is_valid_fd (int fd)
 
HANDLE fdtoh (int fd)
 
static void msvcrt_free_fd (int fd)
 
static int msvcrt_set_fd (HANDLE hand, int flag, int fd)
 
int msvcrt_alloc_fd (HANDLE hand, int flag)
 
static FILEmsvcrt_alloc_fp (void)
 
static int msvcrt_init_fp (FILE *file, int fd, unsigned stream_flags)
 
unsigned create_io_inherit_block (WORD *size, BYTE **block)
 
void msvcrt_init_io (void)
 
static int msvcrt_flush_buffer (FILE *file)
 
int CDECL _isatty (int fd)
 
BOOL msvcrt_alloc_buffer (FILE *file)
 
static BOOL add_std_buffer (FILE *file)
 
static void remove_std_buffer (FILE *file)
 
static int msvcrt_int_to_base32 (int num, char *str)
 
static int msvcrt_int_to_base32_w (int num, wchar_t *str)
 
wchar_tmsvcrt_wstrdupa (const char *str)
 
FILE *CDECL __iob_func (void)
 
int CDECL _access (const char *filename, int mode)
 
int CDECL _access_s (const char *filename, int mode)
 
int CDECL _waccess (const wchar_t *filename, int mode)
 
int CDECL _waccess_s (const wchar_t *filename, int mode)
 
int CDECL _chmod (const char *path, int flags)
 
int CDECL _wchmod (const wchar_t *path, int flags)
 
int CDECL _unlink (const char *path)
 
int CDECL _wunlink (const wchar_t *path)
 
int CDECL _commit (int fd)
 
int CDECL fflush (FILE *file)
 
static int msvcrt_flush_all_buffers (int mask)
 
int CDECL _flushall (void)
 
int CDECL _close (int fd)
 
int CDECL _dup2 (int od, int nd)
 
int CDECL _dup (int od)
 
int CDECL _eof (int fd)
 
int CDECL _fcloseall (void)
 
void msvcrt_free_io (void)
 
__int64 CDECL _lseeki64 (int fd, __int64 offset, int whence)
 
LONG CDECL _lseek (int fd, LONG offset, int whence)
 
void CDECL _lock_file (FILE *file)
 
void CDECL _unlock_file (FILE *file)
 
int CDECL _locking (int fd, int mode, LONG nbytes)
 
int CDECL _fseeki64 (FILE *file, __int64 offset, int whence)
 
int CDECL fseek (FILE *file, long offset, int whence)
 
int CDECL _chsize_s (int fd, __int64 size)
 
int CDECL _chsize (int fd, long size)
 
void CDECL clearerr (FILE *file)
 
void CDECL rewind (FILE *file)
 
static int msvcrt_get_flags (const wchar_t *mode, int *open_flags, int *stream_flags)
 
FILE *CDECL _fdopen (int fd, const char *mode)
 
FILE *CDECL _wfdopen (int fd, const wchar_t *mode)
 
LONG CDECL _filelength (int fd)
 
__int64 CDECL _filelengthi64 (int fd)
 
int CDECL _fileno (FILE *file)
 
intptr_t CDECL _get_osfhandle (int fd)
 
char *CDECL _mktemp (char *pattern)
 
wchar_t *CDECL _wmktemp (wchar_t *pattern)
 
unsigned split_oflags (unsigned oflags)
 
int CDECL _pipe (int *pfds, unsigned int psize, int textmode)
 
static int check_bom (HANDLE h, int oflags, BOOL seek)
 
int CDECL _wsopen_s (int *fd, const wchar_t *path, int oflags, int shflags, int pmode)
 
int CDECL _wsopen (const wchar_t *path, int oflags, int shflags,...)
 
int CDECL _sopen_s (int *fd, const char *path, int oflags, int shflags, int pmode)
 
int CDECL _sopen (const char *path, int oflags, int shflags,...)
 
int CDECL _open (const char *path, int flags,...)
 
int CDECL _wopen (const wchar_t *path, int flags,...)
 
int CDECL _creat (const char *path, int flags)
 
int CDECL _wcreat (const wchar_t *path, int flags)
 
int CDECL _open_osfhandle (intptr_t handle, int oflags)
 
int CDECL _rmtmp (void)
 
static int get_utf8_char_len (char ch)
 
static int read_utf8 (int fd, wchar_t *buf, unsigned int count)
 
static int read_i (int fd, void *buf, unsigned int count)
 
int CDECL _read (int fd, void *buf, unsigned int count)
 
int CDECL _setmode (int fd, int mode)
 
long CDECL _tell (int fd)
 
__int64 CDECL _telli64 (int fd)
 
char *CDECL _tempnam (const char *dir, const char *prefix)
 
wchar_t *CDECL _wtempnam (const wchar_t *dir, const wchar_t *prefix)
 
int CDECL _umask (int umask)
 
int CDECL _write (int fd, const void *buf, unsigned int count)
 
int CDECL _putw (int val, FILE *file)
 
int CDECL fclose (FILE *file)
 
int CDECL feof (FILE *file)
 
int CDECL ferror (FILE *file)
 
int CDECL _filbuf (FILE *file)
 
int CDECL fgetc (FILE *file)
 
int CDECL _fgetchar (void)
 
char *CDECL fgets (char *s, int size, FILE *file)
 
wint_t CDECL fgetwc (FILE *file)
 
int CDECL _getw (FILE *file)
 
wint_t CDECL getwc (FILE *file)
 
wint_t CDECL _fgetwchar (void)
 
wint_t CDECL getwchar (void)
 
wchar_t *CDECL fgetws (wchar_t *s, int size, FILE *file)
 
size_t CDECL fwrite (const void *ptr, size_t size, size_t nmemb, FILE *file)
 
wint_t CDECL fputwc (wchar_t c, FILE *stream)
 
wint_t CDECL _fputwchar (wint_t wc)
 
FILE *CDECL _wfsopen (const wchar_t *path, const wchar_t *mode, int share)
 
FILE *CDECL _fsopen (const char *path, const char *mode, int share)
 
FILE *CDECL fopen (const char *path, const char *mode)
 
int CDECL fopen_s (FILE **pFile, const char *filename, const char *mode)
 
FILE *CDECL _wfopen (const wchar_t *path, const wchar_t *mode)
 
int CDECL _wfopen_s (FILE **pFile, const wchar_t *filename, const wchar_t *mode)
 
int CDECL _flsbuf (int c, FILE *file)
 
int CDECL fputc (int c, FILE *file)
 
int CDECL _fputchar (int c)
 
size_t CDECL fread (void *ptr, size_t size, size_t nmemb, FILE *file)
 
FILE *CDECL _wfreopen (const wchar_t *path, const wchar_t *mode, FILE *file)
 
FILE *CDECL freopen (const char *path, const char *mode, FILE *file)
 
int CDECL fsetpos (FILE *file, const fpos_t *pos)
 
__int64 CDECL _ftelli64 (FILE *file)
 
LONG CDECL ftell (FILE *file)
 
int CDECL fgetpos (FILE *file, fpos_t *pos)
 
int CDECL fputs (const char *s, FILE *file)
 
int CDECL fputws (const wchar_t *s, FILE *file)
 
int CDECL getchar (void)
 
int CDECL getc (FILE *file)
 
char *CDECL gets (char *buf)
 
wchar_t *CDECL _getws (wchar_t *buf)
 
int CDECL putc (int c, FILE *file)
 
int CDECL putchar (int c)
 
wint_t CDECL _putwch (wchar_t c)
 
int CDECL puts (const char *s)
 
int CDECL _putws (const wchar_t *s)
 
int CDECL remove (const char *path)
 
int CDECL _wremove (const wchar_t *path)
 
int CDECL rename (const char *oldpath, const char *newpath)
 
int CDECL _wrename (const wchar_t *oldpath, const wchar_t *newpath)
 
int CDECL setvbuf (FILE *file, char *buf, int mode, size_t size)
 
void CDECL setbuf (FILE *file, char *buf)
 
char *CDECL tmpnam (char *s)
 
wchar_t *CDECL _wtmpnam (wchar_t *s)
 
FILE *CDECL tmpfile (void)
 
int CDECL ungetc (int c, FILE *file)
 
wint_t CDECL ungetwc (wint_t wc, FILE *file)
 
int CDECL _getmaxstdio (void)
 
int CDECL _setmaxstdio (int newmax)
 

Variables

int _commode
 
static char utf8_bom [3] = { 0xef, 0xbb, 0xbf }
 
static char utf16_bom [2] = { 0xff, 0xfe }
 
ioinfo__pioinfo [MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { 0 }
 
ioinfo __badioinfo = { INVALID_HANDLE_VALUE, WX_TEXT }
 
static int fdstart = 3
 
static int fdend = 3
 
FILE _iob [_IOB_ENTRIES] = { { 0 } }
 
static file_critMSVCRT_fstream [MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { NULL }
 
static int MSVCRT_max_streams = 512
 
static int MSVCRT_stream_idx
 
static int MSVCRT_umask = 0
 
static int tmpnam_unique
 
static CRITICAL_SECTION MSVCRT_file_cs = { &MSVCRT_file_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG MSVCRT_file_cs_debug
 

Macro Definition Documentation

#define _IOCOMMIT   0x4000

Definition at line 58 of file file.c.

Referenced by msvcrt_get_flags().

#define EF_UNK_UNICODE   0x08

Definition at line 104 of file file.c.

Referenced by _wsopen_s().

#define EF_UTF16   0x02

Definition at line 103 of file file.c.

Referenced by _setmode(), _write(), _wsopen_s(), fgetwc(), read_i(), and ungetwc().

#define EF_UTF8   0x01

Definition at line 102 of file file.c.

Referenced by _setmode(), _write(), _wsopen_s(), fgetwc(), read_i(), and ungetwc().

#define MSVCRT_FD_BLOCK_SIZE   32

Definition at line 111 of file file.c.

Referenced by get_ioinfo(), get_ioinfo_nolock(), msvcrt_get_file(), and msvcrt_set_fd().

#define MSVCRT_INTERNAL_BUFSIZ   4096

Definition at line 113 of file file.c.

Referenced by fwrite(), and msvcrt_alloc_buffer().

#define MSVCRT_MAX_FILES   2048

Definition at line 110 of file file.c.

Referenced by _setmaxstdio(), get_ioinfo(), get_ioinfo_nolock(), msvcrt_init_io(), and msvcrt_set_fd().

#define WX_APPEND   0x20

Definition at line 97 of file file.c.

Referenced by _write(), msvcrt_set_fd(), and split_oflags().

#define WX_ATEOF   0x02

Definition at line 91 of file file.c.

Referenced by _eof(), _lseeki64(), fread(), read_i(), and read_utf8().

#define WX_DONTINHERIT   0x10

Definition at line 96 of file file.c.

Referenced by create_io_inherit_block(), msvcrt_set_fd(), and split_oflags().

#define WX_OPEN   0x01

Definition at line 90 of file file.c.

Referenced by create_io_inherit_block(), is_valid_fd(), msvcrt_init_io(), and msvcrt_set_fd().

#define WX_PIPE   0x08

Definition at line 94 of file file.c.

Referenced by _open_osfhandle(), _wsopen_s(), msvcrt_init_io(), msvcrt_set_fd(), read_i(), and read_utf8().

#define WX_READCR   0x08 /* underlying file is at \r */

Definition at line 95 of file file.c.

#define WX_READEOF   0x04 /* like ATEOF, but for underlying file rather than buffer */

Definition at line 93 of file file.c.

Referenced by _lseeki64().

#define WX_READNL   0x04 /* read started with \n */

Definition at line 92 of file file.c.

Referenced by _ftelli64(), read_i(), and read_utf8().

#define WX_TEXT   0x80
#define WX_TTY   0x40

Function Documentation

FILE* CDECL __iob_func ( void  )

Definition at line 666 of file file.c.

667 {
668  return &_iob[0];
669 }
FILE _iob[_IOB_ENTRIES]
Definition: file.c:143
int* __p___mb_cur_max ( void  )

Definition at line 430 of file environ.c.

431 {
432  return &get_locinfo()->mb_cur_max;
433 }
#define get_locinfo()
Definition: winesup.h:25
int* __p__fmode ( void  )

Definition at line 9 of file fmode.c.

Referenced by split_oflags().

10 {
11  return &_fmode;
12 }
int _fmode
Definition: fmode.c:4
int CDECL _access ( const char filename,
int  mode 
)

Definition at line 674 of file file.c.

Referenced by _access_s().

675 {
677 
678  TRACE("(%s,%d) %d\n",filename,mode,attr);
679 
680  if (!filename || attr == INVALID_FILE_ATTRIBUTES)
681  {
683  return -1;
684  }
685  if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
686  {
688  return -1;
689  }
690  return 0;
691 }
errno_t __cdecl _set_errno(_In_ int _Value)
#define INVALID_FILE_ATTRIBUTES
Definition: test.h:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:766
#define TRACE(s)
Definition: solgame.cpp:4
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
Definition: cookie.c:158
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define W_OK
Definition: io.h:170
static char filename[MAX_PATH]
Definition: file.c:64
int CDECL _access_s ( const char filename,
int  mode 
)

Definition at line 696 of file file.c.

697 {
698  if (!MSVCRT_CHECK_PMT(filename != NULL) ||
699  !MSVCRT_CHECK_PMT((mode & ~(R_OK | W_OK)) == 0))
700  {
702  return -1;
703  }
704 
705  return _access(filename, mode);
706 }
errno_t __cdecl _set_errno(_In_ int _Value)
Definition: arc.h:39
#define R_OK
Definition: io.h:171
smooth NULL
Definition: ftsmooth.c:557
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define W_OK
Definition: io.h:170
static char filename[MAX_PATH]
Definition: file.c:64
int CDECL _access(const char *filename, int mode)
Definition: file.c:674
int CDECL _chmod ( const char path,
int  flags 
)

Definition at line 748 of file file.c.

Referenced by test_file_write_read().

749 {
750  DWORD oldFlags = GetFileAttributesA(path);
751 
752  if (oldFlags != INVALID_FILE_ATTRIBUTES)
753  {
754  DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY:
755  oldFlags | FILE_ATTRIBUTE_READONLY;
756 
757  if (newFlags == oldFlags || SetFileAttributesA(path, newFlags))
758  return 0;
759  }
761  return -1;
762 }
#define INVALID_FILE_ATTRIBUTES
Definition: test.h:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:766
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:906
#define _S_IWRITE
Definition: cabinet.h:41
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
GLbitfield flags
Definition: glext.h:7161
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:311
int CDECL _chsize ( int  fd,
long  size 
)

Definition at line 1285 of file file.c.

Referenced by test_chsize().

1286 {
1287  /* _chsize_s returns errno on failure but _chsize should return -1 */
1288  return _chsize_s( fd, size ) == 0 ? 0 : -1;
1289 }
int CDECL _chsize_s(int fd, __int64 size)
Definition: file.c:1247
static HANDLE fd
Definition: io.c:55
GLsizeiptr size
Definition: glext.h:5919
int CDECL _chsize_s ( int  fd,
__int64  size 
)

Definition at line 1247 of file file.c.

Referenced by _chsize().

1248 {
1249  __int64 cur, pos;
1250  HANDLE handle;
1251  BOOL ret = FALSE;
1252 
1253  TRACE("(fd=%d, size=%s)\n", fd, wine_dbgstr_longlong(size));
1254 
1255  if (!MSVCRT_CHECK_PMT(size >= 0)) return EINVAL;
1256 
1257  LOCK_FILES();
1258 
1259  handle = fdtoh(fd);
1260  if (handle != INVALID_HANDLE_VALUE)
1261  {
1262  /* save the current file pointer */
1263  cur = _lseeki64(fd, 0, SEEK_CUR);
1264  if (cur >= 0)
1265  {
1266  pos = _lseeki64(fd, size, SEEK_SET);
1267  if (pos >= 0)
1268  {
1269  ret = SetEndOfFile(handle);
1270  if (!ret) _dosmaperr(GetLastError());
1271  }
1272 
1273  /* restore the file pointer */
1274  _lseeki64(fd, cur, SEEK_SET);
1275  }
1276  }
1277 
1278  UNLOCK_FILES();
1279  return ret ? 0 : *_errno();
1280 }
#define SEEK_CUR
Definition: util.h:63
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:79
HANDLE fdtoh(int fd)
Definition: file.c:230
Definition: arc.h:39
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1134
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define FALSE
Definition: types.h:117
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1080
#define UNLOCK_FILES()
Definition: file.c:169
#define SEEK_SET
Definition: jmemansi.c:26
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define LOCK_FILES()
Definition: file.c:168
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
GLsizeiptr size
Definition: glext.h:5919
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
#define __int64
Definition: basetyps.h:16
int CDECL _close ( int  fd)

Definition at line 905 of file file.c.

Referenced by _dup2(), _pipe(), _wfsopen(), fclose(), test__creat(), test_chsize(), test_file_write_read(), test_get_osfhandle(), test_setmode(), and tmpfile().

906 {
907  HANDLE hand;
908  int ret;
909 
910  LOCK_FILES();
911  hand = fdtoh(fd);
912  TRACE(":fd (%d) handle (%p)\n",fd,hand);
913  if (hand == INVALID_HANDLE_VALUE)
914  ret = -1;
915  else if (!CloseHandle(hand))
916  {
917  WARN(":failed-last error (%d)\n",GetLastError());
919  ret = -1;
920  }
921  else
922  {
924  ret = 0;
925  }
926  UNLOCK_FILES();
927  TRACE(":ok\n");
928  return ret;
929 }
#define CloseHandle
Definition: compat.h:398
HANDLE fdtoh(int fd)
Definition: file.c:230
#define WARN(fmt,...)
Definition: debug.h:111
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
static void msvcrt_free_fd(int fd)
Definition: file.c:245
#define UNLOCK_FILES()
Definition: file.c:169
#define TRACE(s)
Definition: solgame.cpp:4
int ret
#define LOCK_FILES()
Definition: file.c:168
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
int CDECL _commit ( int  fd)

Definition at line 812 of file file.c.

813 {
814  HANDLE hand = fdtoh(fd);
815 
816  TRACE(":fd (%d) handle (%p)\n",fd,hand);
817  if (hand == INVALID_HANDLE_VALUE)
818  return -1;
819 
820  if (!FlushFileBuffers(hand))
821  {
823  {
824  /* FlushFileBuffers fails for console handles
825  * so we ignore this error.
826  */
827  return 0;
828  }
829  TRACE(":failed-last error (%d)\n",GetLastError());
831  return -1;
832  }
833  TRACE(":ok\n");
834  return 0;
835 }
HANDLE fdtoh(int fd)
Definition: file.c:230
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:175
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
int CDECL _creat ( const char path,
int  flags 
)

Definition at line 1970 of file file.c.

Referenced by test__creat().

1971 {
1972  int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC;
1973  return _open(path, usedFlags);
1974 }
#define _O_CREAT
Definition: cabinet.h:54
#define _O_TRUNC
Definition: cabinet.h:55
GLbitfield flags
Definition: glext.h:7161
#define _O_WRONLY
Definition: cabinet.h:46
Definition: services.c:311
#define _O_TEXT
Definition: cabinet.h:58
int CDECL _open(const char *path, int flags,...)
Definition: file.c:1932
int CDECL _dup ( int  od)

Definition at line 985 of file file.c.

Referenced by test_stdin().

986 {
987  int fd, ret;
988 
989  LOCK_FILES();
990  fd = fdstart;
991  if (_dup2(od, fd) == 0)
992  ret = fd;
993  else
994  ret = -1;
995  UNLOCK_FILES();
996  return ret;
997 }
static int fdstart
Definition: file.c:135
#define UNLOCK_FILES()
Definition: file.c:169
int ret
#define LOCK_FILES()
Definition: file.c:168
static HANDLE fd
Definition: io.c:55
int CDECL _dup2(int od, int nd)
Definition: file.c:938
int CDECL _dup2 ( int  od,
int  nd 
)

Definition at line 938 of file file.c.

Referenced by _dup(), test_dup2(), test_stat(), and test_stdin().

939 {
940  int ret;
941 
942  TRACE("(od=%d, nd=%d)\n", od, nd);
943  LOCK_FILES();
944  if (nd < MSVCRT_MAX_FILES && nd >= 0 && is_valid_fd(od))
945  {
946  HANDLE handle;
947 
948  if (DuplicateHandle(GetCurrentProcess(), get_ioinfo(od)->handle,
950  {
951  int wxflag = get_ioinfo(od)->wxflag & ~_O_NOINHERIT;
952 
953  if (is_valid_fd(nd))
954  _close(nd);
955  ret = msvcrt_set_fd(handle, wxflag, nd);
956  if (ret == -1)
957  {
958  CloseHandle(handle);
959  *_errno() = EMFILE;
960  }
961  else
962  {
963  /* _dup2 returns 0, not nd, on success */
964  ret = 0;
965  }
966  }
967  else
968  {
969  ret = -1;
971  }
972  }
973  else
974  {
975  *_errno() = EBADF;
976  ret = -1;
977  }
978  UNLOCK_FILES();
979  return ret;
980 }
static int msvcrt_set_fd(HANDLE hand, int flag, int fd)
Definition: file.c:283
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:79
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
static BOOL is_valid_fd(int fd)
Definition: file.c:219
Definition: arc.h:36
#define _O_NOINHERIT
Definition: cabinet.h:53
#define DUPLICATE_SAME_ACCESS
#define UNLOCK_FILES()
Definition: file.c:169
int CDECL _close(int fd)
Definition: file.c:905
unsigned char wxflag
Definition: file.c:41
#define TRACE(s)
Definition: solgame.cpp:4
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1183
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
#define LOCK_FILES()
Definition: file.c:168
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:52
Definition: arc.h:42
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
int CDECL _eof ( int  fd)

Definition at line 1002 of file file.c.

1003 {
1004  DWORD curpos,endpos;
1005  LONG hcurpos,hendpos;
1006  HANDLE hand = fdtoh(fd);
1007 
1008  TRACE(":fd (%d) handle (%p)\n",fd,hand);
1009 
1010  if (hand == INVALID_HANDLE_VALUE)
1011  return -1;
1012 
1013  if (get_ioinfo(fd)->wxflag & WX_ATEOF) return TRUE;
1014 
1015  /* Otherwise we do it the hard way */
1016  hcurpos = hendpos = 0;
1017  curpos = SetFilePointer(hand, 0, &hcurpos, FILE_CURRENT);
1018  endpos = SetFilePointer(hand, 0, &hendpos, FILE_END);
1019 
1020  if (curpos == endpos && hcurpos == hendpos)
1021  {
1022  /* FIXME: shouldn't WX_ATEOF be set here? */
1023  return TRUE;
1024  }
1025 
1026  SetFilePointer(hand, curpos, &hcurpos, FILE_BEGIN);
1027  return FALSE;
1028 }
#define TRUE
Definition: types.h:120
HANDLE fdtoh(int fd)
Definition: file.c:230
#define FILE_CURRENT
Definition: winbase.h:111
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define TRACE(s)
Definition: solgame.cpp:4
#define FILE_END
Definition: winbase.h:112
#define FILE_BEGIN
Definition: winbase.h:110
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
#define WX_ATEOF
Definition: file.c:91
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
int CDECL _fcloseall ( void  )

Definition at line 1033 of file file.c.

Referenced by msvcrt_free_io(), and test_fopen_fclose_fcloseall().

1034 {
1035  int num_closed = 0, i;
1036  FILE *file;
1037 
1038  LOCK_FILES();
1039  for (i = 3; i < MSVCRT_stream_idx; i++) {
1040  file = msvcrt_get_file(i);
1041 
1042  if (file->_flag && !fclose(file))
1043  num_closed++;
1044  }
1045  UNLOCK_FILES();
1046 
1047  TRACE(":closed (%d) handles\n",num_closed);
1048  return num_closed;
1049 }
static int MSVCRT_stream_idx
Definition: file.c:145
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define UNLOCK_FILES()
Definition: file.c:169
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:168
int _flag
Definition: mbstring.h:23
static FILE * msvcrt_get_file(int i)
Definition: file.c:193
int CDECL fclose(FILE *file)
Definition: file.c:2699
FILE* CDECL _fdopen ( int  fd,
const char mode 
)

Definition at line 1435 of file file.c.

1436 {
1437  FILE *ret;
1438  wchar_t *modeW = NULL;
1439 
1440  if (mode && !(modeW = msvcrt_wstrdupa(mode))) return NULL;
1441 
1442  ret = _wfdopen(fd, modeW);
1443 
1444  free(modeW);
1445  return ret;
1446 }
#define free
Definition: debug_ros.c:5
FILE *CDECL _wfdopen(int fd, const wchar_t *mode)
Definition: file.c:1451
wchar_t * msvcrt_wstrdupa(const char *str)
Definition: file.c:653
smooth NULL
Definition: ftsmooth.c:557
int ret
static HANDLE fd
Definition: io.c:55
int CDECL _fgetchar ( void  )

Definition at line 2822 of file file.c.

2823 {
2824  return fgetc(stdin);
2825 }
FILE * stdin
int CDECL fgetc(FILE *file)
Definition: file.c:2802
wint_t CDECL _fgetwchar ( void  )

Definition at line 2943 of file file.c.

Referenced by getwchar().

2944 {
2945  return fgetwc(stdin);
2946 }
FILE * stdin
wint_t CDECL fgetwc(FILE *file)
Definition: file.c:2862
int CDECL _filbuf ( FILE file)

Definition at line 2749 of file file.c.

Referenced by fgetc(), and test_filbuf().

2750 {
2751  unsigned char c;
2752  _lock_file(file);
2753 
2754  if(file->_flag & _IOSTRG) {
2755  _unlock_file(file);
2756  return EOF;
2757  }
2758 
2759  /* Allocate buffer if needed */
2760  if(!(file->_flag & (_IONBF | _IOMYBUF | _USERBUF)))
2761  msvcrt_alloc_buffer(file);
2762 
2763  if(!(file->_flag & _IOREAD)) {
2764  if(file->_flag & _IORW)
2765  file->_flag |= _IOREAD;
2766  else {
2767  _unlock_file(file);
2768  return EOF;
2769  }
2770  }
2771 
2772  if(!(file->_flag & (_IOMYBUF | _USERBUF))) {
2773  int r;
2774  if ((r = read_i(file->_file,&c,1)) != 1) {
2775  file->_flag |= (r == 0) ? _IOEOF : _IOERR;
2776  _unlock_file(file);
2777  return EOF;
2778  }
2779 
2780  _unlock_file(file);
2781  return c;
2782  } else {
2783  file->_cnt = read_i(file->_file, file->_base, file->_bufsiz);
2784  if(file->_cnt<=0) {
2785  file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR;
2786  file->_cnt = 0;
2787  _unlock_file(file);
2788  return EOF;
2789  }
2790 
2791  file->_cnt--;
2792  file->_ptr = file->_base+1;
2793  c = *(unsigned char *)file->_base;
2794  _unlock_file(file);
2795  return c;
2796  }
2797 }
#define _USERBUF
Definition: stdio.h:137
char * _base
Definition: mbstring.h:22
int _cnt
Definition: mbstring.h:21
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
char * _ptr
Definition: mbstring.h:20
#define _IOSTRG
Definition: stdio.h:135
#define _IOERR
Definition: stdio.h:134
#define _IOREAD
Definition: stdio.h:125
#define _IOEOF
Definition: stdio.h:133
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
#define _IOMYBUF
Definition: stdio.h:132
BOOL msvcrt_alloc_buffer(FILE *file)
Definition: file.c:556
int _bufsiz
Definition: mbstring.h:26
int _flag
Definition: mbstring.h:23
#define EOF
Definition: stdio.h:24
int _file
Definition: mbstring.h:24
#define c
Definition: ke_i.h:80
#define _IONBF
Definition: stdio.h:130
static int read_i(int fd, void *buf, unsigned int count)
Definition: file.c:2238
#define _IORW
Definition: stdio.h:136
LONG CDECL _filelength ( int  fd)

Definition at line 1475 of file file.c.

Referenced by test_chsize().

1476 {
1477  LONG curPos = _lseek(fd, 0, SEEK_CUR);
1478  if (curPos != -1)
1479  {
1480  LONG endPos = _lseek(fd, 0, SEEK_END);
1481  if (endPos != -1)
1482  {
1483  if (endPos != curPos)
1484  _lseek(fd, curPos, SEEK_SET);
1485  return endPos;
1486  }
1487  }
1488  return -1;
1489 }
#define SEEK_CUR
Definition: util.h:63
long LONG
Definition: pedump.c:60
#define SEEK_SET
Definition: jmemansi.c:26
LONG CDECL _lseek(int fd, LONG offset, int whence)
Definition: file.c:1120
static HANDLE fd
Definition: io.c:55
#define SEEK_END
Definition: cabinet.c:21
__int64 CDECL _filelengthi64 ( int  fd)

Definition at line 1494 of file file.c.

1495 {
1496  __int64 curPos = _lseeki64(fd, 0, SEEK_CUR);
1497  if (curPos != -1)
1498  {
1499  __int64 endPos = _lseeki64(fd, 0, SEEK_END);
1500  if (endPos != -1)
1501  {
1502  if (endPos != curPos)
1503  _lseeki64(fd, curPos, SEEK_SET);
1504  return endPos;
1505  }
1506  }
1507  return -1;
1508 }
#define SEEK_CUR
Definition: util.h:63
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1080
#define SEEK_SET
Definition: jmemansi.c:26
static HANDLE fd
Definition: io.c:55
#define SEEK_END
Definition: cabinet.c:21
#define __int64
Definition: basetyps.h:16
int CDECL _fileno ( FILE file)

Definition at line 1513 of file file.c.

Referenced by test_fflush().

1514 {
1515  TRACE(":FILE* (%p) fd (%d)\n",file,file->_file);
1516  return file->_file;
1517 }
#define TRACE(s)
Definition: solgame.cpp:4
int _file
Definition: mbstring.h:24
int CDECL _flsbuf ( int  c,
FILE file 
)

Definition at line 14 of file _flsbuf.c.

Referenced by fputc(), fwrite(), and test_flsbuf().

15 {
16  int count, written;
17 
18  /* Check if the stream supports flushing */
19  if ((stream->_flag & _IOSTRG) || !(stream->_flag & (_IORW|_IOWRT)))
20  {
21  stream->_flag |= _IOERR;
22  return EOF;
23  }
24 
25  /* Always reset _cnt */
26  stream->_cnt = 0;
27 
28  /* Check if this was a read buffer */
29  if (stream->_flag & _IOREAD)
30  {
31  /* Must be at the end of the file */
32  if (!(stream->_flag & _IOEOF))
33  {
34  stream->_flag |= _IOERR;
35  return EOF;
36  }
37 
38  /* Reset buffer */
39  stream->_ptr = stream->_base;
40  }
41 
42  /* Fixup flags */
43  stream->_flag &= ~(_IOREAD|_IOEOF);
44  stream->_flag |= _IOWRT;
45 
46  /* Check if should get a buffer */
47  if (!(stream->_flag & _IONBF) && stream != stdout && stream != stderr)
48  {
49  /* If we have no buffer, try to allocate one */
50  if (!stream->_base) msvcrt_alloc_buffer(stream);
51  }
52 
53  /* Check if we can use a buffer now */
54  if (stream->_base && !(stream->_flag & _IONBF))
55  {
56  /* We can, check if there is something to write */
57  count = (int)(stream->_ptr - stream->_base);
58  if (count > 0)
59  written = _write(stream->_file, stream->_base, count);
60  else
61  written = 0;
62 
63  /* Reset buffer and put the char into it */
64  stream->_ptr = stream->_base + sizeof(TCHAR);
65  stream->_cnt = stream->_bufsiz - sizeof(TCHAR);
66  *(TCHAR*)stream->_base = ch;
67  }
68  else
69  {
70  /* There is no buffer, write the char directly */
71  count = sizeof(TCHAR);
72  written = _write(stream->_file, &ch, sizeof(TCHAR));
73  }
74 
75  /* Check for failure */
76  if (written != count)
77  {
78  stream->_flag |= _IOERR;
79  return EOF;
80  }
81 
82  return ch & (sizeof(TCHAR) > sizeof(char) ? 0xffff : 0xff);
83 }
_CRTIMP int __cdecl _write(_In_ int _FileHandle, _In_reads_bytes_(_MaxCharCount) const void *_Buf, _In_ unsigned int _MaxCharCount)
BOOL __cdecl msvcrt_alloc_buffer(FILE *stream)
Definition: file.c:556
#define _IOSTRG
Definition: stdio.h:135
FILE * stdout
#define _IOERR
Definition: stdio.h:134
#define _IOREAD
Definition: stdio.h:125
#define _IOEOF
Definition: stdio.h:133
char TCHAR
Definition: xmlstorage.h:189
#define _IOWRT
Definition: stdio.h:126
GLuint GLuint GLsizei count
Definition: gl.h:1545
Definition: parse.h:22
#define EOF
Definition: stdio.h:24
FILE * stderr
#define _IONBF
Definition: stdio.h:130
#define _IORW
Definition: stdio.h:136
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29
int CDECL _flushall ( void  )

Definition at line 867 of file file.c.

Referenced by msvcrt_free_io(), test_fflush(), and wmain().

868 {
870 }
#define _IOREAD
Definition: stdio.h:125
#define _IOWRT
Definition: stdio.h:126
static int msvcrt_flush_all_buffers(int mask)
Definition: file.c:841
int CDECL _fputchar ( int  c)

Definition at line 3246 of file file.c.

3247 {
3248  return fputc(c, stdout);
3249 }
FILE * stdout
int CDECL fputc(int c, FILE *file)
Definition: file.c:3218
const GLubyte * c
Definition: glext.h:8905
wint_t CDECL _fputwchar ( wint_t  wc)

Definition at line 3093 of file file.c.

3094 {
3095  return fputwc(wc, stdout);
3096 }
wint_t CDECL fputwc(wchar_t c, FILE *stream)
Definition: file.c:3061
FILE * stdout
int CDECL _fseeki64 ( FILE file,
__int64  offset,
int  whence 
)

Definition at line 1207 of file file.c.

Referenced by fseek().

1208 {
1209  int ret;
1210 
1211  _lock_file(file);
1212  /* Flush output if needed */
1213  if(file->_flag & _IOWRT)
1214  msvcrt_flush_buffer(file);
1215 
1216  if(whence == SEEK_CUR && file->_flag & _IOREAD ) {
1217  whence = SEEK_SET;
1218  offset += _ftelli64(file);
1219  }
1220 
1221  /* Discard buffered input */
1222  file->_cnt = 0;
1223  file->_ptr = file->_base;
1224  /* Reset direction of i/o */
1225  if(file->_flag & _IORW) {
1226  file->_flag &= ~(_IOREAD|_IOWRT);
1227  }
1228  /* Clear end of file flag */
1229  file->_flag &= ~_IOEOF;
1230  ret = (_lseeki64(file->_file,offset,whence) == -1)?-1:0;
1231 
1232  _unlock_file(file);
1233  return ret;
1234 }
#define SEEK_CUR
Definition: util.h:63
char * _base
Definition: mbstring.h:22
int _cnt
Definition: mbstring.h:21
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
char * _ptr
Definition: mbstring.h:20
#define _IOREAD
Definition: stdio.h:125
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1080
#define _IOEOF
Definition: stdio.h:133
#define SEEK_SET
Definition: jmemansi.c:26
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
#define _IOWRT
Definition: stdio.h:126
int ret
int _flag
Definition: mbstring.h:23
__int64 CDECL _ftelli64(FILE *file)
Definition: file.c:3420
int _file
Definition: mbstring.h:24
#define _IORW
Definition: stdio.h:136
GLintptr offset
Definition: glext.h:5920
static int msvcrt_flush_buffer(FILE *file)
Definition: file.c:519
FILE* CDECL _fsopen ( const char path,
const char mode,
int  share 
)

Definition at line 3135 of file file.c.

Referenced by fopen().

3136 {
3137  FILE *ret;
3138  wchar_t *pathW = NULL, *modeW = NULL;
3139 
3140  if (path && !(pathW = msvcrt_wstrdupa(path))) {
3141  _invalid_parameter(NULL, NULL, NULL, 0, 0);
3142  *_errno() = EINVAL;
3143  return NULL;
3144  }
3145  if (mode && !(modeW = msvcrt_wstrdupa(mode)))
3146  {
3147  free(pathW);
3148  _invalid_parameter(NULL, NULL, NULL, 0, 0);
3149  *_errno() = EINVAL;
3150  return NULL;
3151  }
3152 
3153  ret = _wfsopen(pathW, modeW, share);
3154 
3155  free(pathW);
3156  free(modeW);
3157  return ret;
3158 }
Definition: arc.h:39
#define free
Definition: debug_ros.c:5
wchar_t * msvcrt_wstrdupa(const char *str)
Definition: file.c:653
smooth NULL
Definition: ftsmooth.c:557
FILE *CDECL _wfsopen(const wchar_t *path, const wchar_t *mode, int share)
Definition: file.c:3101
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
Definition: services.c:311
void _invalid_parameter(const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved)
Definition: errno.c:137
__int64 CDECL _ftelli64 ( FILE file)

Definition at line 3420 of file file.c.

Referenced by _fseeki64(), fgetpos(), and ftell().

3421 {
3422  __int64 pos;
3423 
3424  _lock_file(file);
3425  pos = _telli64(file->_file);
3426  if(pos == -1) {
3427  _unlock_file(file);
3428  return -1;
3429  }
3430  if(file->_flag & (_IOMYBUF | _USERBUF)) {
3431  if(file->_flag & _IOWRT) {
3432  pos += file->_ptr - file->_base;
3433 
3434  if(get_ioinfo(file->_file)->wxflag & WX_TEXT) {
3435  char *p;
3436 
3437  for(p=file->_base; p<file->_ptr; p++)
3438  if(*p == '\n')
3439  pos++;
3440  }
3441  } else if(!file->_cnt) { /* nothing to do */
3442  } else if(_lseeki64(file->_file, 0, SEEK_END)==pos) {
3443  int i;
3444 
3445  pos -= file->_cnt;
3446  if(get_ioinfo(file->_file)->wxflag & WX_TEXT) {
3447  for(i=0; i<file->_cnt; i++)
3448  if(file->_ptr[i] == '\n')
3449  pos--;
3450  }
3451  } else {
3452  char *p;
3453 
3454  if(_lseeki64(file->_file, pos, SEEK_SET) != pos) {
3455  _unlock_file(file);
3456  return -1;
3457  }
3458 
3459  pos -= file->_bufsiz;
3460  pos += file->_ptr - file->_base;
3461 
3462  if(get_ioinfo(file->_file)->wxflag & WX_TEXT) {
3463  if(get_ioinfo(file->_file)->wxflag & WX_READNL)
3464  pos--;
3465 
3466  for(p=file->_base; p<file->_ptr; p++)
3467  if(*p == '\n')
3468  pos++;
3469  }
3470  }
3471  }
3472 
3473  _unlock_file(file);
3474  return pos;
3475 }
#define _USERBUF
Definition: stdio.h:137
char * _base
Definition: mbstring.h:22
int _cnt
Definition: mbstring.h:21
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
char * _ptr
Definition: mbstring.h:20
__int64 CDECL _telli64(int fd)
Definition: file.c:2451
#define WX_TEXT
Definition: file.c:99
GLenum GLclampf GLint i
Definition: glfuncs.h:14
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1080
#define SEEK_SET
Definition: jmemansi.c:26
unsigned char wxflag
Definition: file.c:41
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
#define _IOWRT
Definition: stdio.h:126
#define _IOMYBUF
Definition: stdio.h:132
int _bufsiz
Definition: mbstring.h:26
int _flag
Definition: mbstring.h:23
#define WX_READNL
Definition: file.c:92
int _file
Definition: mbstring.h:24
#define SEEK_END
Definition: cabinet.c:21
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
GLfloat GLfloat p
Definition: glext.h:8902
#define __int64
Definition: basetyps.h:16
intptr_t CDECL _get_osfhandle ( int  fd)

Definition at line 1522 of file file.c.

Referenced by test_close(), test_get_osfhandle(), and test_stdin().

1523 {
1524  HANDLE hand = fdtoh(fd);
1525  TRACE(":fd (%d) handle (%p)\n",fd,hand);
1526 
1527  return (intptr_t)hand;
1528 }
HANDLE fdtoh(int fd)
Definition: file.c:230
#define TRACE(s)
Definition: solgame.cpp:4
int intptr_t
Definition: crtdefs.h:283
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
int CDECL _getmaxstdio ( void  )

Definition at line 3942 of file file.c.

3943 {
3944  return MSVCRT_max_streams;
3945 }
static int MSVCRT_max_streams
Definition: file.c:145
int CDECL _getw ( FILE file)

Definition at line 2910 of file file.c.

Referenced by test_readmode().

2911 {
2912  char *ch;
2913  int i, k;
2914  unsigned int j;
2915  ch = (char *)&i;
2916 
2917  _lock_file(file);
2918  for (j=0; j<sizeof(int); j++) {
2919  k = fgetc(file);
2920  if (k == EOF) {
2921  file->_flag |= _IOEOF;
2922  _unlock_file(file);
2923  return EOF;
2924  }
2925  ch[j] = k;
2926  }
2927 
2928  _unlock_file(file);
2929  return i;
2930 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
static int(__cdecl *p_fopen_s)(FILE **
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define _IOEOF
Definition: stdio.h:133
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
int _flag
Definition: mbstring.h:23
#define EOF
Definition: stdio.h:24
int CDECL fgetc(FILE *file)
Definition: file.c:2802
int k
Definition: mpi.c:3369
wchar_t* CDECL _getws ( wchar_t buf)

Definition at line 3579 of file file.c.

3580 {
3581  wint_t cc;
3582  wchar_t* ws = buf;
3583 
3584  _lock_file(stdin);
3585  for (cc = fgetwc(stdin); cc != WEOF && cc != '\n';
3586  cc = fgetwc(stdin))
3587  {
3588  if (cc != '\r')
3589  *buf++ = (wchar_t)cc;
3590  }
3591  *buf = '\0';
3592 
3593  TRACE("got %s\n", debugstr_w(ws));
3595  return ws;
3596 }
const char * ws
Definition: skip_ws.cpp:7
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
FILE * stdin
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define debugstr_w
Definition: kernel32.h:32
int wint_t
Definition: _apple.h:38
#define TRACE(s)
Definition: solgame.cpp:4
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
#define WEOF
Definition: conio.h:185
uint32_t cc
Definition: isohybrid.c:75
wint_t CDECL fgetwc(FILE *file)
Definition: file.c:2862
#define wchar_t
Definition: wchar.h:102
int CDECL _isatty ( int  fd)

Definition at line 548 of file file.c.

Referenced by add_std_buffer(), and msvcrt_alloc_buffer().

549 {
550  TRACE(":fd (%d)\n",fd);
551 
552  return get_ioinfo_nolock(fd)->wxflag & WX_TTY;
553 }
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:171
#define WX_TTY
Definition: file.c:98
unsigned char wxflag
Definition: file.c:41
#define TRACE(s)
Definition: solgame.cpp:4
static HANDLE fd
Definition: io.c:55
void CDECL _lock_file ( FILE file)

Definition at line 1128 of file file.c.

Referenced by _filbuf(), _fseeki64(), _ftelli64(), _getw(), _getws(), _putw(), _putws(), clearerr(), fclose(), fflush(), fgetc(), fgets(), fgetwc(), fgetws(), fputc(), fputs(), fputws(), fread(), fsetpos(), fwrite(), gets(), puts(), rewind(), setvbuf(), ungetc(), and ungetwc().

1129 {
1130  if(file>=_iob && file<_iob+_IOB_ENTRIES)
1131  _lock(_STREAM_LOCKS+(file-_iob));
1132  /* ReactOS: string streams dont need to be locked */
1133  else if(!(file->_flag & _IOSTRG))
1134  EnterCriticalSection(&((file_crit*)file)->crit);
1135 }
#define _lock
#define _STREAM_LOCKS
Definition: mtdll.h:65
#define _IOSTRG
Definition: stdio.h:135
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define _IOB_ENTRIES
Definition: stdio.h:23
int _flag
Definition: mbstring.h:23
FILE _iob[_IOB_ENTRIES]
Definition: file.c:143
int CDECL _locking ( int  fd,
int  mode,
LONG  nbytes 
)

Definition at line 1155 of file file.c.

1156 {
1157  BOOL ret;
1158  DWORD cur_locn;
1159  HANDLE hand = fdtoh(fd);
1160 
1161  TRACE(":fd (%d) handle (%p)\n",fd,hand);
1162  if (hand == INVALID_HANDLE_VALUE)
1163  return -1;
1164 
1165  if (mode < 0 || mode > 4)
1166  {
1167  *_errno() = EINVAL;
1168  return -1;
1169  }
1170 
1171  TRACE(":fd (%d) by 0x%08x mode %s\n",
1172  fd,nbytes,(mode==_LK_UNLCK)?"_LK_UNLCK":
1173  (mode==_LK_LOCK)?"_LK_LOCK":
1174  (mode==_LK_NBLCK)?"_LK_NBLCK":
1175  (mode==_LK_RLCK)?"_LK_RLCK":
1176  (mode==_LK_NBRLCK)?"_LK_NBRLCK":
1177  "UNKNOWN");
1178 
1179  if ((cur_locn = SetFilePointer(hand, 0L, NULL, SEEK_CUR)) == INVALID_SET_FILE_POINTER)
1180  {
1181  FIXME ("Seek failed\n");
1182  *_errno() = EINVAL; /* FIXME */
1183  return -1;
1184  }
1185  if (mode == _LK_LOCK || mode == _LK_RLCK)
1186  {
1187  int nretry = 10;
1188  ret = 1; /* just to satisfy gcc */
1189  while (nretry--)
1190  {
1191  ret = LockFile(hand, cur_locn, 0L, nbytes, 0L);
1192  if (ret) break;
1193  Sleep(1);
1194  }
1195  }
1196  else if (mode == _LK_UNLCK)
1197  ret = UnlockFile(hand, cur_locn, 0L, nbytes, 0L);
1198  else
1199  ret = LockFile(hand, cur_locn, 0L, nbytes, 0L);
1200  /* FIXME - what about error settings? */
1201  return ret ? 0 : -1;
1202 }
#define _LK_NBRLCK
Definition: locking.h:19
#define SEEK_CUR
Definition: util.h:63
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:113
HANDLE fdtoh(int fd)
Definition: file.c:230
Definition: bidi.c:75
Definition: arc.h:39
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
BOOL WINAPI UnlockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToUnlockLow, IN DWORD nNumberOfBytesToUnlockHigh)
Definition: lock.c:142
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:557
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _LK_LOCK
Definition: locking.h:16
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
BOOL WINAPI LockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh)
Definition: lock.c:25
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
#define _LK_RLCK
Definition: locking.h:18
#define _LK_UNLCK
Definition: locking.h:15
#define _LK_NBLCK
Definition: locking.h:17
LONG CDECL _lseek ( int  fd,
LONG  offset,
int  whence 
)

Definition at line 1120 of file file.c.

Referenced by _filelength(), _tell(), _write(), test__creat(), test_chsize(), test_fflush(), and test_file_write_read().

1121 {
1122  return (LONG)_lseeki64(fd, offset, whence);
1123 }
long LONG
Definition: pedump.c:60
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1080
static HANDLE fd
Definition: io.c:55
GLintptr offset
Definition: glext.h:5920
__int64 CDECL _lseeki64 ( int  fd,
__int64  offset,
int  whence 
)

Definition at line 1080 of file file.c.

Referenced by _chsize_s(), _filelengthi64(), _fseeki64(), _ftelli64(), _lseek(), _telli64(), and fsetpos().

1081 {
1082  HANDLE hand = fdtoh(fd);
1083  LARGE_INTEGER ofs;
1084 
1085  TRACE(":fd (%d) handle (%p)\n",fd,hand);
1086  if (hand == INVALID_HANDLE_VALUE)
1087  return -1;
1088 
1089  if (whence < 0 || whence > 2)
1090  {
1091  *_errno() = EINVAL;
1092  return -1;
1093  }
1094 
1095  TRACE(":fd (%d) to %s pos %s\n",
1097  (whence==SEEK_SET)?"SEEK_SET":
1098  (whence==SEEK_CUR)?"SEEK_CUR":
1099  (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
1100 
1101  /* The MoleBox protection scheme expects msvcrt to use SetFilePointer only,
1102  * so a LARGE_INTEGER offset cannot be passed directly via SetFilePointerEx. */
1103  ofs.QuadPart = offset;
1104  if ((ofs.u.LowPart = SetFilePointer(hand, ofs.u.LowPart, &ofs.u.HighPart, whence)) != INVALID_SET_FILE_POINTER ||
1106  {
1108  /* FIXME: What if we seek _to_ EOF - is EOF set? */
1109 
1110  return ofs.QuadPart;
1111  }
1112  TRACE(":error-last error (%d)\n",GetLastError());
1114  return -1;
1115 }
#define SEEK_CUR
Definition: util.h:63
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:113
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK void ULONG PLARGE_INTEGER offset
Definition: file.c:85
#define ERROR_SUCCESS
Definition: deptool.c:10
HANDLE fdtoh(int fd)
Definition: file.c:230
Definition: arc.h:39
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
struct _LARGE_INTEGER::@2037 u
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define SEEK_SET
Definition: jmemansi.c:26
unsigned char wxflag
Definition: file.c:41
#define TRACE(s)
Definition: solgame.cpp:4
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define WX_READEOF
Definition: file.c:93
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
#define WX_ATEOF
Definition: file.c:91
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
#define SEEK_END
Definition: cabinet.c:21
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
LONGLONG QuadPart
Definition: typedefs.h:112
GLintptr offset
Definition: glext.h:5920
char* CDECL _mktemp ( char pattern)

Definition at line 1533 of file file.c.

Referenced by test_mktemp().

1534 {
1535  int numX = 0;
1536  char *retVal = pattern;
1537  int id;
1538  char letter = 'a';
1539 
1540  if(!pattern)
1541  return NULL;
1542 
1543  while(*pattern)
1544  numX = (*pattern++ == 'X')? numX + 1 : 0;
1545  if (numX < 6)
1546  return NULL;
1547  pattern--;
1548  id = GetCurrentProcessId();
1549  numX = 6;
1550  while(numX--)
1551  {
1552  int tempNum = id / 10;
1553  *pattern-- = id - (tempNum * 10) + '0';
1554  id = tempNum;
1555  }
1556  pattern++;
1557  do
1558  {
1559  *pattern = letter++;
1561  return retVal;
1562  } while(letter <= 'z');
1563  return NULL;
1564 }
#define INVALID_FILE_ATTRIBUTES
Definition: test.h:47
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:766
smooth NULL
Definition: ftsmooth.c:557
GLenum GLuint id
Definition: glext.h:5579
GLubyte * pattern
Definition: glext.h:7787
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1203
int CDECL _open ( const char path,
int  flags,
  ... 
)

Definition at line 1932 of file file.c.

Referenced by _creat(), compat_open(), install_from_unix_file(), main(), process_file(), rd_open_file(), rw(), test_chsize(), test_file_write_read(), test_get_osfhandle(), test_setmode(), and tmpfile().

1933 {
1934  va_list ap;
1935 
1936  if (flags & _O_CREAT)
1937  {
1938  int pmode;
1939  va_start(ap, flags);
1940  pmode = va_arg(ap, int);
1941  va_end(ap);
1942  return _sopen( path, flags, _SH_DENYNO, pmode );
1943  }
1944  else
1945  return _sopen( path, flags, _SH_DENYNO);
1946 }
#define _O_CREAT
Definition: cabinet.h:54
#define _SH_DENYNO
Definition: share.h:17
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
int int pmode
Definition: fci.h:172
int CDECL _sopen(const char *path, int oflags, int shflags,...)
Definition: file.c:1909
GLbitfield flags
Definition: glext.h:7161
#define va_arg(ap, T)
Definition: acmsvcex.h:89
Definition: services.c:311
#define va_start(ap, A)
Definition: acmsvcex.h:91
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
int CDECL _open_osfhandle ( intptr_t  handle,
int  oflags 
)

Definition at line 1988 of file file.c.

Referenced by test__open_osfhandle(), and test_close().

1989 {
1990  DWORD flags;
1991  int fd;
1992 
1993  /* _O_RDONLY (0) always matches, so set the read flag
1994  * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
1995  * file, so set the write flag. It also only sets _O_TEXT if it wants
1996  * text - it never sets _O_BINARY.
1997  */
1998  /* don't let split_oflags() decide the mode if no mode is passed */
1999  if (!(oflags & (_O_BINARY | _O_TEXT)))
2000  oflags |= _O_BINARY;
2001 
2002  flags = GetFileType((HANDLE)handle);
2003  if (flags==FILE_TYPE_UNKNOWN && GetLastError()!=NO_ERROR)
2004  {
2006  return -1;
2007  }
2008 
2009  if (flags == FILE_TYPE_CHAR)
2010  flags = WX_TTY;
2011  else if (flags == FILE_TYPE_PIPE)
2012  flags = WX_PIPE;
2013  else
2014  flags = 0;
2015  flags |= split_oflags(oflags);
2016 
2017  fd = msvcrt_alloc_fd((HANDLE)handle, flags);
2018  TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle, fd, flags);
2019  return fd;
2020 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define WX_PIPE
Definition: file.c:94
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:399
#define FILE_TYPE_UNKNOWN
Definition: winbase.h:253
unsigned split_oflags(unsigned oflags)
Definition: file.c:1600
#define NO_ERROR
Definition: dderror.h:5
DWORD DWORD
Definition: winlogon.h:75
#define WX_TTY
Definition: file.c:98
#define FILE_TYPE_CHAR
Definition: winbase.h:255
int msvcrt_alloc_fd(HANDLE hand, int flag)
Definition: file.c:341
#define TRACE(s)
Definition: solgame.cpp:4
GLbitfield flags
Definition: glext.h:7161
#define _O_BINARY
Definition: cabinet.h:59
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
#define FILE_TYPE_PIPE
Definition: winbase.h:256
#define _O_TEXT
Definition: cabinet.h:58
int CDECL _pipe ( int pfds,
unsigned int  psize,
int  textmode 
)

Definition at line 1631 of file file.c.

Referenced by test_pipes(), and test_stat().

1632 {
1633  int ret = -1;
1635  HANDLE readHandle, writeHandle;
1636 
1637  if (!pfds)
1638  {
1639  *_errno() = EINVAL;
1640  return -1;
1641  }
1642 
1643  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
1644  sa.bInheritHandle = !(textmode & _O_NOINHERIT);
1646  if (CreatePipe(&readHandle, &writeHandle, &sa, psize))
1647  {
1648  unsigned int wxflags = split_oflags(textmode);
1649  int fd;
1650 
1651  LOCK_FILES();
1652  fd = msvcrt_alloc_fd(readHandle, wxflags);
1653  if (fd != -1)
1654  {
1655  pfds[0] = fd;
1656  fd = msvcrt_alloc_fd(writeHandle, wxflags);
1657  if (fd != -1)
1658  {
1659  pfds[1] = fd;
1660  ret = 0;
1661  }
1662  else
1663  {
1664  _close(pfds[0]);
1665  CloseHandle(writeHandle);
1666  *_errno() = EMFILE;
1667  }
1668  }
1669  else
1670  {
1671  CloseHandle(readHandle);
1672  CloseHandle(writeHandle);
1673  *_errno() = EMFILE;
1674  }
1675  UNLOCK_FILES();
1676  }
1677  else
1679 
1680  return ret;
1681 }
#define CloseHandle
Definition: compat.h:398
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569
Definition: arc.h:39
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
unsigned split_oflags(unsigned oflags)
Definition: file.c:1600
#define _O_NOINHERIT
Definition: cabinet.h:53
smooth NULL
Definition: ftsmooth.c:557
int msvcrt_alloc_fd(HANDLE hand, int flag)
Definition: file.c:341
#define UNLOCK_FILES()
Definition: file.c:169
int CDECL _close(int fd)
Definition: file.c:905
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
#define LOCK_FILES()
Definition: file.c:168
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:28
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
LPVOID lpSecurityDescriptor
Definition: compat.h:181
Definition: arc.h:42
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
int CDECL _putw ( int  val,
FILE file 
)

Definition at line 2680 of file file.c.

2681 {
2682  int len;
2683 
2684  _lock_file(file);
2685  len = _write(file->_file, &val, sizeof(val));
2686  if (len == sizeof(val)) {
2687  _unlock_file(file);
2688  return val;
2689  }
2690 
2691  file->_flag |= _IOERR;
2692  _unlock_file(file);
2693  return EOF;
2694 }
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
#define _IOERR
Definition: stdio.h:134
GLuint GLfloat * val
Definition: glext.h:7180
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
int CDECL _write(int fd, const void *buf, unsigned int count)
Definition: file.c:2509
GLenum GLsizei len
Definition: glext.h:6722
int _flag
Definition: mbstring.h:23
#define EOF
Definition: stdio.h:24
int _file
Definition: mbstring.h:24
wint_t CDECL _putwch ( wchar_t  c)

Definition at line 3617 of file file.c.

3618 {
3619  return fputwc(c, stdout);
3620 }
wint_t CDECL fputwc(wchar_t c, FILE *stream)
Definition: file.c:3061
FILE * stdout
const GLubyte * c
Definition: glext.h:8905
int CDECL _putws ( const wchar_t s)

Definition at line 3644 of file file.c.

3645 {
3646  static const wchar_t nl = '\n';
3647  size_t len = strlenW(s);
3648  int ret;
3649 
3650  _lock_file(stdout);
3651  if(fwrite(s, sizeof(*s), len, stdout) != len) {
3653  return EOF;
3654  }
3655 
3656  ret = fwrite(&nl,sizeof(nl),1,stdout) == 1 ? 0 : EOF;
3658  return ret;
3659 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
FILE * stdout
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:2991
int ret
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
#define EOF
Definition: stdio.h:24
int CDECL _read ( int  fd,
void buf,
unsigned int  count 
)

Definition at line 2400 of file file.c.

Referenced by fread(), test__creat(), and test_file_write_read().

2401 {
2402  int num_read;
2403  num_read = read_i(fd, buf, count);
2404  return num_read;
2405 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
static HANDLE fd
Definition: io.c:55
static int read_i(int fd, void *buf, unsigned int count)
Definition: file.c:2238
int CDECL _rmtmp ( void  )

Definition at line 2025 of file file.c.

2026 {
2027  int num_removed = 0, i;
2028  FILE *file;
2029 
2030  LOCK_FILES();
2031  for (i = 3; i < MSVCRT_stream_idx; i++) {
2032  file = msvcrt_get_file(i);
2033 
2034  if (file->_tmpfname)
2035  {
2036  fclose(file);
2037  num_removed++;
2038  }
2039  }
2040  UNLOCK_FILES();
2041 
2042  if (num_removed)
2043  TRACE(":removed (%d) temp files\n",num_removed);
2044  return num_removed;
2045 }
static int MSVCRT_stream_idx
Definition: file.c:145
char * _tmpfname
Definition: mbstring.h:27
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define UNLOCK_FILES()
Definition: file.c:169
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:168
static FILE * msvcrt_get_file(int i)
Definition: file.c:193
int CDECL fclose(FILE *file)
Definition: file.c:2699
int CDECL _setmaxstdio ( int  newmax)

Definition at line 3950 of file file.c.

Referenced by test_setmaxstdio().

3951 {
3952  TRACE("%d\n", newmax);
3953 
3954  if(newmax<_IOB_ENTRIES || newmax>MSVCRT_MAX_FILES || newmax<MSVCRT_stream_idx)
3955  return -1;
3956 
3957  MSVCRT_max_streams = newmax;
3958  return MSVCRT_max_streams;
3959 }
static int MSVCRT_stream_idx
Definition: file.c:145
static int MSVCRT_max_streams
Definition: file.c:145
#define TRACE(s)
Definition: solgame.cpp:4
#define MSVCRT_MAX_FILES
Definition: file.c:110
int CDECL _setmode ( int  fd,
int  mode 
)

Definition at line 2410 of file file.c.

Referenced by test_setmode().

2411 {
2413  if(ret==_O_TEXT && (get_ioinfo(fd)->exflag & (EF_UTF8|EF_UTF16)))
2414  ret = _O_WTEXT;
2415 
2416  if(mode!=_O_TEXT && mode!=_O_BINARY && mode!=_O_WTEXT
2417  && mode!=_O_U16TEXT && mode!=_O_U8TEXT) {
2418  *_errno() = EINVAL;
2419  return -1;
2420  }
2421 
2422  if(mode == _O_BINARY) {
2423  get_ioinfo(fd)->wxflag &= ~WX_TEXT;
2425  return ret;
2426  }
2427 
2428  get_ioinfo(fd)->wxflag |= WX_TEXT;
2429  if(mode == _O_TEXT)
2431  else if(mode == _O_U8TEXT)
2433  else
2435 
2436  return ret;
2437 
2438 }
Definition: arc.h:39
#define _O_WTEXT
Definition: fcntl.h:20
#define WX_TEXT
Definition: file.c:99
int exflag
Definition: file.c:43
#define _O_U8TEXT
Definition: fcntl.h:22
unsigned char wxflag
Definition: file.c:41
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define _O_U16TEXT
Definition: fcntl.h:21
int ret
#define _O_BINARY
Definition: cabinet.h:59
static HANDLE fd
Definition: io.c:55
#define _O_TEXT
Definition: cabinet.h:58
#define EF_UTF8
Definition: file.c:102
#define EF_UTF16
Definition: file.c:103
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
int CDECL _sopen ( const char path,
int  oflags,
int  shflags,
  ... 
)

Definition at line 1909 of file file.c.

Referenced by _open(), and test_get_osfhandle().

1910 {
1911  int pmode;
1912  int fd;
1913 
1914  if (oflags & _O_CREAT)
1915  {
1916  va_list ap;
1917 
1918  va_start(ap, shflags);
1919  pmode = va_arg(ap, int);
1920  va_end(ap);
1921  }
1922  else
1923  pmode = 0;
1924 
1925  _sopen_s(&fd, path, oflags, shflags, pmode);
1926  return fd;
1927 }
#define _O_CREAT
Definition: cabinet.h:54
int CDECL _sopen_s(int *fd, const char *path, int oflags, int shflags, int pmode)
Definition: file.c:1893
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
int int pmode
Definition: fci.h:172
#define va_arg(ap, T)
Definition: acmsvcex.h:89
static HANDLE fd
Definition: io.c:55
Definition: services.c:311
#define va_start(ap, A)
Definition: acmsvcex.h:91
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
int CDECL _sopen_s ( int fd,
const char path,
int  oflags,
int  shflags,
int  pmode 
)

Definition at line 1893 of file file.c.

Referenced by _sopen().

1894 {
1895  wchar_t *pathW;
1896  int ret;
1897 
1898  if(!MSVCRT_CHECK_PMT(path && (pathW = msvcrt_wstrdupa(path))))
1899  return EINVAL;
1900 
1901  ret = _wsopen_s(fd, pathW, oflags, shflags, pmode);
1902  free(pathW);
1903  return ret;
1904 }
Definition: arc.h:39
#define free
Definition: debug_ros.c:5
wchar_t * msvcrt_wstrdupa(const char *str)
Definition: file.c:653
int int pmode
Definition: fci.h:172
int CDECL _wsopen_s(int *fd, const wchar_t *path, int oflags, int shflags, int pmode)
Definition: file.c:1709
int ret
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
static HANDLE fd
Definition: io.c:55
Definition: services.c:311
long CDECL _tell ( int  fd)

Definition at line 2443 of file file.c.

Referenced by test__creat().

2444 {
2445  return _lseek(fd, 0, SEEK_CUR);
2446 }
#define SEEK_CUR
Definition: util.h:63
LONG CDECL _lseek(int fd, LONG offset, int whence)
Definition: file.c:1120
static HANDLE fd
Definition: io.c:55
__int64 CDECL _telli64 ( int  fd)

Definition at line 2451 of file file.c.

Referenced by _ftelli64().

2452 {
2453  return _lseeki64(fd, 0, SEEK_CUR);
2454 }
#define SEEK_CUR
Definition: util.h:63
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1080
static HANDLE fd
Definition: io.c:55
char* CDECL _tempnam ( const char dir,
const char prefix 
)

Definition at line 2459 of file file.c.

Referenced by test_chsize(), test_ctrlz(), test_fflush(), test_fgetc(), test_fgetwc(), test_file_put_get(), test_file_write_read(), test_flsbuf(), test_fputc(), and test_write_flush().

2460 {
2461  char tmpbuf[MAX_PATH];
2462  const char *tmp_dir = getenv("TMP");
2463 
2464  if (tmp_dir) dir = tmp_dir;
2465 
2466  TRACE("dir (%s) prefix (%s)\n",dir,prefix);
2467  if (GetTempFileNameA(dir,prefix,0,tmpbuf))
2468  {
2469  TRACE("got name (%s)\n",tmpbuf);
2470  DeleteFileA(tmpbuf);
2471  return _strdup(tmpbuf);
2472  }
2473  TRACE("failed (%d)\n",GetLastError());
2474  return NULL;
2475 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define _strdup
Definition: debug_ros.c:7
PIN_DIRECTION dir
Definition: strmbase.h:226
smooth NULL
Definition: ftsmooth.c:557
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define TRACE(s)
Definition: solgame.cpp:4
#define MAX_PATH
Definition: compat.h:26
const XML_Char * prefix
Definition: expat.h:380
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
int CDECL _umask ( int  umask)

Definition at line 2498 of file file.c.

2499 {
2500  int old_umask = MSVCRT_umask;
2501  TRACE("(%d)\n",umask);
2502  MSVCRT_umask = umask;
2503  return old_umask;
2504 }
static int MSVCRT_umask
Definition: file.c:148
#define TRACE(s)
Definition: solgame.cpp:4
_CRTIMP int __cdecl umask(_In_ int _Mode)
int CDECL _unlink ( const char path)

Definition at line 786 of file file.c.

Referenced by test__wfopen_s(), test_chsize(), test_fopen_fclose_fcloseall(), test_fopen_s(), test_fputwc(), test_get_osfhandle(), test_setmode(), and test_unlink().

787 {
788  TRACE("%s\n",debugstr_a(path));
789  if(DeleteFileA(path))
790  return 0;
791  TRACE("failed (%d)\n",GetLastError());
793  return -1;
794 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:311
void CDECL _unlock_file ( FILE file)

Definition at line 1140 of file file.c.

Referenced by _filbuf(), _fseeki64(), _ftelli64(), _getw(), _getws(), _putw(), _putws(), clearerr(), fclose(), fflush(), fgetc(), fgets(), fgetwc(), fgetws(), fputc(), fputs(), fputws(), fread(), fsetpos(), fwrite(), gets(), puts(), rewind(), setvbuf(), ungetc(), and ungetwc().

1141 {
1142  if(file>=_iob && file<_iob+_IOB_ENTRIES)
1143  _unlock(_STREAM_LOCKS+(file-_iob));
1144  /* ReactOS: string streams dont need to be locked */
1145  else if(!(file->_flag & _IOSTRG))
1146  LeaveCriticalSection(&((file_crit*)file)->crit);
1147 
1148 }
void _unlock(int locknum)
Definition: lock.c:126
#define _STREAM_LOCKS
Definition: mtdll.h:65
#define _IOSTRG
Definition: stdio.h:135
#define _IOB_ENTRIES
Definition: stdio.h:23
int _flag
Definition: mbstring.h:23
FILE _iob[_IOB_ENTRIES]
Definition: file.c:143
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
int CDECL _waccess ( const wchar_t filename,
int  mode 
)

Definition at line 711 of file file.c.

Referenced by _waccess_s().

712 {
714 
715  TRACE("(%s,%d) %d\n",debugstr_w(filename),mode,attr);
716 
717  if (!filename || attr == INVALID_FILE_ATTRIBUTES)
718  {
720  return -1;
721  }
722  if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
723  {
725  return -1;
726  }
727  return 0;
728 }
errno_t __cdecl _set_errno(_In_ int _Value)
#define INVALID_FILE_ATTRIBUTES
Definition: test.h:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:782
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
Definition: cookie.c:158
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define W_OK
Definition: io.h:170
static char filename[MAX_PATH]
Definition: file.c:64
int CDECL _waccess_s ( const wchar_t filename,
int  mode 
)

Definition at line 733 of file file.c.

734 {
735  if (!MSVCRT_CHECK_PMT(filename != NULL) ||
736  !MSVCRT_CHECK_PMT((mode & ~(R_OK | W_OK)) == 0))
737  {
738  *_errno() = EINVAL;
739  return -1;
740  }
741 
742  return _waccess(filename, mode);
743 }
Definition: arc.h:39
#define R_OK
Definition: io.h:171
smooth NULL
Definition: ftsmooth.c:557
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int CDECL _waccess(const wchar_t *filename, int mode)
Definition: file.c:711
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define W_OK
Definition: io.h:170
static char filename[MAX_PATH]
Definition: file.c:64
int CDECL _wchmod ( const wchar_t path,
int  flags 
)

Definition at line 767 of file file.c.

768 {
769  DWORD oldFlags = GetFileAttributesW(path);
770 
771  if (oldFlags != INVALID_FILE_ATTRIBUTES)
772  {
773  DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY:
774  oldFlags | FILE_ATTRIBUTE_READONLY;
775 
776  if (newFlags == oldFlags || SetFileAttributesW(path, newFlags))
777  return 0;
778  }
780  return -1;
781 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:924
#define INVALID_FILE_ATTRIBUTES
Definition: test.h:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:782
#define _S_IWRITE
Definition: cabinet.h:41
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
GLbitfield flags
Definition: glext.h:7161
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:311
int CDECL _wcreat ( const wchar_t path,
int  flags 
)

Definition at line 1979 of file file.c.

1980 {
1981  int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC;
1982  return _wopen(path, usedFlags);
1983 }
#define _O_CREAT
Definition: cabinet.h:54
int CDECL _wopen(const wchar_t *path, int flags,...)
Definition: file.c:1951
#define _O_TRUNC
Definition: cabinet.h:55
GLbitfield flags
Definition: glext.h:7161
#define _O_WRONLY
Definition: cabinet.h:46
Definition: services.c:311
#define _O_TEXT
Definition: cabinet.h:58
FILE* CDECL _wfdopen ( int  fd,
const wchar_t mode 
)

Definition at line 1451 of file file.c.

Referenced by _fdopen().

1452 {
1453  int open_flags, stream_flags;
1454  FILE* file;
1455 
1456  if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) return NULL;
1457 
1458  LOCK_FILES();
1459  if (!(file = msvcrt_alloc_fp()))
1460  file = NULL;
1461  else if (msvcrt_init_fp(file, fd, stream_flags) == -1)
1462  {
1463  file->_flag = 0;
1464  file = NULL;
1465  }
1466  else TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file);
1467  UNLOCK_FILES();
1468 
1469  return file;
1470 }
static int msvcrt_init_fp(FILE *file, int fd, unsigned stream_flags)
Definition: file.c:376
static int msvcrt_get_flags(const wchar_t *mode, int *open_flags, int *stream_flags)
Definition: file.c:1316
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:557
#define UNLOCK_FILES()
Definition: file.c:169
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:168
int _flag
Definition: mbstring.h:23
static HANDLE fd
Definition: io.c:55
static FILE * msvcrt_alloc_fp(void)
Definition: file.c:354
FILE* CDECL _wfopen ( const wchar_t path,
const wchar_t mode 
)

Definition at line 3188 of file file.c.

Referenced by _wfopen_s().

3189 {
3190  return _wfsopen( path, mode, _SH_DENYNO );
3191 }
#define _SH_DENYNO
Definition: share.h:17
FILE *CDECL _wfsopen(const wchar_t *path, const wchar_t *mode, int share)
Definition: file.c:3101
Definition: services.c:311
int CDECL _wfopen_s ( FILE **  pFile,
const wchar_t filename,
const wchar_t mode 
)

Definition at line 3196 of file file.c.

3198 {
3199  if (!MSVCRT_CHECK_PMT(pFile != NULL) || !MSVCRT_CHECK_PMT(filename != NULL) ||
3200  !MSVCRT_CHECK_PMT(mode != NULL)) {
3201  *_errno() = EINVAL;
3202  return EINVAL;
3203  }
3204 
3205  *pFile = _wfopen(filename, mode);
3206 
3207  if(!*pFile)
3208  return *_errno();
3209  return 0;
3210 }
Definition: arc.h:39
smooth NULL
Definition: ftsmooth.c:557
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
FILE *CDECL _wfopen(const wchar_t *path, const wchar_t *mode)
Definition: file.c:3188
static char filename[MAX_PATH]
Definition: file.c:64
FILE* CDECL _wfreopen ( const wchar_t path,
const wchar_t mode,
FILE file 
)

Definition at line 3335 of file file.c.

Referenced by freopen().

3336 {
3337  int open_flags, stream_flags, fd;
3338 
3339  TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path), debugstr_w(mode), file, file ? file->_file : -1);
3340 
3341  LOCK_FILES();
3342  if (!file || ((fd = file->_file) < 0) || fd > fdend)
3343  file = NULL;
3344  else
3345  {
3346  fclose(file);
3347  /* map mode string to open() flags. "man fopen" for possibilities. */
3348  if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1)
3349  file = NULL;
3350  else
3351  {
3352  fd = _wopen(path, open_flags, _S_IREAD | _S_IWRITE);
3353  if (fd < 0)
3354  file = NULL;
3355  else if (msvcrt_init_fp(file, fd, stream_flags) == -1)
3356  {
3357  file->_flag = 0;
3358  WARN(":failed-last error (%d)\n",GetLastError());
3360  file = NULL;
3361  }
3362  }
3363  }
3364  UNLOCK_FILES();
3365  return file;
3366 }
#define _S_IREAD
Definition: cabinet.h:42
#define WARN(fmt,...)
Definition: debug.h:111
int CDECL _wopen(const wchar_t *path, int flags,...)
Definition: file.c:1951
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
static int msvcrt_init_fp(FILE *file, int fd, unsigned stream_flags)
Definition: file.c:376
static int msvcrt_get_flags(const wchar_t *mode, int *open_flags, int *stream_flags)
Definition: file.c:1316
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:557
#define _S_IWRITE
Definition: cabinet.h:41
#define UNLOCK_FILES()
Definition: file.c:169
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:168
int _flag
Definition: mbstring.h:23
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
static HANDLE fd
Definition: io.c:55
Definition: services.c:311
static int fdend
Definition: file.c:136
int _file
Definition: mbstring.h:24
int CDECL fclose(FILE *file)
Definition: file.c:2699
FILE* CDECL _wfsopen ( const wchar_t path,
const wchar_t mode,
int  share 
)

Definition at line 3101 of file file.c.

Referenced by _fsopen(), and _wfopen().

3102 {
3103  FILE* file;
3104  int open_flags, stream_flags, fd;
3105 
3106  TRACE("(%s,%s)\n", debugstr_w(path), debugstr_w(mode));
3107 
3108  /* map mode string to open() flags. "man fopen" for possibilities. */
3109  if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1)
3110  return NULL;
3111 
3112  LOCK_FILES();
3113  fd = _wsopen(path, open_flags, share, _S_IREAD | _S_IWRITE);
3114  if (fd < 0)
3115  file = NULL;
3116  else if ((file = msvcrt_alloc_fp()) && msvcrt_init_fp(file, fd, stream_flags)
3117  != -1)
3118  TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file);
3119  else if (file)
3120  {
3121  file->_flag = 0;
3122  file = NULL;
3123  }
3124 
3125  TRACE(":got (%p)\n",file);
3126  if (fd >= 0 && !file)
3127  _close(fd);
3128  UNLOCK_FILES();
3129  return file;
3130 }
#define _S_IREAD
Definition: cabinet.h:42
static int msvcrt_init_fp(FILE *file, int fd, unsigned stream_flags)
Definition: file.c:376
static int msvcrt_get_flags(const wchar_t *mode, int *open_flags, int *stream_flags)
Definition: file.c:1316
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:557
#define _S_IWRITE
Definition: cabinet.h:41
#define UNLOCK_FILES()
Definition: file.c:169
int CDECL _close(int fd)
Definition: file.c:905
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:168
int _flag
Definition: mbstring.h:23
static HANDLE fd
Definition: io.c:55
Definition: services.c:311
int CDECL _wsopen(const wchar_t *path, int oflags, int shflags,...)
Definition: file.c:1870
static FILE * msvcrt_alloc_fp(void)
Definition: file.c:354
wchar_t* CDECL _wmktemp ( wchar_t pattern)

Definition at line 1569 of file file.c.

1570 {
1571  int numX = 0;
1572  wchar_t *retVal = pattern;
1573  int id;
1574  wchar_t letter = 'a';
1575 
1576  while(*pattern)
1577  numX = (*pattern++ == 'X')? numX + 1 : 0;
1578  if (numX < 5)
1579  return NULL;
1580  pattern--;
1581  id = GetCurrentProcessId();
1582  numX = 6;
1583  while(numX--)
1584  {
1585  int tempNum = id / 10;
1586  *pattern-- = id - (tempNum * 10) + '0';
1587  id = tempNum;
1588  }
1589  pattern++;
1590  do
1591  {
1594  return retVal;
1595  *pattern = letter++;
1596  } while(letter != '|');
1597  return NULL;
1598 }
#define INVALID_FILE_ATTRIBUTES
Definition: test.h:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:782
smooth NULL
Definition: ftsmooth.c:557
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
GLenum GLuint id
Definition: glext.h:5579
GLubyte * pattern
Definition: glext.h:7787
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1203
int CDECL _wopen ( const wchar_t path,
int  flags,
  ... 
)

Definition at line 1951 of file file.c.

Referenced by _wcreat(), _wfreopen(), compat_open(), and gz_open().

1952 {
1953  va_list ap;
1954 
1955  if (flags & _O_CREAT)
1956  {
1957  int pmode;
1958  va_start(ap, flags);
1959  pmode = va_arg(ap, int);
1960  va_end(ap);
1961  return _wsopen( path, flags, _SH_DENYNO, pmode );
1962  }
1963  else
1964  return _wsopen( path, flags, _SH_DENYNO);
1965 }
#define _O_CREAT
Definition: cabinet.h:54
#define _SH_DENYNO
Definition: share.h:17
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
int int pmode
Definition: fci.h:172
GLbitfield flags
Definition: glext.h:7161
#define va_arg(ap, T)
Definition: acmsvcex.h:89
Definition: services.c:311
#define va_start(ap, A)
Definition: acmsvcex.h:91
int CDECL _wsopen(const wchar_t *path, int oflags, int shflags,...)
Definition: file.c:1870
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
int CDECL _wremove ( const wchar_t path)

Definition at line 3677 of file file.c.

3678 {
3679  TRACE("(%s)\n",debugstr_w(path));
3680  if (DeleteFileW(path))
3681  return 0;
3682  TRACE(":failed (%d)\n",GetLastError());
3684  return -1;
3685 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define debugstr_w
Definition: kernel32.h:32
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define TRACE(s)
Definition: solgame.cpp:4
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:311
int CDECL _wrename ( const wchar_t oldpath,
const wchar_t newpath 
)

Definition at line 3703 of file file.c.

3704 {
3705  TRACE(":from %s to %s\n",debugstr_w(oldpath),debugstr_w(newpath));
3706  if (MoveFileExW(oldpath, newpath, MOVEFILE_COPY_ALLOWED))
3707  return 0;
3708  TRACE(":failed (%d)\n",GetLastError());
3710  return -1;
3711 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
#define MOVEFILE_COPY_ALLOWED
Definition: winbase.h:371
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
BOOL WINAPI MoveFileExW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName OPTIONAL, IN DWORD dwFlags)
Definition: move.c:1060
int CDECL _write ( int  fd,
const void buf,
unsigned int  count 
)

Definition at line 2509 of file file.c.

Referenced by _putw(), fwrite(), msvcrt_flush_buffer(), test__creat(), test_chsize(), and test_file_write_read().

2510 {
2511  DWORD num_written;
2512  ioinfo *info = get_ioinfo(fd);
2513  HANDLE hand = info->handle;
2514 
2515  /* Don't trace small writes, it gets *very* annoying */
2516 #if 0
2517  if (count > 32)
2518  TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd,hand,buf,count);
2519 #endif
2520  if (hand == INVALID_HANDLE_VALUE)
2521  {
2522  *_errno() = EBADF;
2523  return -1;
2524  }
2525 
2526  if (((info->exflag&EF_UTF8) || (info->exflag&EF_UTF16)) && count&1)
2527  {
2528  *_errno() = EINVAL;
2529  return -1;
2530  }
2531 
2532  /* If appending, go to EOF */
2533  if (info->wxflag & WX_APPEND)
2534  _lseek(fd, 0, FILE_END);
2535 
2536  if (!(info->wxflag & WX_TEXT))
2537  {
2538  if (WriteFile(hand, buf, count, &num_written, NULL)
2539  && (num_written == count))
2540  return num_written;
2541  TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd,
2542  hand, GetLastError());
2543  *_errno() = ENOSPC;
2544  }
2545  else
2546  {
2547  unsigned int i, j, nr_lf, size;
2548  char *p = NULL;
2549  const char *q;
2550  const char *s = buf, *buf_start = buf;
2551 
2552  if (!(info->exflag & (EF_UTF8|EF_UTF16)))
2553  {
2554  /* find number of \n */
2555  for (nr_lf=0, i=0; i<count; i++)
2556  if (s[i] == '\n')
2557  nr_lf++;
2558  if (nr_lf)
2559  {
2560  size = count+nr_lf;
2561  if ((q = p = malloc(size)))
2562  {
2563  for (s = buf, i = 0, j = 0; i < count; i++)
2564  {
2565  if (s[i] == '\n')
2566  p[j++] = '\r';
2567  p[j++] = s[i];
2568  }
2569  }
2570  else
2571  {
2572  FIXME("Malloc failed\n");
2573  nr_lf = 0;
2574  size = count;
2575  q = buf;
2576  }
2577  }
2578  else
2579  {
2580  size = count;
2581  q = buf;
2582  }
2583  }
2584  else if (info->exflag & EF_UTF16)
2585  {
2586  for (nr_lf=0, i=0; i<count; i+=2)
2587  if (s[i]=='\n' && s[i+1]==0)
2588  nr_lf += 2;
2589  if (nr_lf)
2590  {
2591  size = count+nr_lf;
2592  if ((q = p = malloc(size)))
2593  {
2594  for (s=buf, i=0, j=0; i<count; i++)
2595  {
2596  if (s[i]=='\n' && s[i+1]==0)
2597  {
2598  p[j++] = '\r';
2599  p[j++] = 0;
2600  }
2601  p[j++] = s[i++];
2602  p[j++] = s[i];
2603  }
2604  }
2605  else
2606  {
2607  FIXME("Malloc failed\n");
2608  nr_lf = 0;
2609  size = count;
2610  q = buf;
2611  }
2612  }
2613  else
2614  {
2615  size = count;
2616  q = buf;
2617  }
2618  }
2619  else
2620  {
2621  DWORD conv_len;
2622 
2623  for(nr_lf=0, i=0; i<count; i+=2)
2624  if (s[i]=='\n' && s[i+1]==0)
2625  nr_lf++;
2626 
2627  conv_len = WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)buf, count/2, NULL, 0, NULL, NULL);
2628  if(!conv_len) {
2630  free(p);
2631  return -1;
2632  }
2633 
2634  size = conv_len+nr_lf;
2635  if((p = malloc(count+nr_lf*2+size)))
2636  {
2637  for (s=buf, i=0, j=0; i<count; i++)
2638  {
2639  if (s[i]=='\n' && s[i+1]==0)
2640  {
2641  p[j++] = '\r';
2642  p[j++] = 0;
2643  }
2644  p[j++] = s[i++];
2645  p[j++] = s[i];
2646  }
2647  q = p+count+nr_lf*2;
2648  WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)p, count/2+nr_lf,
2649  p+count+nr_lf*2, conv_len+nr_lf, NULL, NULL);
2650  }
2651  else
2652  {
2653  FIXME("Malloc failed\n");
2654  nr_lf = 0;
2655  size = count;
2656  q = buf;
2657  }
2658  }
2659 
2660  if (!WriteFile(hand, q, size, &num_written, NULL))
2661  num_written = -1;
2662  if(p)
2663  free(p);
2664  if (num_written != size)
2665  {
2666  TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
2667  fd, hand, GetLastError(), num_written);
2668  *_errno() = ENOSPC;
2669  return s - buf_start;
2670  }
2671  return count;
2672  }
2673 
2674  return -1;
2675 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define WideCharToMultiByte
Definition: compat.h:101
Definition: file.c:39
__wchar_t WCHAR
Definition: xmlstorage.h:180
Definition: arc.h:39
#define free
Definition: debug_ros.c:5
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: compobj.c:613
#define WX_APPEND
Definition: file.c:97
Definition: arc.h:36
DWORD DWORD
Definition: winlogon.h:75
#define WX_TEXT
Definition: file.c:99
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define CP_UTF8
Definition: nls.h:20
HANDLE handle
Definition: file.c:40
#define FIXME(fmt,...)
Definition: debug.h:110
Definition: arc.h:49
smooth NULL
Definition: ftsmooth.c:557
int exflag
Definition: file.c:43
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned char wxflag
Definition: file.c:41
#define TRACE(s)
Definition: solgame.cpp:4
#define FILE_END
Definition: winbase.h:112
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
LONG CDECL _lseek(int fd, LONG offset, int whence)
Definition: file.c:1120
GLdouble s
Definition: gl.h:2039
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
GLsizeiptr size
Definition: glext.h:5919
#define EF_UTF8
Definition: file.c:102
#define EF_UTF16
Definition: file.c:103
#define malloc
Definition: debug_ros.c:4
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
GLfloat GLfloat p
Definition: glext.h:8902
int CDECL _wsopen ( const wchar_t path,
int  oflags,
int  shflags,
  ... 
)

Definition at line 1870 of file file.c.

Referenced by _wfsopen(), and _wopen().

1871 {
1872  int pmode;
1873  int fd;
1874 
1875  if (oflags & _O_CREAT)
1876  {
1877  __ms_va_list ap;
1878 
1879  __ms_va_start(ap, shflags);
1880  pmode = va_arg(ap, int);
1881  __ms_va_end(ap);
1882  }
1883  else
1884  pmode = 0;
1885 
1886  _wsopen_s(&fd, path, oflags, shflags, pmode);
1887  return fd;
1888 }
static const char __ms_va_list
Definition: printf.c:70
#define _O_CREAT
Definition: cabinet.h:54
int int pmode
Definition: fci.h:172
int CDECL _wsopen_s(int *fd, const wchar_t *path, int oflags, int shflags, int pmode)
Definition: file.c:1709
#define va_arg(ap, T)
Definition: acmsvcex.h:89
static HANDLE fd
Definition: io.c:55
Definition: services.c:311
#define __ms_va_end(list)
Definition: windef.h:471
#define __ms_va_start(list, arg)
Definition: windef.h:470
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
int CDECL _wsopen_s ( int fd,
const wchar_t path,
int  oflags,
int  shflags,
int  pmode 
)

Definition at line 1709 of file file.c.

Referenced by _sopen_s(), and _wsopen().

1710 {
1711  DWORD access = 0, creation = 0, attrib;
1713  DWORD sharing, type;
1714  int wxflag;
1715  HANDLE hand;
1716 
1717  TRACE("fd*: %p :file (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n",
1718  fd, debugstr_w(path), oflags, shflags, pmode);
1719 
1720  if (!MSVCRT_CHECK_PMT( fd != NULL )) return EINVAL;
1721 
1722  *fd = -1;
1723  wxflag = split_oflags(oflags);
1724  switch (oflags & (_O_RDONLY | _O_WRONLY | _O_RDWR))
1725  {
1726  case _O_RDONLY: access |= GENERIC_READ; break;
1727  case _O_WRONLY: access |= GENERIC_WRITE; break;
1728  case _O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break;
1729  }
1730 
1731  if (oflags & _O_CREAT)
1732  {
1733  if(pmode & ~(_S_IREAD | _S_IWRITE))
1734  FIXME(": pmode 0x%04x ignored\n", pmode);
1735  else
1736  WARN(": pmode 0x%04x ignored\n", pmode);
1737 
1738  if (oflags & _O_EXCL)
1739  creation = CREATE_NEW;
1740  else if (oflags & _O_TRUNC)
1741  creation = CREATE_ALWAYS;
1742  else
1743  creation = OPEN_ALWAYS;
1744  }
1745  else /* no _O_CREAT */
1746  {
1747  if (oflags & _O_TRUNC)
1748  creation = TRUNCATE_EXISTING;
1749  else
1750  creation = OPEN_EXISTING;
1751  }
1752 
1753  switch( shflags )
1754  {
1755  case _SH_DENYRW:
1756  sharing = 0L;
1757  break;
1758  case _SH_DENYWR:
1759  sharing = FILE_SHARE_READ;
1760  break;
1761  case _SH_DENYRD:
1762  sharing = FILE_SHARE_WRITE;
1763  break;
1764  case _SH_DENYNO:
1765  sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
1766  break;
1767  default:
1768  ERR( "Unhandled shflags 0x%x\n", shflags );
1769  return EINVAL;
1770  }
1771  attrib = FILE_ATTRIBUTE_NORMAL;
1772 
1773  if (oflags & _O_TEMPORARY)
1774  {
1775  attrib |= FILE_FLAG_DELETE_ON_CLOSE;
1776  access |= DELETE;
1777  sharing |= FILE_SHARE_DELETE;
1778  }
1779 
1780  sa.nLength = sizeof( SECURITY_ATTRIBUTES );
1782  sa.bInheritHandle = !(oflags & _O_NOINHERIT);
1783 
1784  if ((oflags&(_O_WTEXT|_O_U16TEXT|_O_U8TEXT))
1785  && (creation==OPEN_ALWAYS || creation==OPEN_EXISTING)
1786  && !(access&GENERIC_READ))
1787  {
1790  if (hand != INVALID_HANDLE_VALUE)
1791  {
1792  oflags = check_bom(hand, oflags, FALSE);
1793  CloseHandle(hand);
1794  }
1795  else
1796  oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT);
1797  }
1798 
1799  hand = CreateFileW(path, access, sharing, &sa, creation, attrib, 0);
1800  if (hand == INVALID_HANDLE_VALUE) {
1801  WARN(":failed-last error (%d)\n",GetLastError());
1803  return *_errno();
1804  }
1805 
1806  if (oflags & (_O_WTEXT|_O_U16TEXT|_O_U8TEXT))
1807  {
1808  if ((access & GENERIC_WRITE) && (creation==CREATE_NEW
1809  || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING
1810  || (creation==OPEN_ALWAYS && GetLastError()==ERROR_ALREADY_EXISTS)))
1811  {
1812  if (oflags & _O_U8TEXT)
1813  {
1814  DWORD written = 0, tmp;
1815 
1816  while(written!=sizeof(utf8_bom) && WriteFile(hand, (char*)utf8_bom+written,
1817  sizeof(utf8_bom)-written, &tmp, NULL))
1818  written += tmp;
1819  if (written != sizeof(utf8_bom)) {
1820  WARN("error writing BOM\n");
1821  CloseHandle(hand);
1823  return *_errno();
1824  }
1825  }
1826  else
1827  {
1828  DWORD written = 0, tmp;
1829 
1830  while(written!=sizeof(utf16_bom) && WriteFile(hand, (char*)utf16_bom+written,
1831  sizeof(utf16_bom)-written, &tmp, NULL))
1832  written += tmp;
1833  if (written != sizeof(utf16_bom))
1834  {
1835  WARN("error writing BOM\n");
1836  CloseHandle(hand);
1838  return *_errno();
1839  }
1840  }
1841  }
1842  else if (access & GENERIC_READ)
1843  oflags = check_bom(hand, oflags, TRUE);
1844  }
1845 
1846  type = GetFileType(hand);
1847  if (type == FILE_TYPE_CHAR)
1848  wxflag |= WX_TTY;
1849  else if (type == FILE_TYPE_PIPE)
1850  wxflag |= WX_PIPE;
1851 
1852  *fd = msvcrt_alloc_fd(hand, wxflag);
1853  if (*fd == -1)
1854  return *_errno();
1855 
1856  if (oflags & _O_WTEXT)
1858  else if (oflags & _O_U16TEXT)
1859  get_ioinfo(*fd)->exflag |= EF_UTF16;
1860  else if (oflags & _O_U8TEXT)
1861  get_ioinfo(*fd)->exflag |= EF_UTF8;
1862 
1863  TRACE(":fd (%d) handle (%p)\n", *fd, hand);
1864  return 0;
1865 }
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG sharing
Definition: pipe.c:68
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define _O_RDONLY
Definition: cabinet.h:45
#define _S_IREAD
Definition: cabinet.h:42
Definition: bidi.c:75
Definition: arc.h:39
static char utf8_bom[3]
Definition: file.c:106
#define _O_CREAT
Definition: cabinet.h:54
#define WARN(fmt,...)
Definition: debug.h:111
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define WX_PIPE
Definition: file.c:94
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:399
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
unsigned split_oflags(unsigned oflags)
Definition: file.c:1600
DWORD DWORD
Definition: winlogon.h:75
#define FILE_SHARE_READ
Definition: compat.h:125
#define _O_WTEXT
Definition: fcntl.h:20
#define _SH_DENYNO
Definition: share.h:17
#define _O_RDWR
Definition: cabinet.h:47
#define _O_EXCL
Definition: cabinet.h:56
#define _O_NOINHERIT
Definition: cabinet.h:53
#define WX_TTY
Definition: file.c:98
#define FALSE
Definition: types.h:117
#define FILE_TYPE_CHAR
Definition: winbase.h:255
#define GENERIC_WRITE
Definition: nt_native.h:90
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:557
int exflag
Definition: file.c:43
int int pmode
Definition: fci.h:172
#define _O_TRUNC
Definition: cabinet.h:55
#define _S_IWRITE
Definition: cabinet.h:41
int msvcrt_alloc_fd(HANDLE hand, int flag)
Definition: file.c:341
#define _SH_DENYWR
Definition: share.h:15
#define OPEN_EXISTING
Definition: compat.h:426
#define _O_U8TEXT
Definition: fcntl.h:22
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define TRACE(s)
Definition: solgame.cpp:4
#define _SH_DENYRW
Definition: share.h:14
if(!(yy_init))
Definition: macro.lex.yy.c:704
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define OPEN_ALWAYS
Definition: disk.h:70
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define _O_U16TEXT
Definition: fcntl.h:21
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define GENERIC_READ
Definition: compat.h:124
#define _SH_DENYRD
Definition: share.h:16
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define _O_WRONLY
Definition: cabinet.h:46
#define ERR(fmt,...)
Definition: debug.h:109
static char utf16_bom[2]
Definition: file.c:107
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
#define FILE_TYPE_PIPE
Definition: winbase.h:256
LPVOID lpSecurityDescriptor
Definition: compat.h:181
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
Definition: services.c:311
#define EF_UTF8
Definition: file.c:102
#define CreateFileW
Definition: compat.h:400
#define EF_UTF16
Definition: file.c:103
#define _O_TEMPORARY
Definition: cabinet.h:52
#define EF_UNK_UNICODE
Definition: file.c:104
#define CREATE_NEW
Definition: disk.h:69
#define TRUNCATE_EXISTING
Definition: disk.h:71
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
static int check_bom(HANDLE h, int oflags, BOOL seek)
Definition: file.c:1683
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define DELETE
Definition: nt_native.h:57
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
wchar_t* CDECL _wtempnam ( const wchar_t dir,
const wchar_t prefix 
)

Definition at line 2480 of file file.c.

2481 {
2482  wchar_t tmpbuf[MAX_PATH];
2483 
2484  TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir),debugstr_w(prefix));
2485  if (GetTempFileNameW(dir,prefix,0,tmpbuf))
2486  {
2487  TRACE("got name (%s)\n",debugstr_w(tmpbuf));
2488  DeleteFileW(tmpbuf);
2489  return _wcsdup(tmpbuf);
2490  }
2491  TRACE("failed (%d)\n",GetLastError());
2492  return NULL;
2493 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define debugstr_w
Definition: kernel32.h:32
PIN_DIRECTION dir
Definition: strmbase.h:226
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:557
#define TRACE(s)
Definition: solgame.cpp:4
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
const XML_Char * prefix
Definition: expat.h:380
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
wchar_t* CDECL _wtmpnam ( wchar_t s)

Definition at line 3796 of file file.c.

3797 {
3798  static const wchar_t format[] = {'\\','s','%','s','.',0};
3799  wchar_t tmpstr[16];
3800  wchar_t *p;
3801  int count, size;
3802  if (!s) {
3804 
3805  if(!data->wtmpnam_buffer)
3806  data->wtmpnam_buffer = malloc(sizeof(wchar_t[MAX_PATH]));
3807 
3808  s = data->wtmpnam_buffer;
3809  }
3810 
3812  p = s + _snwprintf(s, MAX_PATH, format, tmpstr);
3813  for (count = 0; count < TMP_MAX; count++)
3814  {
3815  size = msvcrt_int_to_base32_w(tmpnam_unique++, tmpstr);
3816  memcpy(p, tmpstr, size*sizeof(wchar_t));
3817  p[size] = '\0';
3820  break;
3821  }
3822  return s;
3823 }
#define TMP_MAX
Definition: stdio.h:67
static int tmpnam_unique
Definition: file.c:151
#define INVALID_FILE_ATTRIBUTES
Definition: test.h:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
_CRTIMP int __cdecl _snwprintf(wchar_t *_Dest, size_t _Count, const wchar_t *_Format,...)
static int msvcrt_int_to_base32_w(int num, wchar_t *str)
Definition: file.c:628
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:782
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define MAX_PATH
Definition: compat.h:26
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31
GLsizeiptr size
Definition: glext.h:5919
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1203
int CDECL _wunlink ( const wchar_t path)

Definition at line 799 of file file.c.

800 {
801  TRACE("(%s)\n",debugstr_w(path));
802  if(DeleteFileW(path))
803  return 0;
804  TRACE("failed (%d)\n",GetLastError());
806  return -1;
807 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define debugstr_w
Definition: kernel32.h:32
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define TRACE(s)
Definition: solgame.cpp:4
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:311
static BOOL add_std_buffer ( FILE file)
static

Definition at line 577 of file file.c.

Referenced by fputws().

578 {
579  static char buffers[2][BUFSIZ];
580 
581  if((file->_file!=STDOUT_FILENO && file->_file!=STDERR_FILENO)
582  || (file->_flag & (_IONBF | _IOMYBUF | _USERBUF))
583  || !_isatty(file->_file))
584  return FALSE;
585 
586  file->_ptr = file->_base = buffers[file->_file == STDOUT_FILENO ? 0 : 1];
587  file->_bufsiz = file->_cnt = BUFSIZ;
588  file->_flag |= _USERBUF;
589  return TRUE;
590 }
#define _USERBUF
Definition: stdio.h:137
char * _base
Definition: mbstring.h:22
#define TRUE
Definition: types.h:120
int _cnt
Definition: mbstring.h:21
char * _ptr
Definition: mbstring.h:20
const GLuint * buffers
Definition: glext.h:5916
#define BUFSIZ
Definition: nsplookup.c:26
int CDECL _isatty(int fd)
Definition: file.c:548
#define FALSE
Definition: types.h:117
#define STDOUT_FILENO
Definition: syshdrs.h:89
#define _IOMYBUF
Definition: stdio.h:132
int _bufsiz
Definition: mbstring.h:26
int _flag
Definition: mbstring.h:23
int _file
Definition: mbstring.h:24
#define _IONBF
Definition: stdio.h:130
#define STDERR_FILENO
Definition: syshdrs.h:90
static int check_bom ( HANDLE  h,
int  oflags,
BOOL  seek 
)
static

Definition at line 1683 of file file.c.

Referenced by _wsopen_s().

1684 {
1685  char bom[sizeof(utf8_bom)];
1686  DWORD r;
1687 
1688  oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT);
1689 
1690  if (!ReadFile(h, bom, sizeof(utf8_bom), &r, NULL))
1691  return oflags;
1692 
1693  if (r==sizeof(utf8_bom) && !memcmp(bom, utf8_bom, sizeof(utf8_bom))) {
1694  oflags |= _O_U8TEXT;
1695  }else if (r>=sizeof(utf16_bom) && !memcmp(bom, utf16_bom, sizeof(utf16_bom))) {
1696  if (seek && r>2)
1698  oflags |= _O_U16TEXT;
1699  }else if (seek) {
1701  }
1702 
1703  return oflags;
1704 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
static char utf8_bom[3]
Definition: file.c:106
DWORD DWORD
Definition: winlogon.h:75
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define _O_WTEXT
Definition: fcntl.h:20
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
smooth NULL
Definition: ftsmooth.c:557
#define _O_U8TEXT
Definition: fcntl.h:22
#define _O_U16TEXT
Definition: fcntl.h:21
int seek(void *fd, ulong off, int mode)
Definition: pe.c:51
static char utf16_bom[2]
Definition: file.c:107
#define FILE_BEGIN
Definition: winbase.h:110
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
void CDECL clearerr ( FILE file)

Definition at line 1294 of file file.c.

Referenced by rewind(), and ungetc().

1295 {
1296  TRACE(":file (%p) fd (%d)\n",file,file->_file);
1297 
1298  _lock_file(file);
1299  file->_flag &= ~(_IOERR | _IOEOF);
1300  _unlock_file(file);
1301 }
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
#define _IOERR
Definition: stdio.h:134
#define _IOEOF
Definition: stdio.h:133
#define TRACE(s)
Definition: solgame.cpp:4
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
int _flag
Definition: mbstring.h:23
int _file
Definition: mbstring.h:24
unsigned create_io_inherit_block ( WORD size,
BYTE **  block 
)

Definition at line 405 of file file.c.

406 {
407  int fd;
408  char* wxflag_ptr;
409  HANDLE* handle_ptr;
410  ioinfo* fdinfo;
411 
412  *size = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * fdend;
413  *block = calloc(1, *size);
414  if (!*block)
415  {
416  *size = 0;
417  return FALSE;
418  }
419  wxflag_ptr = (char*)*block + sizeof(unsigned);
420  handle_ptr = (HANDLE*)(wxflag_ptr + fdend * sizeof(char));
421 
422  *(unsigned*)*block = fdend;
423  for (fd = 0; fd < fdend; fd++)
424  {
425  /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
426  fdinfo = get_ioinfo(fd);
427  if ((fdinfo->wxflag & (WX_OPEN | WX_DONTINHERIT)) == WX_OPEN)
428  {
429  *wxflag_ptr = fdinfo->wxflag;
430  *handle_ptr = fdinfo->handle;
431  }
432  else
433  {
434  *wxflag_ptr = 0;
435  *handle_ptr = INVALID_HANDLE_VALUE;
436  }
437  wxflag_ptr++; handle_ptr++;
438  }
439  return TRUE;
440 }
static unsigned int block
Definition: xmlmemory.c:118
#define TRUE
Definition: types.h:120
Definition: file.c:39
#define WX_DONTINHERIT
Definition: file.c:96
static HANDLE
Definition: file.c:105
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FALSE
Definition: types.h:117
HANDLE handle
Definition: file.c:40
unsigned char wxflag
Definition: file.c:41
#define WX_OPEN
Definition: file.c:90
DWORD *typedef HANDLE
Definition: winlogon.h:52
static HANDLE fd
Definition: io.c:55
GLsizeiptr size
Definition: glext.h:5919
static int fdend
Definition: file.c:136
#define calloc
Definition: rosglue.h:14
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
int CDECL fclose ( FILE file)

Definition at line 2699 of file file.c.

Referenced by _fcloseall(), _rmtmp(), _wfreopen(), test__wfopen_s(), test_asciimode(), test_asciimode2(), test_ctrlz(), test_fdopen(), test_fflush(), test_fgetc(), test_fgetwc(), test_fgetwc_locale(), test_fgetwc_unicode(), test_filbuf(), test_file_put_get(), test_filemodeT(), test_fileops(), test_flsbuf(), test_fopen_fclose_fcloseall(), test_fopen_s(), test_fputc(), test_fputwc(), test_pipes(), test_readboundary(), test_readmode(), test_unlink(), and test_write_flush().

2700 {
2701  int r, flag;
2702 
2703  _lock_file(file);
2704  flag = file->_flag;
2705  free(file->_tmpfname);
2706  file->_tmpfname = NULL;
2707  /* flush stdio buffers */
2708  if(file->_flag & _IOWRT)
2709  fflush(file);
2710  if(file->_flag & _IOMYBUF)
2711  free(file->_base);
2712 
2713  r=_close(file->_file);
2714 
2715  file->_flag = 0;
2716  _unlock_file(file);
2718  DeleteCriticalSection(&((file_crit*)file)->crit);
2719 
2720  if(file == msvcrt_get_file(MSVCRT_stream_idx-1)) {
2721  while(MSVCRT_stream_idx>3 && !file->_flag) {
2724  }
2725  }
2726 
2727  return ((r == -1) || (flag & _IOERR) ? EOF : 0);
2728 }
char * _base
Definition: mbstring.h:22
static int MSVCRT_stream_idx
Definition: file.c:145
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
char * _tmpfname
Definition: mbstring.h:27
#define _IOERR
Definition: stdio.h:134
#define _IOB_ENTRIES
Definition: stdio.h:23
smooth NULL
Definition: ftsmooth.c:557
int CDECL _close(int fd)
Definition: file.c:905
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean flag
Definition: glfuncs.h:72
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
#define _IOWRT
Definition: stdio.h:126
#define _IOMYBUF
Definition: stdio.h:132
int _flag
Definition: mbstring.h:23
int CDECL fflush(FILE *file)
Definition: file.c:875
static FILE * msvcrt_get_file(int i)
Definition: file.c:193
#define EOF
Definition: stdio.h:24
int _file
Definition: mbstring.h:24
FILE _iob[_IOB_ENTRIES]
Definition: file.c:143
Definition: fci.c:114
HANDLE fdtoh ( int  fd)

Definition at line 230 of file file.c.

Referenced by _chsize_s(), _close(), _commit(), _eof(), _fstat64(), _futime(), _get_osfhandle(), _locking(), _lseeki64(), and read_i().

231 {
232  if (!is_valid_fd(fd))
233  {
234  WARN(":fd (%d) - no handle!\n",fd);
235  *__doserrno() = 0;
236  *_errno() = EBADF;
237  return INVALID_HANDLE_VALUE;
238  }
239  //if (get_ioinfo(fd)->handle == INVALID_HANDLE_VALUE)
240  //FIXME("returning INVALID_HANDLE_VALUE for %d\n", fd);
241  return get_ioinfo(fd)->handle;
242 }
_CRTIMP unsigned long *__cdecl __doserrno(void)
Definition: errno.c:27
#define WARN(fmt,...)
Definition: debug.h:111
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static BOOL is_valid_fd(int fd)
Definition: file.c:219
Definition: arc.h:36
HANDLE handle
Definition: file.c:40
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
static HANDLE fd
Definition: io.c:55
static ioinfo * get_ioinfo(int fd)
Definition: file.c:182
int CDECL feof ( FILE file)

Definition at line 2733 of file file.c.

Referenced by test_ctrlz(), test_fileops(), test_pipes(), and test_readmode().

2734 {
2735  return file->_flag & _IOEOF;
2736 }
#define _IOEOF
Definition: stdio.h:133
int _flag
Definition: mbstring.h:23
int CDECL ferror ( FILE file)

Definition at line 2741 of file file.c.

Referenced by test_pipes().

2742 {
2743  return file->_flag & _IOERR;
2744 }
#define _IOERR
Definition: stdio.h:134
int _flag
Definition: mbstring.h:23
int CDECL fflush ( FILE file)

Definition at line 875 of file file.c.

Referenced by fclose(), msvcrt_flush_all_buffers(), setvbuf(), test_fflush(), and test_write_flush_size().

876 {
877  if(!file) {
879  } else if(file->_flag & _IOWRT) {
880  int res;
881 
882  _lock_file(file);
883  res = msvcrt_flush_buffer(file);
884  /* FIXME
885  if(!res && (file->_flag & _IOCOMMIT))
886  res = _commit(file->_file) ? EOF : 0;
887  */
888  _unlock_file(file);
889 
890  return res;
891  } else if(file->_flag & _IOREAD) {
892  _lock_file(file);
893  file->_cnt = 0;
894  file->_ptr = file->_base;
895  _unlock_file(file);
896 
897  return 0;
898  }
899  return 0;
900 }
char * _base
Definition: mbstring.h:22
int _cnt
Definition: mbstring.h:21
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
char * _ptr
Definition: mbstring.h:20
#define _IOREAD
Definition: stdio.h:125
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
#define _IOWRT
Definition: stdio.h:126
int _flag
Definition: mbstring.h:23
static int msvcrt_flush_all_buffers(int mask)
Definition: file.c:841
GLuint res
Definition: glext.h:9613
static int msvcrt_flush_buffer(FILE *file)
Definition: file.c:519
int CDECL fgetc ( FILE file)

Definition at line 2802 of file file.c.

Referenced by _fgetchar(), _getw(), fgets(), fgetwc(), getc(), getchar(), gets(), test_asciimode(), test_fgetc(), test_fgetwc(), test_fileops(), test_flsbuf(), and test_readboundary().

2803 {
2804  unsigned char *i;
2805  unsigned int j;
2806 
2807  _lock_file(file);
2808  if (file->_cnt>0) {
2809  file->_cnt--;
2810  i = (unsigned char *)file->_ptr++;
2811  j = *i;
2812  } else
2813  j = _filbuf(file);
2814 
2815  _unlock_file(file);
2816  return j;
2817 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
int _cnt
Definition: mbstring.h:21
void CDECL _unlock_file(FILE *file)
Definition: file.c:1140
char * _ptr
Definition: mbstring.h:20
GLenum GLclampf GLint i
Definition: glfuncs.h:14
int CDECL _filbuf(FILE *file)
Definition: file.c:2749
void CDECL _lock_file(FILE *file)
Definition: file.c:1128
int CDECL fgetpos ( FILE file,
fpos_t pos 
)

Definition at line 3488 of file file.c.

Referenced by test_filbuf(), test_fileops(), and test_write_flush_size().

3489 {
3490  *pos = _ftelli64(file);
3491  if(*pos == -1)
3492  return -1;
3493  return 0;
3494 }
__int64 CDECL _ftelli64(FILE *file)
Definition: file.c:3420
char* CDECL fgets ( char s,
int  size,
FILE file 
)

Definition at line 2830 of file file.c.

Referenced by test_asciimode(), test_ctrlz(), test_file_put_get(), test_fileops(), and test_readmode().

2831 {
2832  int cc = EOF;
2833  char * buf_start = s;
2834 
2835  TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
2836  file,file->_file,s,size);
2837 
2838  _lock_file(file);
2839 
2840  while ((size >1) && (cc = fgetc(file)) != EOF && cc != '\n')
2841  {
2842  *s++ = (char)cc;
2843