ReactOS  0.4.11-dev-765-g5e024bf
file.c File Reference
#include <precomp.h>
#include "wine/unicode.h"
#include "internal/wine/msvcrt.h"
#include <sys/utime.h>
#include <direct.h>
Include dependency graph for file.c:

Go to the source code of this file.

Classes

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_CRIT_INIT   0x04
 
#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 void init_ioinfo_cs (ioinfo *info)
 
ioinfoget_ioinfo (int fd)
 
static BOOL alloc_pioinfo_block (int fd)
 
static ioinfoget_ioinfo_alloc_fd (int fd)
 
static ioinfoget_ioinfo_alloc (int *fd)
 
void release_ioinfo (ioinfo *info)
 
static FILEmsvcrt_get_file (int i)
 
static void msvcrt_free_fd (int fd)
 
static void msvcrt_set_fd (ioinfo *fdinfo, HANDLE hand, int flag)
 
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 (ioinfo *fdinfo, wchar_t *buf, unsigned int count)
 
static int read_i (int fd, ioinfo *fdinfo, 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 }
 
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 59 of file file.c.

Referenced by msvcrt_get_flags().

#define EF_CRIT_INIT   0x04

Definition at line 105 of file file.c.

Referenced by init_ioinfo_cs(), msvcrt_free_io(), msvcrt_set_fd(), and release_ioinfo().

#define EF_UNK_UNICODE   0x08

Definition at line 106 of file file.c.

Referenced by _wsopen_s().

#define EF_UTF16   0x02

Definition at line 104 of file file.c.

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

#define EF_UTF8   0x01

Definition at line 103 of file file.c.

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

#define MSVCRT_FD_BLOCK_SIZE   32

Definition at line 113 of file file.c.

Referenced by alloc_pioinfo_block(), get_ioinfo_nolock(), msvcrt_free_io(), and msvcrt_get_file().

#define MSVCRT_INTERNAL_BUFSIZ   4096

Definition at line 115 of file file.c.

Referenced by fwrite(), and msvcrt_alloc_buffer().

#define MSVCRT_MAX_FILES   2048
#define WX_APPEND   0x20

Definition at line 98 of file file.c.

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

#define WX_ATEOF   0x02

Definition at line 92 of file file.c.

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

#define WX_DONTINHERIT   0x10

Definition at line 97 of file file.c.

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

#define WX_OPEN   0x01
#define WX_PIPE   0x08

Definition at line 95 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 96 of file file.c.

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

Definition at line 94 of file file.c.

Referenced by _lseeki64().

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

Definition at line 93 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 683 of file file.c.

684 {
685  return &_iob[0];
686 }
FILE _iob[_IOB_ENTRIES]
Definition: file.c:133
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 691 of file file.c.

Referenced by _access_s().

692 {
694 
695  TRACE("(%s,%d) %d\n",filename,mode,attr);
696 
697  if (!filename || attr == INVALID_FILE_ATTRIBUTES)
698  {
700  return -1;
701  }
702  if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
703  {
705  return -1;
706  }
707  return 0;
708 }
errno_t __cdecl _set_errno(_In_ int _Value)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
const char * filename
Definition: ioapi.h:135
DWORD DWORD
Definition: winlogon.h:84
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:786
#define TRACE(s)
Definition: solgame.cpp:4
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
Definition: cookie.c:170
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define W_OK
Definition: io.h:170
int CDECL _access_s ( const char filename,
int  mode 
)

Definition at line 713 of file file.c.

714 {
715  if (!MSVCRT_CHECK_PMT(filename != NULL) ||
716  !MSVCRT_CHECK_PMT((mode & ~(R_OK | W_OK)) == 0))
717  {
719  return -1;
720  }
721 
722  return _access(filename, mode);
723 }
errno_t __cdecl _set_errno(_In_ int _Value)
Definition: arc.h:39
#define R_OK
Definition: io.h:171
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define W_OK
Definition: io.h:170
int CDECL _access(const char *filename, int mode)
Definition: file.c:691
int CDECL _chmod ( const char path,
int  flags 
)

Definition at line 765 of file file.c.

Referenced by test_file_write_read().

766 {
767  DWORD oldFlags = GetFileAttributesA(path);
768 
769  if (oldFlags != INVALID_FILE_ATTRIBUTES)
770  {
771  DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY:
772  oldFlags | FILE_ATTRIBUTE_READONLY;
773 
774  if (newFlags == oldFlags || SetFileAttributesA(path, newFlags))
775  return 0;
776  }
778  return -1;
779 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD DWORD
Definition: winlogon.h:84
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:786
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:926
#define _S_IWRITE
Definition: cabinet.h:33
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLbitfield flags
Definition: glext.h:7161
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:325
int CDECL _chsize ( int  fd,
long  size 
)

Definition at line 1354 of file file.c.

Referenced by test_chsize().

1355 {
1356  /* _chsize_s returns errno on failure but _chsize should return -1 */
1357  return _chsize_s( fd, size ) == 0 ? 0 : -1;
1358 }
static int fd
Definition: io.c:51
int CDECL _chsize_s(int fd, __int64 size)
Definition: file.c:1318
GLsizeiptr size
Definition: glext.h:5919
int CDECL _chsize_s ( int  fd,
__int64  size 
)

Definition at line 1318 of file file.c.

Referenced by _chsize().

1319 {
1320  ioinfo *info;
1321  __int64 cur, pos;
1322  BOOL ret = FALSE;
1323 
1324  TRACE("(fd=%d, size=%s)\n", fd, wine_dbgstr_longlong(size));
1325 
1326  if (!MSVCRT_CHECK_PMT(size >= 0)) return EINVAL;
1327 
1328  info = get_ioinfo(fd);
1329  if (info->handle != INVALID_HANDLE_VALUE)
1330  {
1331  /* save the current file pointer */
1332  cur = _lseeki64(fd, 0, SEEK_CUR);
1333  if (cur >= 0)
1334  {
1335  pos = _lseeki64(fd, size, SEEK_SET);
1336  if (pos >= 0)
1337  {
1338  ret = SetEndOfFile(info->handle);
1339  if (!ret) _dosmaperr(GetLastError());
1340  }
1341 
1342  /* restore the file pointer */
1343  _lseeki64(fd, cur, SEEK_SET);
1344  }
1345  }
1346 
1347  release_ioinfo(info);
1348  return ret ? 0 : *_errno();
1349 }
#define SEEK_CUR
Definition: util.h:63
Definition: file.c:40
Definition: arc.h:39
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static int fd
Definition: io.c:51
#define FALSE
Definition: types.h:117
HANDLE handle
Definition: file.c:41
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1138
#define SEEK_SET
Definition: jmemansi.c:26
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
void release_ioinfo(ioinfo *info)
Definition: file.c:263
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
const XML_Char XML_Encoding * info
Definition: expat.h:530
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 931 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().

932 {
933  ioinfo *info = get_ioinfo(fd);
934  int ret;
935 
936  TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
937  if (!(info->wxflag & WX_OPEN)) {
938  ret = -1;
939  } else if (fd == STDOUT_FILENO &&
942  ret = 0;
943  } else if (fd == STDERR_FILENO &&
946  ret = 0;
947  } else {
948  ret = CloseHandle(info->handle) ? 0 : -1;
950  if (ret) {
951  WARN(":failed-last error (%d)\n",GetLastError());
953  ret = -1;
954  }
955  }
956  release_ioinfo(info);
957  return ret;
958 }
#define CloseHandle
Definition: compat.h:398
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
Definition: file.c:40
#define WARN(fmt,...)
Definition: debug.h:111
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static int fd
Definition: io.c:51
static void msvcrt_free_fd(int fd)
Definition: file.c:296
HANDLE handle
Definition: file.c:41
#define STDOUT_FILENO
Definition: syshdrs.h:89
unsigned char wxflag
Definition: file.c:42
#define TRACE(s)
Definition: solgame.cpp:4
#define WX_OPEN
Definition: file.c:91
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
int ret
void release_ioinfo(ioinfo *info)
Definition: file.c:263
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define STDERR_FILENO
Definition: syshdrs.h:90
int CDECL _commit ( int  fd)

Definition at line 829 of file file.c.

830 {
831  ioinfo *info = get_ioinfo(fd);
832  int ret;
833 
834  TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
835  if (info->handle == INVALID_HANDLE_VALUE)
836  ret = -1;
837  else if (!FlushFileBuffers(info->handle))
838  {
840  {
841  /* FlushFileBuffers fails for console handles
842  * so we ignore this error.
843  */
844  ret = 0;
845  }
846  else
847  {
848  TRACE(":failed-last error (%d)\n",GetLastError());
850  ret = -1;
851  }
852  }
853  else
854  {
855  TRACE(":ok\n");
856  ret = 0;
857  }
858 
859  release_ioinfo(info);
860  return ret;
861 }
Definition: file.c:40
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static int fd
Definition: io.c:51
HANDLE handle
Definition: file.c:41
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:175
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
int ret
void release_ioinfo(ioinfo *info)
Definition: file.c:263
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
int CDECL _creat ( const char path,
int  flags 
)

Definition at line 2039 of file file.c.

Referenced by test__creat().

2040 {
2041  int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC;
2042  return _open(path, usedFlags);
2043 }
#define _O_CREAT
Definition: cabinet.h:46
#define _O_TRUNC
Definition: cabinet.h:47
GLbitfield flags
Definition: glext.h:7161
#define _O_WRONLY
Definition: cabinet.h:38
Definition: services.c:325
#define _O_TEXT
Definition: cabinet.h:50
int CDECL _open(const char *path, int flags,...)
Definition: file.c:2001
int CDECL _dup ( int  od)

Definition at line 1025 of file file.c.

Referenced by test_stdin().

1026 {
1027  int fd, ret;
1028  ioinfo *info = get_ioinfo_alloc(&fd);
1029 
1030  if (_dup2(od, fd) == 0)
1031  ret = fd;
1032  else
1033  ret = -1;
1034  release_ioinfo(info);
1035  return ret;
1036 }
Definition: file.c:40
static int fd
Definition: io.c:51
static ioinfo * get_ioinfo_alloc(int *fd)
Definition: file.c:230
int ret
void release_ioinfo(ioinfo *info)
Definition: file.c:263
int CDECL _dup2(int od, int nd)
Definition: file.c:967
int CDECL _dup2 ( int  od,
int  nd 
)

Definition at line 967 of file file.c.

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

968 {
969  ioinfo *info_od, *info_nd;
970  int ret;
971 
972  TRACE("(od=%d, nd=%d)\n", od, nd);
973 
974  if (od < nd)
975  {
976  info_od = get_ioinfo(od);
977  info_nd = get_ioinfo_alloc_fd(nd);
978  }
979  else
980  {
981  info_nd = get_ioinfo_alloc_fd(nd);
982  info_od = get_ioinfo(od);
983  }
984 
985  if (info_nd == &__badioinfo)
986  {
987  ret = -1;
988  }
989  else if (info_od->wxflag & WX_OPEN)
990  {
991  HANDLE handle;
992 
993  if (DuplicateHandle(GetCurrentProcess(), info_od->handle,
995  {
996  int wxflag = info_od->wxflag & ~_O_NOINHERIT;
997 
998  if (info_nd->wxflag & WX_OPEN)
999  _close(nd);
1000 
1001  msvcrt_set_fd(info_nd, handle, wxflag);
1002  /* _dup2 returns 0, not nd, on success */
1003  ret = 0;
1004  }
1005  else
1006  {
1007  ret = -1;
1009  }
1010  }
1011  else
1012  {
1013  *_errno() = EBADF;
1014  ret = -1;
1015  }
1016 
1017  release_ioinfo(info_od);
1018  release_ioinfo(info_nd);
1019  return ret;
1020 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
Definition: file.c:40
ioinfo __badioinfo
Definition: file.c:126
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
Definition: arc.h:36
#define _O_NOINHERIT
Definition: cabinet.h:45
#define DUPLICATE_SAME_ACCESS
HANDLE handle
Definition: file.c:41
int CDECL _close(int fd)
Definition: file.c:931
unsigned char wxflag
Definition: file.c:42
#define TRACE(s)
Definition: solgame.cpp:4
#define WX_OPEN
Definition: file.c:91
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
void release_ioinfo(ioinfo *info)
Definition: file.c:263
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:61
static ioinfo * get_ioinfo_alloc_fd(int fd)
Definition: file.c:216
static void msvcrt_set_fd(ioinfo *fdinfo, HANDLE hand, int flag)
Definition: file.c:325
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 1041 of file file.c.

1042 {
1043  ioinfo *info = get_ioinfo(fd);
1044  DWORD curpos,endpos;
1045  LONG hcurpos,hendpos;
1046 
1047  TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1048 
1049  if (info->handle == INVALID_HANDLE_VALUE)
1050  {
1051  release_ioinfo(info);
1052  return -1;
1053  }
1054 
1055  if (info->wxflag & WX_ATEOF)
1056  {
1057  release_ioinfo(info);
1058  return TRUE;
1059  }
1060 
1061  /* Otherwise we do it the hard way */
1062  hcurpos = hendpos = 0;
1063  curpos = SetFilePointer(info->handle, 0, &hcurpos, FILE_CURRENT);
1064  endpos = SetFilePointer(info->handle, 0, &hendpos, FILE_END);
1065 
1066  if (curpos == endpos && hcurpos == hendpos)
1067  {
1068  /* FIXME: shouldn't WX_ATEOF be set here? */
1069  release_ioinfo(info);
1070  return TRUE;
1071  }
1072 
1073  SetFilePointer(info->handle, curpos, &hcurpos, FILE_BEGIN);
1074  release_ioinfo(info);
1075  return FALSE;
1076 }
#define TRUE
Definition: types.h:120
Definition: file.c:40
#define FILE_CURRENT
Definition: winbase.h:113
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static int fd
Definition: io.c:51
DWORD DWORD
Definition: winlogon.h:84
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
HANDLE handle
Definition: file.c:41
unsigned char wxflag
Definition: file.c:42
#define TRACE(s)
Definition: solgame.cpp:4
#define FILE_END
Definition: winbase.h:114
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
void release_ioinfo(ioinfo *info)
Definition: file.c:263
#define FILE_BEGIN
Definition: winbase.h:112
#define WX_ATEOF
Definition: file.c:92
int CDECL _fcloseall ( void  )

Definition at line 1081 of file file.c.

Referenced by msvcrt_free_io(), and test_fopen_fclose_fcloseall().

1082 {
1083  int num_closed = 0, i;
1084  FILE *file;
1085 
1086  LOCK_FILES();
1087  for (i = 3; i < MSVCRT_stream_idx; i++) {
1088  file = msvcrt_get_file(i);
1089 
1090  if (file->_flag && !fclose(file))
1091  num_closed++;
1092  }
1093  UNLOCK_FILES();
1094 
1095  TRACE(":closed (%d) handles\n",num_closed);
1096  return num_closed;
1097 }
static int MSVCRT_stream_idx
Definition: file.c:135
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define UNLOCK_FILES()
Definition: file.c:156
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:155
int _flag
Definition: mbstring.h:23
static FILE * msvcrt_get_file(int i)
Definition: file.c:269
int CDECL fclose(FILE *file)
Definition: file.c:2783
FILE* CDECL _fdopen ( int  fd,
const char mode 
)

Definition at line 1504 of file file.c.

1505 {
1506  FILE *ret;
1507  wchar_t *modeW = NULL;
1508 
1509  if (mode && !(modeW = msvcrt_wstrdupa(mode))) return NULL;
1510 
1511  ret = _wfdopen(fd, modeW);
1512 
1513  free(modeW);
1514  return ret;
1515 }
#define free
Definition: debug_ros.c:5
static int fd
Definition: io.c:51
FILE *CDECL _wfdopen(int fd, const wchar_t *mode)
Definition: file.c:1520
wchar_t * msvcrt_wstrdupa(const char *str)
Definition: file.c:670
smooth NULL
Definition: ftsmooth.c:416
int ret
int CDECL _fgetchar ( void  )

Definition at line 2906 of file file.c.

2907 {
2908  return fgetc(stdin);
2909 }
FILE * stdin
int CDECL fgetc(FILE *file)
Definition: file.c:2886
wint_t CDECL _fgetwchar ( void  )

Definition at line 3027 of file file.c.

Referenced by getwchar().

3028 {
3029  return fgetwc(stdin);
3030 }
FILE * stdin
wint_t CDECL fgetwc(FILE *file)
Definition: file.c:2946
int CDECL _filbuf ( FILE file)

Definition at line 2833 of file file.c.

Referenced by fgetc(), and test_filbuf().

2834 {
2835  unsigned char c;
2836  _lock_file(file);
2837 
2838  if(file->_flag & _IOSTRG) {
2839  _unlock_file(file);
2840  return EOF;
2841  }
2842 
2843  /* Allocate buffer if needed */
2844  if(!(file->_flag & (_IONBF | _IOMYBUF | _USERBUF)))
2845  msvcrt_alloc_buffer(file);
2846 
2847  if(!(file->_flag & _IOREAD)) {
2848  if(file->_flag & _IORW)
2849  file->_flag |= _IOREAD;
2850  else {
2851  _unlock_file(file);
2852  return EOF;
2853  }
2854  }
2855 
2856  if(!(file->_flag & (_IOMYBUF | _USERBUF))) {
2857  int r;
2858  if ((r = _read(file->_file,&c,1)) != 1) {
2859  file->_flag |= (r == 0) ? _IOEOF : _IOERR;
2860  _unlock_file(file);
2861  return EOF;
2862  }
2863 
2864  _unlock_file(file);
2865  return c;
2866  } else {
2867  file->_cnt = _read(file->_file, file->_base, file->_bufsiz);
2868  if(file->_cnt<=0) {
2869  file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR;
2870  file->_cnt = 0;
2871  _unlock_file(file);
2872  return EOF;
2873  }
2874 
2875  file->_cnt--;
2876  file->_ptr = file->_base+1;
2877  c = *(unsigned char *)file->_base;
2878  _unlock_file(file);
2879  return c;
2880  }
2881 }
#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:1205
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
int CDECL _read(int fd, void *buf, unsigned int count)
Definition: file.c:2466
#define _IOEOF
Definition: stdio.h:133
void CDECL _lock_file(FILE *file)
Definition: file.c:1193
#define _IOMYBUF
Definition: stdio.h:132
BOOL msvcrt_alloc_buffer(FILE *file)
Definition: file.c:573
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
#define _IORW
Definition: stdio.h:136
LONG CDECL _filelength ( int  fd)

Definition at line 1544 of file file.c.

Referenced by test_chsize().

1545 {
1546  LONG curPos = _lseek(fd, 0, SEEK_CUR);
1547  if (curPos != -1)
1548  {
1549  LONG endPos = _lseek(fd, 0, SEEK_END);
1550  if (endPos != -1)
1551  {
1552  if (endPos != curPos)
1553  _lseek(fd, curPos, SEEK_SET);
1554  return endPos;
1555  }
1556  }
1557  return -1;
1558 }
#define SEEK_CUR
Definition: util.h:63
static int fd
Definition: io.c:51
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:1185
#define SEEK_END
Definition: cabinet.c:27
__int64 CDECL _filelengthi64 ( int  fd)

Definition at line 1563 of file file.c.

1564 {
1565  __int64 curPos = _lseeki64(fd, 0, SEEK_CUR);
1566  if (curPos != -1)
1567  {
1568  __int64 endPos = _lseeki64(fd, 0, SEEK_END);
1569  if (endPos != -1)
1570  {
1571  if (endPos != curPos)
1572  _lseeki64(fd, curPos, SEEK_SET);
1573  return endPos;
1574  }
1575  }
1576  return -1;
1577 }
#define SEEK_CUR
Definition: util.h:63
static int fd
Definition: io.c:51
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1138
#define SEEK_SET
Definition: jmemansi.c:26
#define SEEK_END
Definition: cabinet.c:27
#define __int64
Definition: basetyps.h:16
int CDECL _fileno ( FILE file)

Definition at line 1582 of file file.c.

Referenced by test_fflush().

1583 {
1584  TRACE(":FILE* (%p) fd (%d)\n",file,file->_file);
1585  return file->_file;
1586 }
#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(), test_flsbuf(), and test_invalid_stdin_child().

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:573
#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 893 of file file.c.

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

894 {
896 }
#define _IOREAD
Definition: stdio.h:125
#define _IOWRT
Definition: stdio.h:126
static int msvcrt_flush_all_buffers(int mask)
Definition: file.c:867
int CDECL _fputchar ( int  c)

Definition at line 3330 of file file.c.

3331 {
3332  return fputc(c, stdout);
3333 }
FILE * stdout
int CDECL fputc(int c, FILE *file)
Definition: file.c:3302
const GLubyte * c
Definition: glext.h:8905
wint_t CDECL _fputwchar ( wint_t  wc)

Definition at line 3177 of file file.c.

3178 {
3179  return fputwc(wc, stdout);
3180 }
wint_t CDECL fputwc(wchar_t c, FILE *stream)
Definition: file.c:3145
FILE * stdout
int CDECL _fseeki64 ( FILE file,
__int64  offset,
int  whence 
)

Definition at line 1278 of file file.c.

Referenced by fseek().

1279 {
1280  int ret;
1281 
1282  _lock_file(file);
1283  /* Flush output if needed */
1284  if(file->_flag & _IOWRT)
1285  msvcrt_flush_buffer(file);
1286 
1287  if(whence == SEEK_CUR && file->_flag & _IOREAD ) {
1288  whence = SEEK_SET;
1289  offset += _ftelli64(file);
1290  }
1291 
1292  /* Discard buffered input */
1293  file->_cnt = 0;
1294  file->_ptr = file->_base;
1295  /* Reset direction of i/o */
1296  if(file->_flag & _IORW) {
1297  file->_flag &= ~(_IOREAD|_IOWRT);
1298  }
1299  /* Clear end of file flag */
1300  file->_flag &= ~_IOEOF;
1301  ret = (_lseeki64(file->_file,offset,whence) == -1)?-1:0;
1302 
1303  _unlock_file(file);
1304  return ret;
1305 }
#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:1205
GLintptr offset
Definition: glext.h:5920
char * _ptr
Definition: mbstring.h:20
#define _IOREAD
Definition: stdio.h:125
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1138
#define _IOEOF
Definition: stdio.h:133
#define SEEK_SET
Definition: jmemansi.c:26
void CDECL _lock_file(FILE *file)
Definition: file.c:1193
#define _IOWRT
Definition: stdio.h:126
int ret
int _flag
Definition: mbstring.h:23
__int64 CDECL _ftelli64(FILE *file)
Definition: file.c:3504
int _file
Definition: mbstring.h:24
#define _IORW
Definition: stdio.h:136
static int msvcrt_flush_buffer(FILE *file)
Definition: file.c:536
FILE* CDECL _fsopen ( const char path,
const char mode,
int  share 
)

Definition at line 3219 of file file.c.

Referenced by fopen().

3220 {
3221  FILE *ret;
3222  wchar_t *pathW = NULL, *modeW = NULL;
3223 
3224  if (path && !(pathW = msvcrt_wstrdupa(path))) {
3225  _invalid_parameter(NULL, NULL, NULL, 0, 0);
3226  *_errno() = EINVAL;
3227  return NULL;
3228  }
3229  if (mode && !(modeW = msvcrt_wstrdupa(mode)))
3230  {
3231  free(pathW);
3232  _invalid_parameter(NULL, NULL, NULL, 0, 0);
3233  *_errno() = EINVAL;
3234  return NULL;
3235  }
3236 
3237  ret = _wfsopen(pathW, modeW, share);
3238 
3239  free(pathW);
3240  free(modeW);
3241  return ret;
3242 }
Definition: arc.h:39
#define free
Definition: debug_ros.c:5
wchar_t * msvcrt_wstrdupa(const char *str)
Definition: file.c:670
smooth NULL
Definition: ftsmooth.c:416
FILE *CDECL _wfsopen(const wchar_t *path, const wchar_t *mode, int share)
Definition: file.c:3185
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
Definition: services.c:325
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 3504 of file file.c.

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

3505 {
3506  __int64 pos;
3507 
3508  _lock_file(file);
3509  pos = _telli64(file->_file);
3510  if(pos == -1) {
3511  _unlock_file(file);
3512  return -1;
3513  }
3514  if(file->_flag & (_IOMYBUF | _USERBUF)) {
3515  if(file->_flag & _IOWRT) {
3516  pos += file->_ptr - file->_base;
3517 
3518  if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) {
3519  char *p;
3520 
3521  for(p=file->_base; p<file->_ptr; p++)
3522  if(*p == '\n')
3523  pos++;
3524  }
3525  } else if(!file->_cnt) { /* nothing to do */
3526  } else if(_lseeki64(file->_file, 0, SEEK_END)==pos) {
3527  int i;
3528 
3529  pos -= file->_cnt;
3530  if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) {
3531  for(i=0; i<file->_cnt; i++)
3532  if(file->_ptr[i] == '\n')
3533  pos--;
3534  }
3535  } else {
3536  char *p;
3537 
3538  if(_lseeki64(file->_file, pos, SEEK_SET) != pos) {
3539  _unlock_file(file);
3540  return -1;
3541  }
3542 
3543  pos -= file->_bufsiz;
3544  pos += file->_ptr - file->_base;
3545 
3546  if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) {
3547  if(get_ioinfo_nolock(file->_file)->wxflag & WX_READNL)
3548  pos--;
3549 
3550  for(p=file->_base; p<file->_ptr; p++)
3551  if(*p == '\n')
3552  pos++;
3553  }
3554  }
3555  }
3556 
3557  _unlock_file(file);
3558  return pos;
3559 }
#define _USERBUF
Definition: stdio.h:137
char * _base
Definition: mbstring.h:22
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
int _cnt
Definition: mbstring.h:21
void CDECL _unlock_file(FILE *file)
Definition: file.c:1205
char * _ptr
Definition: mbstring.h:20
__int64 CDECL _telli64(int fd)
Definition: file.c:2527
#define WX_TEXT
Definition: file.c:100
GLenum GLclampf GLint i
Definition: glfuncs.h:14
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1138
#define SEEK_SET
Definition: jmemansi.c:26
unsigned char wxflag
Definition: file.c:42
void CDECL _lock_file(FILE *file)
Definition: file.c:1193
#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:93
int _file
Definition: mbstring.h:24
#define SEEK_END
Definition: cabinet.c:27
GLfloat GLfloat p
Definition: glext.h:8902
#define __int64
Definition: basetyps.h:16
intptr_t CDECL _get_osfhandle ( int  fd)

Definition at line 1591 of file file.c.

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

1592 {
1593  HANDLE hand = get_ioinfo_nolock(fd)->handle;
1594  TRACE(":fd (%d) handle (%p)\n",fd,hand);
1595 
1596  if(hand == INVALID_HANDLE_VALUE)
1597  *_errno() = EBADF;
1598  return (intptr_t)hand;
1599 }
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static int fd
Definition: io.c:51
Definition: arc.h:36
HANDLE handle
Definition: file.c:41
#define TRACE(s)
Definition: solgame.cpp:4
int intptr_t
Definition: crtdefs.h:283
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
DWORD *typedef HANDLE
Definition: winlogon.h:61
int CDECL _getmaxstdio ( void  )

Definition at line 4026 of file file.c.

4027 {
4028  return MSVCRT_max_streams;
4029 }
static int MSVCRT_max_streams
Definition: file.c:135
int CDECL _getw ( FILE file)

Definition at line 2994 of file file.c.

Referenced by test_readmode().

2995 {
2996  char *ch;
2997  int i, k;
2998  unsigned int j;
2999  ch = (char *)&i;
3000 
3001  _lock_file(file);
3002  for (j=0; j<sizeof(int); j++) {
3003  k = fgetc(file);
3004  if (k == EOF) {
3005  file->_flag |= _IOEOF;
3006  _unlock_file(file);
3007  return EOF;
3008  }
3009  ch[j] = k;
3010  }
3011 
3012  _unlock_file(file);
3013  return i;
3014 }
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:1205
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:1193
int _flag
Definition: mbstring.h:23
#define EOF
Definition: stdio.h:24
int CDECL fgetc(FILE *file)
Definition: file.c:2886
int k
Definition: mpi.c:3369
wchar_t* CDECL _getws ( wchar_t buf)

Definition at line 3663 of file file.c.

3664 {
3665  wint_t cc;
3666  wchar_t* ws = buf;
3667 
3668  _lock_file(stdin);
3669  for (cc = fgetwc(stdin); cc != WEOF && cc != '\n';
3670  cc = fgetwc(stdin))
3671  {
3672  if (cc != '\r')
3673  *buf++ = (wchar_t)cc;
3674  }
3675  *buf = '\0';
3676 
3677  TRACE("got %s\n", debugstr_w(ws));
3679  return ws;
3680 }
const char * ws
Definition: skip_ws.cpp:7
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
void CDECL _unlock_file(FILE *file)
Definition: file.c:1205
FILE * stdin
#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:1193
#define WEOF
Definition: conio.h:185
uint32_t cc
Definition: isohybrid.c:75
wint_t CDECL fgetwc(FILE *file)
Definition: file.c:2946
#define wchar_t
Definition: wchar.h:102
int CDECL _isatty ( int  fd)

Definition at line 565 of file file.c.

Referenced by add_std_buffer(), and msvcrt_alloc_buffer().

566 {
567  TRACE(":fd (%d)\n",fd);
568 
569  return get_ioinfo_nolock(fd)->wxflag & WX_TTY;
570 }
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
static int fd
Definition: io.c:51
#define WX_TTY
Definition: file.c:99
unsigned char wxflag
Definition: file.c:42
#define TRACE(s)
Definition: solgame.cpp:4
void CDECL _lock_file ( FILE file)

Definition at line 1193 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().

1194 {
1195  if(file>=_iob && file<_iob+_IOB_ENTRIES)
1196  _lock(_STREAM_LOCKS+(file-_iob));
1197  /* ReactOS: string streams dont need to be locked */
1198  else if(!(file->_flag & _IOSTRG))
1199  EnterCriticalSection(&((file_crit*)file)->crit);
1200 }
#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:133
int CDECL _locking ( int  fd,
int  mode,
LONG  nbytes 
)

Definition at line 1220 of file file.c.

1221 {
1222  ioinfo *info = get_ioinfo(fd);
1223  BOOL ret;
1224  DWORD cur_locn;
1225 
1226  TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1227  if (info->handle == INVALID_HANDLE_VALUE)
1228  {
1229  release_ioinfo(info);
1230  return -1;
1231  }
1232 
1233  if (mode < 0 || mode > 4)
1234  {
1235  release_ioinfo(info);
1236  *_errno() = EINVAL;
1237  return -1;
1238  }
1239 
1240  TRACE(":fd (%d) by 0x%08x mode %s\n",
1241  fd,nbytes,(mode==_LK_UNLCK)?"_LK_UNLCK":
1242  (mode==_LK_LOCK)?"_LK_LOCK":
1243  (mode==_LK_NBLCK)?"_LK_NBLCK":
1244  (mode==_LK_RLCK)?"_LK_RLCK":
1245  (mode==_LK_NBRLCK)?"_LK_NBRLCK":
1246  "UNKNOWN");
1247 
1248  if ((cur_locn = SetFilePointer(info->handle, 0L, NULL, FILE_CURRENT)) == INVALID_SET_FILE_POINTER)
1249  {
1250  release_ioinfo(info);
1251  FIXME ("Seek failed\n");
1252  *_errno() = EINVAL; /* FIXME */
1253  return -1;
1254  }
1255  if (mode == _LK_LOCK || mode == _LK_RLCK)
1256  {
1257  int nretry = 10;
1258  ret = 1; /* just to satisfy gcc */
1259  while (nretry--)
1260  {
1261  ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L);
1262  if (ret) break;
1263  Sleep(1);
1264  }
1265  }
1266  else if (mode == _LK_UNLCK)
1267  ret = UnlockFile(info->handle, cur_locn, 0L, nbytes, 0L);
1268  else
1269  ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L);
1270  /* FIXME - what about error settings? */
1271  release_ioinfo(info);
1272  return ret ? 0 : -1;
1273 }
#define _LK_NBRLCK
Definition: locking.h:19
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
Definition: file.c:40
Definition: arc.h:39
#define FILE_CURRENT
Definition: winbase.h:113
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static int fd
Definition: io.c:51
DWORD DWORD
Definition: winlogon.h:84
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
HANDLE handle
Definition: file.c:41
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _LK_LOCK
Definition: locking.h:16
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
static const WCHAR L[]
Definition: oid.c:1087
void release_ioinfo(ioinfo *info)
Definition: file.c:263
BOOL WINAPI LockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh)
Definition: lock.c:25
#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 1185 of file file.c.

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

1186 {
1187  return (LONG)_lseeki64(fd, offset, whence);
1188 }
GLintptr offset
Definition: glext.h:5920
static int fd
Definition: io.c:51
long LONG
Definition: pedump.c:60
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1138
__int64 CDECL _lseeki64 ( int  fd,
__int64  offset,
int  whence 
)

Definition at line 1138 of file file.c.

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

1139 {
1140  ioinfo *info = get_ioinfo(fd);
1141  LARGE_INTEGER ofs;
1142 
1143  TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1144 
1145  if (info->handle == INVALID_HANDLE_VALUE)
1146  {
1147  release_ioinfo(info);
1148  return -1;
1149  }
1150 
1151  if (whence < 0 || whence > 2)
1152  {
1153  release_ioinfo(info);
1154  *_errno() = EINVAL;
1155  return -1;
1156  }
1157 
1158  TRACE(":fd (%d) to %s pos %s\n",
1160  (whence==SEEK_SET)?"SEEK_SET":
1161  (whence==SEEK_CUR)?"SEEK_CUR":
1162  (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
1163 
1164  /* The MoleBox protection scheme expects msvcrt to use SetFilePointer only,
1165  * so a LARGE_INTEGER offset cannot be passed directly via SetFilePointerEx. */
1166  ofs.QuadPart = offset;
1167  if ((ofs.u.LowPart = SetFilePointer(info->handle, ofs.u.LowPart, &ofs.u.HighPart, whence)) != INVALID_SET_FILE_POINTER ||
1169  {
1170  info->wxflag &= ~(WX_ATEOF|WX_READEOF);
1171  /* FIXME: What if we seek _to_ EOF - is EOF set? */
1172 
1173  release_ioinfo(info);
1174  return ofs.QuadPart;
1175  }
1176  release_ioinfo(info);
1177  TRACE(":error-last error (%d)\n",GetLastError());
1179  return -1;
1180 }
#define SEEK_CUR
Definition: util.h:63
struct _LARGE_INTEGER::@2193 u
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK void ULONG PLARGE_INTEGER offset
Definition: file.c:88
#define ERROR_SUCCESS
Definition: deptool.c:10
Definition: file.c:40
Definition: arc.h:39
GLintptr offset
Definition: glext.h:5920
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static int fd
Definition: io.c:51
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
HANDLE handle
Definition: file.c:41
#define SEEK_SET
Definition: jmemansi.c:26
unsigned char wxflag
Definition: file.c:42
#define TRACE(s)
Definition: solgame.cpp:4
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
void release_ioinfo(ioinfo *info)
Definition: file.c:263
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define WX_READEOF
Definition: file.c:94
#define WX_ATEOF
Definition: file.c:92
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
#define SEEK_END
Definition: cabinet.c:27
LONGLONG QuadPart
Definition: typedefs.h:112
char* CDECL _mktemp ( char pattern)

Definition at line 1604 of file file.c.

Referenced by test_mktemp().

1605 {
1606  int numX = 0;
1607  char *retVal = pattern;
1608  int id;
1609  char letter = 'a';
1610 
1611  if(!pattern)
1612  return NULL;
1613 
1614  while(*pattern)
1615  numX = (*pattern++ == 'X')? numX + 1 : 0;
1616  if (numX < 6)
1617  return NULL;
1618  pattern--;
1619  id = GetCurrentProcessId();
1620  numX = 6;
1621  while(numX--)
1622  {
1623  int tempNum = id / 10;
1624  *pattern-- = id - (tempNum * 10) + '0';
1625  id = tempNum;
1626  }
1627  pattern++;
1628  do
1629  {
1630  *pattern = letter++;
1632  return retVal;
1633  } while(letter <= 'z');
1634  return NULL;
1635 }
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:786
smooth NULL
Definition: ftsmooth.c:416
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLenum GLuint id
Definition: glext.h:5579
GLubyte * pattern
Definition: glext.h:7787
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1188
int CDECL _open ( const char path,
int  flags,
  ... 
)

Definition at line 2001 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().

2002 {
2003  va_list ap;
2004 
2005  if (flags & _O_CREAT)
2006  {
2007  int pmode;
2008  va_start(ap, flags);
2009  pmode = va_arg(ap, int);
2010  va_end(ap);
2011  return _sopen( path, flags, _SH_DENYNO, pmode );
2012  }
2013  else
2014  return _sopen( path, flags, _SH_DENYNO);
2015 }
#define _O_CREAT
Definition: cabinet.h:46
#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:1978
GLbitfield flags
Definition: glext.h:7161
#define va_arg(ap, T)
Definition: acmsvcex.h:89
Definition: services.c:325
#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 2057 of file file.c.

Referenced by test__open_osfhandle(), and test_close().

2058 {
2059  DWORD flags;
2060  int fd;
2061 
2062  /* _O_RDONLY (0) always matches, so set the read flag
2063  * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
2064  * file, so set the write flag. It also only sets _O_TEXT if it wants
2065  * text - it never sets _O_BINARY.
2066  */
2067  /* don't let split_oflags() decide the mode if no mode is passed */
2068  if (!(oflags & (_O_BINARY | _O_TEXT)))
2069  oflags |= _O_BINARY;
2070 
2071  flags = GetFileType((HANDLE)handle);
2072  if (flags==FILE_TYPE_UNKNOWN && GetLastError()!=NO_ERROR)
2073  {
2075  return -1;
2076  }
2077 
2078  if (flags == FILE_TYPE_CHAR)
2079  flags = WX_TTY;
2080  else if (flags == FILE_TYPE_PIPE)
2081  flags = WX_PIPE;
2082  else
2083  flags = 0;
2084  flags |= split_oflags(oflags);
2085 
2086  fd = msvcrt_alloc_fd((HANDLE)handle, flags);
2087  TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle, fd, flags);
2088  return fd;
2089 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static int fd
Definition: io.c:51
#define WX_PIPE
Definition: file.c:95
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:419
#define FILE_TYPE_UNKNOWN
Definition: winbase.h:255
unsigned split_oflags(unsigned oflags)
Definition: file.c:1671
#define NO_ERROR
Definition: dderror.h:5
DWORD DWORD
Definition: winlogon.h:84
#define WX_TTY
Definition: file.c:99
#define FILE_TYPE_CHAR
Definition: winbase.h:257
int msvcrt_alloc_fd(HANDLE hand, int flag)
Definition: file.c:343
#define TRACE(s)
Definition: solgame.cpp:4
GLbitfield flags
Definition: glext.h:7161
#define _O_BINARY
Definition: cabinet.h:51
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define FILE_TYPE_PIPE
Definition: winbase.h:258
#define _O_TEXT
Definition: cabinet.h:50
int CDECL _pipe ( int pfds,
unsigned int  psize,
int  textmode 
)

Definition at line 1702 of file file.c.

Referenced by test_pipes(), and test_stat().

1703 {
1704  int ret = -1;
1706  HANDLE readHandle, writeHandle;
1707 
1708  if (!pfds)
1709  {
1710  *_errno() = EINVAL;
1711  return -1;
1712  }
1713 
1714  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
1715  sa.bInheritHandle = !(textmode & _O_NOINHERIT);
1717  if (CreatePipe(&readHandle, &writeHandle, &sa, psize))
1718  {
1719  unsigned int wxflags = split_oflags(textmode);
1720  int fd;
1721 
1722  fd = msvcrt_alloc_fd(readHandle, wxflags);
1723  if (fd != -1)
1724  {
1725  pfds[0] = fd;
1726  fd = msvcrt_alloc_fd(writeHandle, wxflags);
1727  if (fd != -1)
1728  {
1729  pfds[1] = fd;
1730  ret = 0;
1731  }
1732  else
1733  {
1734  _close(pfds[0]);
1735  CloseHandle(writeHandle);
1736  *_errno() = EMFILE;
1737  }
1738  }
1739  else
1740  {
1741  CloseHandle(readHandle);
1742  CloseHandle(writeHandle);
1743  *_errno() = EMFILE;
1744  }
1745  }
1746  else
1748 
1749  return ret;
1750 }
#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:1059
static int fd
Definition: io.c:51
unsigned split_oflags(unsigned oflags)
Definition: file.c:1671
#define _O_NOINHERIT
Definition: cabinet.h:45
smooth NULL
Definition: ftsmooth.c:416
int msvcrt_alloc_fd(HANDLE hand, int flag)
Definition: file.c:343
int CDECL _close(int fd)
Definition: file.c:931
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:61
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 2764 of file file.c.

2765 {
2766  int len;
2767 
2768  _lock_file(file);
2769  len = _write(file->_file, &val, sizeof(val));
2770  if (len == sizeof(val)) {
2771  _unlock_file(file);
2772  return val;
2773  }
2774 
2775  file->_flag |= _IOERR;
2776  _unlock_file(file);
2777  return EOF;
2778 }
void CDECL _unlock_file(FILE *file)
Definition: file.c:1205
#define _IOERR
Definition: stdio.h:134
GLuint GLfloat * val
Definition: glext.h:7180
void CDECL _lock_file(FILE *file)
Definition: file.c:1193
int CDECL _write(int fd, const void *buf, unsigned int count)
Definition: file.c:2585
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 3701 of file file.c.

3702 {
3703  return fputwc(c, stdout);
3704 }
wint_t CDECL fputwc(wchar_t c, FILE *stream)
Definition: file.c:3145
FILE * stdout
const GLubyte * c
Definition: glext.h:8905
int CDECL _putws ( const wchar_t s)

Definition at line 3728 of file file.c.

3729 {
3730  static const wchar_t nl = '\n';
3731  size_t len = strlenW(s);
3732  int ret;
3733 
3734  _lock_file(stdout);
3735  if(fwrite(s, sizeof(*s), len, stdout) != len) {
3737  return EOF;
3738  }
3739 
3740  ret = fwrite(&nl,sizeof(nl),1,stdout) == 1 ? 0 : EOF;
3742  return ret;
3743 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
void CDECL _unlock_file(FILE *file)
Definition: file.c:1205
FILE * stdout
void CDECL _lock_file(FILE *file)
Definition: file.c:1193
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:3075
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 2466 of file file.c.

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

2467 {
2468  ioinfo *info = get_ioinfo(fd);
2469  int num_read = read_i(fd, info, buf, count);
2470  release_ioinfo(info);
2471  return num_read;
2472 }
Definition: file.c:40
static int fd
Definition: io.c:51
GLuint GLuint GLsizei count
Definition: gl.h:1545
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
static int read_i(int fd, ioinfo *fdinfo, void *buf, unsigned int count)
Definition: file.c:2306
void release_ioinfo(ioinfo *info)
Definition: file.c:263
int CDECL _rmtmp ( void  )

Definition at line 2094 of file file.c.

2095 {
2096  int num_removed = 0, i;
2097  FILE *file;
2098 
2099  LOCK_FILES();
2100  for (i = 3; i < MSVCRT_stream_idx; i++) {
2101  file = msvcrt_get_file(i);
2102 
2103  if (file->_tmpfname)
2104  {
2105  fclose(file);
2106  num_removed++;
2107  }
2108  }
2109  UNLOCK_FILES();
2110 
2111  if (num_removed)
2112  TRACE(":removed (%d) temp files\n",num_removed);
2113  return num_removed;
2114 }
static int MSVCRT_stream_idx
Definition: file.c:135
char * _tmpfname
Definition: mbstring.h:27
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define UNLOCK_FILES()
Definition: file.c:156
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:155
static FILE * msvcrt_get_file(int i)
Definition: file.c:269
int CDECL fclose(FILE *file)
Definition: file.c:2783
int CDECL _setmaxstdio ( int  newmax)

Definition at line 4034 of file file.c.

Referenced by test_setmaxstdio().

4035 {
4036  TRACE("%d\n", newmax);
4037 
4038  if(newmax<_IOB_ENTRIES || newmax>MSVCRT_MAX_FILES || newmax<MSVCRT_stream_idx)
4039  return -1;
4040 
4041  MSVCRT_max_streams = newmax;
4042  return MSVCRT_max_streams;
4043 }
static int MSVCRT_stream_idx
Definition: file.c:135
static int MSVCRT_max_streams
Definition: file.c:135
#define TRACE(s)
Definition: solgame.cpp:4
#define MSVCRT_MAX_FILES
Definition: file.c:112
int CDECL _setmode ( int  fd,
int  mode 
)

Definition at line 2477 of file file.c.

Referenced by test_setmode().

2478 {
2479  ioinfo *info = get_ioinfo(fd);
2480  int ret = info->wxflag & WX_TEXT ? _O_TEXT : _O_BINARY;
2481  if(ret==_O_TEXT && (info->exflag & (EF_UTF8|EF_UTF16)))
2482  ret = _O_WTEXT;
2483 
2484  if(mode!=_O_TEXT && mode!=_O_BINARY && mode!=_O_WTEXT
2485  && mode!=_O_U16TEXT && mode!=_O_U8TEXT) {
2486  *_errno() = EINVAL;
2487  release_ioinfo(info);
2488  return -1;
2489  }
2490 
2491  if(info == &__badioinfo) {
2492  *_errno() = EBADF;
2493  return EOF;
2494  }
2495 
2496  if(mode == _O_BINARY) {
2497  info->wxflag &= ~WX_TEXT;
2498  info->exflag &= ~(EF_UTF8|EF_UTF16);
2499  release_ioinfo(info);
2500  return ret;
2501  }
2502 
2503  info->wxflag |= WX_TEXT;
2504  if(mode == _O_TEXT)
2505  info->exflag &= ~(EF_UTF8|EF_UTF16);
2506  else if(mode == _O_U8TEXT)
2507  info->exflag = (info->exflag & ~EF_UTF16) | EF_UTF8;
2508  else
2509  info->exflag = (info->exflag & ~EF_UTF8) | EF_UTF16;
2510 
2511  release_ioinfo(info);
2512  return ret;
2513 
2514 }
Definition: file.c:40
Definition: arc.h:39
ioinfo __badioinfo
Definition: file.c:126
static int fd
Definition: io.c:51
Definition: arc.h:36
#define _O_WTEXT
Definition: fcntl.h:20
#define WX_TEXT
Definition: file.c:100
int exflag
Definition: file.c:44
#define _O_U8TEXT
Definition: fcntl.h:22
unsigned char wxflag
Definition: file.c:42
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define _O_U16TEXT
Definition: fcntl.h:21
int ret
#define _O_BINARY
Definition: cabinet.h:51
void release_ioinfo(ioinfo *info)
Definition: file.c:263
#define _O_TEXT
Definition: cabinet.h:50
#define EF_UTF8
Definition: file.c:103
#define EF_UTF16
Definition: file.c:104
#define EOF
Definition: stdio.h:24
int CDECL _sopen ( const char path,
int  oflags,
int  shflags,
  ... 
)

Definition at line 1978 of file file.c.

Referenced by _open(), and test_get_osfhandle().

1979 {
1980  int pmode;
1981  int fd;
1982 
1983  if (oflags & _O_CREAT)
1984  {
1985  va_list ap;
1986 
1987  va_start(ap, shflags);
1988  pmode = va_arg(ap, int);
1989  va_end(ap);
1990  }
1991  else
1992  pmode = 0;
1993 
1994  _sopen_s(&fd, path, oflags, shflags, pmode);
1995  return fd;
1996 }
#define _O_CREAT
Definition: cabinet.h:46
static int fd
Definition: io.c:51
int CDECL _sopen_s(int *fd, const char *path, int oflags, int shflags, int pmode)
Definition: file.c:1962
#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
Definition: services.c:325
#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 1962 of file file.c.

Referenced by _sopen().

1963 {
1964  wchar_t *pathW;
1965  int ret;
1966 
1967  if(!MSVCRT_CHECK_PMT(path && (pathW = msvcrt_wstrdupa(path))))
1968  return EINVAL;
1969 
1970  ret = _wsopen_s(fd, pathW, oflags, shflags, pmode);
1971  free(pathW);
1972  return ret;
1973 }
Definition: arc.h:39
#define free
Definition: debug_ros.c:5
static int fd
Definition: io.c:51
wchar_t * msvcrt_wstrdupa(const char *str)
Definition: file.c:670
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:1778
int ret
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
Definition: services.c:325
long CDECL _tell ( int  fd)

Definition at line 2519 of file file.c.

Referenced by test__creat().

2520 {
2521  return _lseek(fd, 0, SEEK_CUR);
2522 }
#define SEEK_CUR
Definition: util.h:63
static int fd
Definition: io.c:51
LONG CDECL _lseek(int fd, LONG offset, int whence)
Definition: file.c:1185
__int64 CDECL _telli64 ( int  fd)

Definition at line 2527 of file file.c.

Referenced by _ftelli64().

2528 {
2529  return _lseeki64(fd, 0, SEEK_CUR);
2530 }
#define SEEK_CUR
Definition: util.h:63
static int fd
Definition: io.c:51
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1138
char* CDECL _tempnam ( const char dir,
const char prefix 
)

Definition at line 2535 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().

2536 {
2537  char tmpbuf[MAX_PATH];
2538  const char *tmp_dir = getenv("TMP");
2539 
2540  if (tmp_dir) dir = tmp_dir;
2541 
2542  TRACE("dir (%s) prefix (%s)\n",dir,prefix);
2543  if (GetTempFileNameA(dir,prefix,0,tmpbuf))
2544  {
2545  TRACE("got name (%s)\n",tmpbuf);
2546  DeleteFileA(tmpbuf);
2547  return _strdup(tmpbuf);
2548  }
2549  TRACE("failed (%d)\n",GetLastError());
2550  return NULL;
2551 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define _strdup
Definition: debug_ros.c:7
PIN_DIRECTION dir
Definition: strmbase.h:230
smooth NULL
Definition: ftsmooth.c:416
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 2574 of file file.c.

2575 {
2576  int old_umask = MSVCRT_umask;
2577  TRACE("(%d)\n",umask);
2578  MSVCRT_umask = umask;
2579  return old_umask;
2580 }
static int MSVCRT_umask
Definition: file.c:138
#define TRACE(s)
Definition: solgame.cpp:4
_CRTIMP int __cdecl umask(_In_ int _Mode)
int CDECL _unlink ( const char path)

Definition at line 803 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().

804 {
805  TRACE("%s\n",debugstr_a(path));
806  if(DeleteFileA(path))
807  return 0;
808  TRACE("failed (%d)\n",GetLastError());
810  return -1;
811 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
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:325
void CDECL _unlock_file ( FILE file)

Definition at line 1205 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().

1206 {
1207  if(file>=_iob && file<_iob+_IOB_ENTRIES)
1208  _unlock(_STREAM_LOCKS+(file-_iob));
1209  /* ReactOS: string streams dont need to be locked */
1210  else if(!(file->_flag & _IOSTRG))
1211  LeaveCriticalSection(&((file_crit*)file)->crit);
1212 
1213 }
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:133
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
int CDECL _waccess ( const wchar_t filename,
int  mode 
)

Definition at line 728 of file file.c.

Referenced by _waccess_s().

729 {
731 
732  TRACE("(%s,%d) %d\n",debugstr_w(filename),mode,attr);
733 
734  if (!filename || attr == INVALID_FILE_ATTRIBUTES)
735  {
737  return -1;
738  }
739  if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
740  {
742  return -1;
743  }
744  return 0;
745 }
errno_t __cdecl _set_errno(_In_ int _Value)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
const char * filename
Definition: ioapi.h:135
DWORD DWORD
Definition: winlogon.h:84
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#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:170
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
#define W_OK
Definition: io.h:170
int CDECL _waccess_s ( const wchar_t filename,
int  mode 
)

Definition at line 750 of file file.c.

751 {
752  if (!MSVCRT_CHECK_PMT(filename != NULL) ||
753  !MSVCRT_CHECK_PMT((mode & ~(R_OK | W_OK)) == 0))
754  {
755  *_errno() = EINVAL;
756  return -1;
757  }
758 
759  return _waccess(filename, mode);
760 }
Definition: arc.h:39
#define R_OK
Definition: io.h:171
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int CDECL _waccess(const wchar_t *filename, int mode)
Definition: file.c:728
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
#define W_OK
Definition: io.h:170
int CDECL _wchmod ( const wchar_t path,
int  flags 
)

Definition at line 784 of file file.c.

785 {
786  DWORD oldFlags = GetFileAttributesW(path);
787 
788  if (oldFlags != INVALID_FILE_ATTRIBUTES)
789  {
790  DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY:
791  oldFlags | FILE_ATTRIBUTE_READONLY;
792 
793  if (newFlags == oldFlags || SetFileAttributesW(path, newFlags))
794  return 0;
795  }
797  return -1;
798 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD DWORD
Definition: winlogon.h:84
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define _S_IWRITE
Definition: cabinet.h:33
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLbitfield flags
Definition: glext.h:7161
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:325
int CDECL _wcreat ( const wchar_t path,
int  flags 
)

Definition at line 2048 of file file.c.

2049 {
2050  int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC;
2051  return _wopen(path, usedFlags);
2052 }
#define _O_CREAT
Definition: cabinet.h:46
int CDECL _wopen(const wchar_t *path, int flags,...)
Definition: file.c:2020
#define _O_TRUNC
Definition: cabinet.h:47
GLbitfield flags
Definition: glext.h:7161
#define _O_WRONLY
Definition: cabinet.h:38
Definition: services.c:325
#define _O_TEXT
Definition: cabinet.h:50
FILE* CDECL _wfdopen ( int  fd,
const wchar_t mode 
)

Definition at line 1520 of file file.c.

Referenced by _fdopen().

1521 {
1522  int open_flags, stream_flags;
1523  FILE* file;
1524 
1525  if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) return NULL;
1526 
1527  LOCK_FILES();
1528  if (!(file = msvcrt_alloc_fp()))
1529  file = NULL;
1530  else if (msvcrt_init_fp(file, fd, stream_flags) == -1)
1531  {
1532  file->_flag = 0;
1533  file = NULL;
1534  }
1535  else TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file);
1536  UNLOCK_FILES();
1537 
1538  return file;
1539 }
static int fd
Definition: io.c:51
static int msvcrt_init_fp(FILE *file, int fd, unsigned stream_flags)
Definition: file.c:382
static int msvcrt_get_flags(const wchar_t *mode, int *open_flags, int *stream_flags)
Definition: file.c:1385
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define UNLOCK_FILES()
Definition: file.c:156
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:155
int _flag
Definition: mbstring.h:23
static FILE * msvcrt_alloc_fp(void)
Definition: file.c:360
FILE* CDECL _wfopen ( const wchar_t path,
const wchar_t mode 
)

Definition at line 3272 of file file.c.

Referenced by _wfopen_s().

3273 {
3274  return _wfsopen( path, mode, _SH_DENYNO );
3275 }
#define _SH_DENYNO
Definition: share.h:17
FILE *CDECL _wfsopen(const wchar_t *path, const wchar_t *mode, int share)
Definition: file.c:3185
Definition: services.c:325
int CDECL _wfopen_s ( FILE **  pFile,
const wchar_t filename,
const wchar_t mode 
)

Definition at line 3280 of file file.c.

3282 {
3283  if (!MSVCRT_CHECK_PMT(pFile != NULL) || !MSVCRT_CHECK_PMT(filename != NULL) ||
3284  !MSVCRT_CHECK_PMT(mode != NULL)) {
3285  *_errno() = EINVAL;
3286  return EINVAL;
3287  }
3288 
3289  *pFile = _wfopen(filename, mode);
3290 
3291  if(!*pFile)
3292  return *_errno();
3293  return 0;
3294 }
Definition: arc.h:39
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
_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:3272
FILE* CDECL _wfreopen ( const wchar_t path,
const wchar_t mode,
FILE file 
)

Definition at line 3419 of file file.c.

Referenced by freopen().

3420 {
3421  int open_flags, stream_flags, fd;
3422 
3423  TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path), debugstr_w(mode), file, file ? file->_file : -1);
3424 
3425  LOCK_FILES();
3426  if (!file || ((fd = file->_file) < 0))
3427  file = NULL;
3428  else
3429  {
3430  fclose(file);
3431  /* map mode string to open() flags. "man fopen" for possibilities. */
3432  if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1)
3433  file = NULL;
3434  else
3435  {
3436  fd = _wopen(path, open_flags, _S_IREAD | _S_IWRITE);
3437  if (fd < 0)
3438  file = NULL;
3439  else if (msvcrt_init_fp(file, fd, stream_flags) == -1)
3440  {
3441  file->_flag = 0;
3442  WARN(":failed-last error (%d)\n",GetLastError());
3444  file = NULL;
3445  }
3446  }
3447  }
3448  UNLOCK_FILES();
3449  return file;
3450 }
#define _S_IREAD
Definition: cabinet.h:34
#define WARN(fmt,...)
Definition: debug.h:111
int CDECL _wopen(const wchar_t *path, int flags,...)
Definition: file.c:2020
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static int fd
Definition: io.c:51
static int msvcrt_init_fp(FILE *file, int fd, unsigned stream_flags)
Definition: file.c:382
static int msvcrt_get_flags(const wchar_t *mode, int *open_flags, int *stream_flags)
Definition: file.c:1385
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define _S_IWRITE
Definition: cabinet.h:33
#define UNLOCK_FILES()
Definition: file.c:156
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:155
int _flag
Definition: mbstring.h:23
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
Definition: services.c:325
int _file
Definition: mbstring.h:24
int CDECL fclose(FILE *file)
Definition: file.c:2783
FILE* CDECL _wfsopen ( const wchar_t path,
const wchar_t mode,
int  share 
)

Definition at line 3185 of file file.c.

Referenced by _fsopen(), and _wfopen().

3186 {
3187  FILE* file;
3188  int open_flags, stream_flags, fd;
3189 
3190  TRACE("(%s,%s)\n", debugstr_w(path), debugstr_w(mode));
3191 
3192  /* map mode string to open() flags. "man fopen" for possibilities. */
3193  if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1)
3194  return NULL;
3195 
3196  LOCK_FILES();
3197  fd = _wsopen(path, open_flags, share, _S_IREAD | _S_IWRITE);
3198  if (fd < 0)
3199  file = NULL;
3200  else if ((file = msvcrt_alloc_fp()) && msvcrt_init_fp(file, fd, stream_flags)
3201  != -1)
3202  TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file);
3203  else if (file)
3204  {
3205  file->_flag = 0;
3206  file = NULL;
3207  }
3208 
3209  TRACE(":got (%p)\n",file);
3210  if (fd >= 0 && !file)
3211  _close(fd);
3212  UNLOCK_FILES();
3213  return file;
3214 }
#define _S_IREAD
Definition: cabinet.h:34
static int fd
Definition: io.c:51
static int msvcrt_init_fp(FILE *file, int fd, unsigned stream_flags)
Definition: file.c:382
static int msvcrt_get_flags(const wchar_t *mode, int *open_flags, int *stream_flags)
Definition: file.c:1385
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define _S_IWRITE
Definition: cabinet.h:33
#define UNLOCK_FILES()
Definition: file.c:156
int CDECL _close(int fd)
Definition: file.c:931
#define TRACE(s)
Definition: solgame.cpp:4
const char file[]
Definition: icontest.c:11
#define LOCK_FILES()
Definition: file.c:155
int _flag
Definition: mbstring.h:23
Definition: services.c:325
int CDECL _wsopen(const wchar_t *path, int oflags, int shflags,...)
Definition: file.c:1939
static FILE * msvcrt_alloc_fp(void)
Definition: file.c:360
wchar_t* CDECL _wmktemp ( wchar_t pattern)

Definition at line 1640 of file file.c.

1641 {
1642  int numX = 0;
1643  wchar_t *retVal = pattern;
1644  int id;
1645  wchar_t letter = 'a';
1646 
1647  while(*pattern)
1648  numX = (*pattern++ == 'X')? numX + 1 : 0;
1649  if (numX < 5)
1650  return NULL;
1651  pattern--;
1652  id = GetCurrentProcessId();
1653  numX = 6;
1654  while(numX--)
1655  {
1656  int tempNum = id / 10;
1657  *pattern-- = id - (tempNum * 10) + '0';
1658  id = tempNum;
1659  }
1660  pattern++;
1661  do
1662  {
1665  return retVal;
1666  *pattern = letter++;
1667  } while(letter != '|');
1668  return NULL;
1669 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLenum GLuint id
Definition: glext.h:5579
GLubyte * pattern
Definition: glext.h:7787
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1188
int CDECL _wopen ( const wchar_t path,
int  flags,
  ... 
)

Definition at line 2020 of file file.c.

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

2021 {
2022  va_list ap;
2023 
2024  if (flags & _O_CREAT)
2025  {
2026  int pmode;
2027  va_start(ap, flags);
2028  pmode = va_arg(ap, int);
2029  va_end(ap);
2030  return _wsopen( path, flags, _SH_DENYNO, pmode );
2031  }
2032  else
2033  return _wsopen( path, flags, _SH_DENYNO);
2034 }
#define _O_CREAT
Definition: cabinet.h:46
#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:325
#define va_start(ap, A)
Definition: acmsvcex.h:91
int CDECL _wsopen(const wchar_t *path, int oflags, int shflags,...)
Definition: file.c:1939
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
int CDECL _wremove ( const wchar_t path)

Definition at line 3761 of file file.c.

3762 {
3763  TRACE("(%s)\n",debugstr_w(path));
3764  if (DeleteFileW(path))
3765  return 0;
3766  TRACE(":failed (%d)\n",GetLastError());
3768  return -1;
3769 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#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:325
int CDECL _wrename ( const wchar_t oldpath,
const wchar_t newpath 
)

Definition at line 3787 of file file.c.

3788 {
3789  TRACE(":from %s to %s\n",debugstr_w(oldpath),debugstr_w(newpath));
3790  if (MoveFileExW(oldpath, newpath, MOVEFILE_COPY_ALLOWED))
3791  return 0;
3792  TRACE(":failed (%d)\n",GetLastError());
3794  return -1;
3795 }
#define MOVEFILE_COPY_ALLOWED
Definition: filesup.h:29
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
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 2585 of file file.c.

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

2586 {
2587  DWORD num_written;
2588  ioinfo *info = get_ioinfo(fd);
2589  HANDLE hand = info->handle;
2590 
2591  /* Don't trace small writes, it gets *very* annoying */
2592 #if 0
2593  if (count > 32)
2594  TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd,hand,buf,count);
2595 #endif
2596  if (hand == INVALID_HANDLE_VALUE)
2597  {
2598  *_errno() = EBADF;
2599  release_ioinfo(info);
2600  return -1;
2601  }
2602 
2603  if (((info->exflag&EF_UTF8) || (info->exflag&EF_UTF16)) && count&1)
2604  {
2605  *_errno() = EINVAL;
2606  release_ioinfo(info);
2607  return -1;
2608  }
2609 
2610  /* If appending, go to EOF */
2611  if (info->wxflag & WX_APPEND)
2612  _lseek(fd, 0, FILE_END);
2613 
2614  if (!(info->wxflag & WX_TEXT))
2615  {
2616  if (WriteFile(hand, buf, count, &num_written, NULL)
2617  && (num_written == count))
2618  {
2619  release_ioinfo(info);
2620  return num_written;
2621  }
2622  TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd,
2623  hand, GetLastError());
2624  *_errno() = ENOSPC;
2625  }
2626  else
2627  {
2628  unsigned int i, j, nr_lf, size;
2629  char *p = NULL;
2630  const char *q;
2631  const char *s = buf, *buf_start = buf;
2632 
2633  if (!(info->exflag & (EF_UTF8|EF_UTF16)))
2634  {
2635  /* find number of \n */
2636  for (nr_lf=0, i=0; i<count; i++)
2637  if (s[i] == '\n')
2638  nr_lf++;
2639  if (nr_lf)
2640  {
2641  size = count+nr_lf;
2642  if ((q = p = malloc(size)))
2643  {
2644  for (s = buf, i = 0, j = 0; i < count; i++)
2645  {
2646  if (s[i] == '\n')
2647  p[j++] = '\r';
2648  p[j++] = s[i];
2649  }
2650  }
2651  else
2652  {
2653  FIXME("Malloc failed\n");
2654  nr_lf = 0;
2655  size = count;
2656  q = buf;
2657  }
2658  }
2659  else
2660  {
2661  size = count;
2662  q = buf;
2663  }
2664  }
2665  else if (info->exflag & EF_UTF16)
2666  {
2667  for (nr_lf=0, i=0; i<count; i+=2)
2668  if (s[i]=='\n' && s[i+1]==0)
2669  nr_lf += 2;
2670  if (nr_lf)
2671  {
2672  size = count+nr_lf;
2673  if ((q = p = malloc(size)))
2674  {
2675  for (s=buf, i=0, j=0; i<count; i++)
2676  {
2677  if (s[i]=='\n' && s[i+1]==0)
2678  {
2679  p[j++] = '\r';
2680  p[j++] = 0;
2681  }
2682  p[j++] = s[i++];
2683  p[j++] = s[i];
2684  }
2685  }
2686  else
2687  {
2688  FIXME("Malloc failed\n");
2689  nr_lf = 0;
2690  size = count;
2691  q = buf;
2692  }
2693  }
2694  else
2695  {
2696  size = count;
2697  q = buf;
2698  }
2699  }
2700  else
2701  {
2702  DWORD conv_len;
2703 
2704  for(nr_lf=0, i=0; i<count; i+=2)
2705  if (s[i]=='\n' && s[i+1]==0)
2706  nr_lf++;
2707 
2708  conv_len = WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)buf, count/2, NULL, 0, NULL, NULL);
2709  if(!conv_len) {
2711  free(p);
2712  release_ioinfo(info);
2713  return -1;
2714  }
2715 
2716  size = conv_len+nr_lf;
2717  if((p = malloc(count+nr_lf*2+size)))
2718  {
2719  for (s=buf, i=0, j=0; i<count; i++)
2720  {
2721  if (s[i]=='\n' && s[i+1]==0)
2722  {
2723  p[j++] = '\r';
2724  p[j++] = 0;
2725  }
2726  p[j++] = s[i++];
2727  p[j++] = s[i];
2728  }
2729  q = p+count+nr_lf*2;
2730  WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)p, count/2+nr_lf,
2731  p+count+nr_lf*2, conv_len+nr_lf, NULL, NULL);
2732  }
2733  else
2734  {
2735  FIXME("Malloc failed\n");
2736  nr_lf = 0;
2737  size = count;
2738  q = buf;
2739  }
2740  }
2741 
2742  if (!WriteFile(hand, q, size, &num_written, NULL))
2743  num_written = -1;
2744  release_ioinfo(info);
2745  if(p)
2746  free(p);
2747  if (num_written != size)
2748  {
2749  TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
2750  fd, hand, GetLastError(), num_written);
2751  *_errno() = ENOSPC;
2752  return s - buf_start;
2753  }
2754  return count;
2755  }
2756 
2757  release_ioinfo(info);
2758  return -1;
2759 }
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:40
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
__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:1059
static int fd
Definition: io.c:51
#define WX_APPEND
Definition: file.c:98
Definition: arc.h:36
DWORD DWORD
Definition: winlogon.h:84
#define WX_TEXT
Definition: file.c:100
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define CP_UTF8
Definition: nls.h:20
HANDLE handle
Definition: file.c:41
#define FIXME(fmt,...)
Definition: debug.h:110
Definition: arc.h:49
smooth NULL
Definition: ftsmooth.c:416
int exflag
Definition: file.c:44
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:42
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define FILE_END
Definition: winbase.h:114
GLuint GLuint GLsizei count
Definition: gl.h:1545
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
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:1185
GLdouble s
Definition: gl.h:2039
void release_ioinfo(ioinfo *info)
Definition: file.c:263
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define EF_UTF8
Definition: file.c:103
#define EF_UTF16
Definition: file.c:104
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902
int CDECL _wsopen ( const wchar_t path,
int  oflags,
int  shflags,
  ... 
)

Definition at line 1939 of file file.c.

Referenced by _wfsopen(), and _wopen().

1940 {
1941  int pmode;
1942  int fd;
1943 
1944  if (oflags & _O_CREAT)
1945  {
1946  __ms_va_list ap;
1947 
1948  __ms_va_start(ap, shflags);
1949  pmode = va_arg(ap, int);
1950  __ms_va_end(ap);
1951  }
1952  else
1953  pmode = 0;
1954 
1955  _wsopen_s(&fd, path, oflags, shflags, pmode);
1956  return fd;
1957 }
static const char __ms_va_list
Definition: printf.c:70
#define _O_CREAT
Definition: cabinet.h:46
static int fd
Definition: io.c:51
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:1778
#define va_arg(ap, T)
Definition: acmsvcex.h:89
Definition: services.c:325
#define __ms_va_end(list)
Definition: windef.h:448
#define __ms_va_start(list, arg)
Definition: windef.h:447
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 1778 of file file.c.

Referenced by _sopen_s(), and _wsopen().

1779 {
1780  DWORD access = 0, creation = 0, attrib;
1782  DWORD sharing, type;
1783  int wxflag;
1784  HANDLE hand;
1785 
1786  TRACE("fd*: %p :file (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n",
1787  fd, debugstr_w(path), oflags, shflags, pmode);
1788 
1789  if (!MSVCRT_CHECK_PMT( fd != NULL )) return EINVAL;
1790 
1791  *fd = -1;
1792  wxflag = split_oflags(oflags);
1793  switch (oflags & (_O_RDONLY | _O_WRONLY | _O_RDWR))
1794  {
1795  case _O_RDONLY: access |= GENERIC_READ; break;
1796  case _O_WRONLY: access |= GENERIC_WRITE; break;
1797  case _O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break;
1798  }
1799 
1800  if (oflags & _O_CREAT)
1801  {
1802  if(pmode & ~(_S_IREAD | _S_IWRITE))
1803  FIXME(": pmode 0x%04x ignored\n", pmode);
1804  else
1805  WARN(": pmode 0x%04x ignored\n", pmode);
1806 
1807  if (oflags & _O_EXCL)
1808  creation = CREATE_NEW;
1809  else if (oflags & _O_TRUNC)
1810  creation = CREATE_ALWAYS;
1811  else
1812  creation = OPEN_ALWAYS;
1813  }
1814  else /* no _O_CREAT */
1815  {
1816  if (oflags & _O_TRUNC)
1817  creation = TRUNCATE_EXISTING;
1818  else
1819  creation = OPEN_EXISTING;
1820  }
1821 
1822  switch( shflags )
1823  {
1824  case _SH_DENYRW:
1825  sharing = 0L;
1826  break;
1827  case _SH_DENYWR:
1828  sharing = FILE_SHARE_READ;
1829  break;
1830  case _SH_DENYRD:
1831  sharing = FILE_SHARE_WRITE;
1832  break;
1833  case _SH_DENYNO:
1834  sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
1835  break;
1836  default:
1837  ERR( "Unhandled shflags 0x%x\n", shflags );
1838  return EINVAL;
1839  }
1840  attrib = FILE_ATTRIBUTE_NORMAL;
1841 
1842  if (oflags & _O_TEMPORARY)
1843  {
1844  attrib |= FILE_FLAG_DELETE_ON_CLOSE;
1845  access |= DELETE;
1846  sharing |= FILE_SHARE_DELETE;
1847  }
1848 
1849  sa.nLength = sizeof( SECURITY_ATTRIBUTES );
1851  sa.bInheritHandle = !(oflags & _O_NOINHERIT);
1852 
1853  if ((oflags&(_O_WTEXT|_O_U16TEXT|_O_U8TEXT))
1854  && (creation==OPEN_ALWAYS || creation==OPEN_EXISTING)
1855  && !(access&GENERIC_READ))
1856  {
1859  if (hand != INVALID_HANDLE_VALUE)
1860  {
1861  oflags = check_bom(hand, oflags, FALSE);
1862  CloseHandle(hand);
1863  }
1864  else
1865  oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT);
1866  }
1867 
1868  hand = CreateFileW(path, access, sharing, &sa, creation, attrib, 0);
1869  if (hand == INVALID_HANDLE_VALUE) {
1870  WARN(":failed-last error (%d)\n",GetLastError());
1872  return *_errno();
1873  }
1874 
1875  if (oflags & (_O_WTEXT|_O_U16TEXT|_O_U8TEXT))
1876  {
1877  if ((access & GENERIC_WRITE) && (creation==CREATE_NEW
1878  || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING
1879  || (creation==OPEN_ALWAYS && GetLastError()==ERROR_ALREADY_EXISTS)))
1880  {
1881  if (oflags & _O_U8TEXT)
1882  {
1883  DWORD written = 0, tmp;
1884 
1885  while(written!=sizeof(utf8_bom) && WriteFile(hand, (char*)utf8_bom+written,
1886  sizeof(utf8_bom)-written, &tmp, NULL))
1887  written += tmp;
1888  if (written != sizeof(utf8_bom)) {
1889  WARN("error writing BOM\n");
1890  CloseHandle(hand);
1892  return *_errno();
1893  }
1894  }
1895  else
1896  {
1897  DWORD written = 0, tmp;
1898 
1899  while(written!=sizeof(utf16_bom) && WriteFile(hand, (char*)utf16_bom+written,
1900  sizeof(utf16_bom)-written, &tmp, NULL))
1901  written += tmp;
1902  if (written != sizeof(utf16_bom))
1903  {
1904  WARN("error writing BOM\n");
1905  CloseHandle(hand);
1907  return *_errno();
1908  }
1909  }
1910  }
1911  else if (access & GENERIC_READ)
1912  oflags = check_bom(hand, oflags, TRUE);
1913  }
1914 
1915  type = GetFileType(hand);
1916  if (type == FILE_TYPE_CHAR)
1917  wxflag |= WX_TTY;
1918  else if (type == FILE_TYPE_PIPE)
1919  wxflag |= WX_PIPE;
1920 
1921  *fd = msvcrt_alloc_fd(hand, wxflag);
1922  if (*fd == -1)
1923  return *_errno();
1924 
1925  if (oflags & _O_WTEXT)
1927  else if (oflags & _O_U16TEXT)
1929  else if (oflags & _O_U8TEXT)
1930  get_ioinfo_nolock(*fd)->exflag |= EF_UTF8;
1931 
1932  TRACE(":fd (%d) handle (%p)\n", *fd, hand);
1933  return 0;
1934 }
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:37
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
#define _S_IREAD
Definition: cabinet.h:34
Definition: arc.h:39
static char utf8_bom[3]
Definition: file.c:108
#define _O_CREAT
Definition: cabinet.h:46
#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:1059
static int fd
Definition: io.c:51
#define WX_PIPE
Definition: file.c:95
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:419
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
unsigned split_oflags(unsigned oflags)
Definition: file.c:1671
DWORD DWORD
Definition: winlogon.h:84
#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:39
#define _O_EXCL
Definition: cabinet.h:48
#define _O_NOINHERIT
Definition: cabinet.h:45
#define WX_TTY
Definition: file.c:99
#define FALSE
Definition: types.h:117
#define FILE_TYPE_CHAR
Definition: winbase.h:257
#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:416
int exflag
Definition: file.c:44
int int pmode
Definition: fci.h:172
#define _O_TRUNC
Definition: cabinet.h:47
#define _S_IWRITE
Definition: cabinet.h:33
int msvcrt_alloc_fd(HANDLE hand, int flag)
Definition: file.c:343
#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:717
#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
static const WCHAR L[]
Definition: oid.c:1087
#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:38
#define ERR(fmt,...)
Definition: debug.h:109
static char utf16_bom[2]
Definition: file.c:109
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define FILE_TYPE_PIPE
Definition: winbase.h:258
LPVOID lpSecurityDescriptor
Definition: compat.h:181
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
Definition: services.c:325
#define EF_UTF8
Definition: file.c:103
#define CreateFileW
Definition: compat.h:400
#define EF_UTF16
Definition: file.c:104
#define _O_TEMPORARY
Definition: cabinet.h:44
#define EF_UNK_UNICODE
Definition: file.c:106
#define CREATE_NEW
Definition: disk.h:69
#define TRUNCATE_EXISTING
Definition: disk.h:71
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
static int check_bom(HANDLE h, int oflags, BOOL seek)
Definition: file.c:1752
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 2556 of file file.c.

2557 {
2558  wchar_t tmpbuf[MAX_PATH];
2559 
2560  TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir),debugstr_w(prefix));
2561  if (GetTempFileNameW(dir,prefix,0,tmpbuf))
2562  {
2563  TRACE("got name (%s)\n",debugstr_w(tmpbuf));
2564  DeleteFileW(tmpbuf);
2565  return _wcsdup(tmpbuf);
2566  }
2567  TRACE("failed (%d)\n",GetLastError());
2568  return NULL;
2569 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define debugstr_w
Definition: kernel32.h:32
PIN_DIRECTION dir
Definition: strmbase.h:230
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
#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 3880 of file file.c.

3881 {
3882  static const wchar_t format[] = {'\\','s','%','s','.',0};
3883  wchar_t tmpstr[16];
3884  wchar_t *p;
3885  int count, size;
3886  if (!s) {
3888 
3889  if(!data->wtmpnam_buffer)
3890  data->wtmpnam_buffer = malloc(sizeof(wchar_t[MAX_PATH]));
3891 
3892  s = data->wtmpnam_buffer;
3893  }
3894 
3896  p = s + _snwprintf(s, MAX_PATH, format, tmpstr);
3897  for (count = 0; count < TMP_MAX; count++)
3898  {
3899  size = msvcrt_int_to_base32_w(tmpnam_unique++, tmpstr);
3900  memcpy(p, tmpstr, size*sizeof(wchar_t));
3901  p[size] = '\0';
3904  break;
3905  }
3906  return s;
3907 }
#define TMP_MAX
Definition: stdio.h:67
static int tmpnam_unique
Definition: file.c:141
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static int msvcrt_int_to_base32_w(int num, wchar_t *str)
Definition: file.c:645
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
GLsizeiptr size
Definition: glext.h:5919
#define MAX_PATH
Definition: compat.h:26
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
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
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1188
int CDECL _wunlink ( const wchar_t path)

Definition at line 816 of file file.c.

817 {
818  TRACE("(%s)\n",debugstr_w(path));
819  if(DeleteFileW(path))
820  return 0;
821  TRACE("failed (%d)\n",GetLastError());
823  return -1;
824 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#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:325
static BOOL add_std_buffer ( FILE file)
static

Definition at line 594 of file file.c.

Referenced by fputws().

595 {
596  static char buffers[2][BUFSIZ];
597 
598  if((file->_file!=STDOUT_FILENO && file->_file!=STDERR_FILENO)
599  || (file->_flag & (_IONBF | _IOMYBUF | _USERBUF))
600  || !_isatty(file->_file))
601  return FALSE;
602 
603  file->_ptr = file->_base = buffers[file->_file == STDOUT_FILENO ? 0 : 1];
604  file->_bufsiz = file->_cnt = BUFSIZ;
605  file->_flag |= _USERBUF;
606  return TRUE;
607 }
#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:565
#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 BOOL alloc_pioinfo_block ( int  fd)
inlinestatic

Definition at line 191 of file file.c.

Referenced by get_ioinfo_alloc(), and get_ioinfo_alloc_fd().

192 {
193  ioinfo *block;
194  int i;
195 
196  if(fd<0 || fd>=MSVCRT_MAX_FILES)
197  {
198  *_errno() = ENFILE;
199  return FALSE;
200  }
201 
202  block = calloc(MSVCRT_FD_BLOCK_SIZE, sizeof(ioinfo));
203  if(!block)
204  {
205  WARN(":out of memory!\n");
206  *_errno() = ENOMEM;
207  return FALSE;
208  }
209  for(i=0; i<MSVCRT_FD_BLOCK_SIZE; i++)
210  block[i].handle = INVALID_HANDLE_VALUE;
211  if(InterlockedCompareExchangePointer((void**)&__pioinfo[fd/MSVCRT_FD_BLOCK_SIZE], block, NULL))
212  free(block);
213  return TRUE;
214 }
static unsigned int block
Definition: xmlmemory.c:118
#define MSVCRT_FD_BLOCK_SIZE
Definition: file.c:113
#define TRUE
Definition: types.h:120
Definition: file.c:40
#define free
Definition: debug_ros.c:5
#define WARN(fmt,...)
Definition: debug.h:111
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static int fd
Definition: io.c:51
ioinfo * __pioinfo[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE]
Definition: file.c:121
Definition: arc.h:48
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
smooth NULL
Definition: ftsmooth.c:416
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define ENFILE
Definition: errno.h:29
#define calloc
Definition: rosglue.h:14
#define MSVCRT_MAX_FILES
Definition: file.c:112
static int check_bom ( HANDLE  h,
int  oflags,
BOOL  seek 
)
static

Definition at line 1752 of file file.c.

Referenced by _wsopen_s().

1753 {
1754  char bom[sizeof(utf8_bom)];
1755  DWORD r;
1756 
1757  oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT);
1758 
1759  if (!ReadFile(h, bom, sizeof(utf8_bom), &r, NULL))
1760  return oflags;
1761 
1762  if (r==sizeof(utf8_bom) && !memcmp(bom, utf8_bom, sizeof(utf8_bom))) {
1763  oflags |= _O_U8TEXT;
1764  }else if (r>=sizeof(utf16_bom) && !memcmp(bom, utf16_bom, sizeof(utf16_bom))) {
1765  if (seek && r>2)
1767  oflags |= _O_U16TEXT;
1768  }else if (seek) {
1770  }
1771 
1772  return oflags;
1773 }
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:108
DWORD DWORD
Definition: winlogon.h:84
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:416
#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:109
#define FILE_BEGIN
Definition: winbase.h:112
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 1363 of file file.c.

Referenced by rewind(), and ungetc().

1364 {
1365  TRACE(":file (%p) fd (%d)\n",file,file->_file);
1366 
1367  _lock_file(file);
1368  file->_flag &= ~(_IOERR | _IOEOF);
1369  _unlock_file(file);
1370 }
void CDECL _unlock_file(FILE *file)
Definition: file.c:1205
#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:1193
int _flag
Definition: mbstring.h:23
int _file
Definition: mbstring.h:24
unsigned create_io_inherit_block ( WORD size,
BYTE **  block 
)

Definition at line 411 of file file.c.

412 {
413  int fd, last_fd;
414  char* wxflag_ptr;
415  HANDLE* handle_ptr;
416  ioinfo* fdinfo;
417 
418  for (last_fd=MSVCRT_MAX_FILES-1; last_fd>=0; last_fd--)
420  break;
421  last_fd++;
422 
423  *size = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * last_fd;
424  *block = calloc(1, *size);
425  if (!*block)
426  {
427  *size = 0;
428  return FALSE;
429  }
430  wxflag_ptr = (char*)*block + sizeof(unsigned);
431  handle_ptr = (HANDLE*)(wxflag_ptr + last_fd);
432 
433  *(unsigned*)*block = last_fd;
434  for (fd = 0; fd < last_fd; fd++)
435  {
436  /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
437  fdinfo = get_ioinfo(fd);
438  if ((fdinfo->wxflag & (WX_OPEN | WX_DONTINHERIT)) == WX_OPEN)
439  {
440  *wxflag_ptr = fdinfo->wxflag;
441  *handle_ptr = fdinfo->handle;
442  }
443  else
444  {
445  *wxflag_ptr = 0;
446  *handle_ptr = INVALID_HANDLE_VALUE;
447  }
448  release_ioinfo(fdinfo);
449  wxflag_ptr++; handle_ptr++;
450  }
451  return TRUE;
452 }
static unsigned int block
Definition: xmlmemory.c:118
#define TRUE
Definition: types.h:120
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
Definition: file.c:40
#define WX_DONTINHERIT
Definition: file.c:97
static HANDLE
Definition: file.c:109
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static int fd
Definition: io.c:51
#define FALSE
Definition: types.h:117
HANDLE handle
Definition: file.c:41
unsigned char wxflag
Definition: file.c:42
GLsizeiptr size
Definition: glext.h:5919
#define WX_OPEN
Definition: file.c:91
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
void release_ioinfo(ioinfo *info)
Definition: file.c:263
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define calloc
Definition: rosglue.h:14
#define MSVCRT_MAX_FILES
Definition: file.c:112
int CDECL fclose ( FILE file)

Definition at line 2783 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_invalid_stdin_child(), test_pipes(), test_readboundary(), test_readmode(), test_unlink(), and test_write_flush().

2784 {
2785  int r, flag;
2786 
2787  _lock_file(file);
2788  flag = file->_flag;
2789  free(file->_tmpfname);
2790  file->_tmpfname = NULL;
2791  /* flush stdio buffers */
2792  if(file->_flag & _IOWRT)
2793  fflush(file);
2794  if(file->_flag & _IOMYBUF)
2795  free(file->_base);
2796 
2797  r=_close(file->_file);
2798 
2799  file->_flag = 0;
2800  _unlock_file(file);
2802  DeleteCriticalSection(&((file_crit*)file)->crit);
2803 
2804  if(file == msvcrt_get_file(MSVCRT_stream_idx-1)) {
2805  while(MSVCRT_stream_idx>3 && !file->_flag) {
2808  }
2809  }
2810 
2811  return ((r == -1) || (flag & _IOERR) ? EOF : 0);
2812 }
char * _base
Definition: mbstring.h:22
static int MSVCRT_stream_idx
Definition: file.c:135
void CDECL _unlock_file(FILE *file)
Definition: file.c:1205
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:416
int CDECL _close(int fd)
Definition: file.c:931
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:1193
#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:901
static FILE * msvcrt_get_file(int i)
Definition: file.c:269
#define EOF
Definition: stdio.h:24
int _file
Definition: mbstring.h:24
FILE _iob[_IOB_ENTRIES]
Definition: file.c:133
Definition: fci.c:126
int CDECL feof ( FILE file)

Definition at line 2817 of file file.c.

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

2818 {
2819  return file->_flag & _IOEOF;
2820 }
#define _IOEOF
Definition: stdio.h:133
int _flag
D