ReactOS 0.4.16-dev-2104-gb84fa49
file.c File Reference
#include <direct.h>
#include <fcntl.h>
#include <io.h>
#include <share.h>
#include <stdarg.h>
#include <sys/locking.h>
#include <sys/types.h>
#include <sys/utime.h>
#include <time.h>
#include <limits.h>
#include "windef.h"
#include "winbase.h"
#include "wincon.h"
#include "winternl.h"
#include "winnls.h"
#include "msvcrt.h"
#include "mtdll.h"
#include "wine/asm.h"
#include "wine/debug.h"
Include dependency graph for file.c:

Go to the source code of this file.

Classes

struct  ioinfo
 
struct  file_crit
 

Macros

#define ALL_S_IREAD   (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
 
#define ALL_S_IWRITE   (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
 
#define ALL_S_IEXEC   (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))
 
#define MSVCRT_W_OK   0x02
 
#define MSVCRT_R_OK   0x04
 
#define WX_OPEN   0x01
 
#define WX_ATEOF   0x02
 
#define WX_READNL   0x04 /* read started with \n */
 
#define WX_PIPE   0x08
 
#define WX_DONTINHERIT   0x10
 
#define WX_APPEND   0x20
 
#define WX_TTY   0x40
 
#define WX_TEXT   0x80
 
#define MSVCRT_INTERNAL_BUFSIZ   4096
 
#define MSVCRT_MAX_FILES   2048
 
#define MSVCRT_FD_BLOCK_SIZE   32
 
#define EF_UTF8   0x01
 
#define EF_UTF16   0x02
 
#define EF_CRIT_INIT   0x04
 
#define EF_UNK_UNICODE   0x08
 
#define TOUL(x)   (ULONGLONG)(x)
 
#define LOCK_FILES()   do { EnterCriticalSection(&MSVCRT_file_cs); } while (0)
 
#define UNLOCK_FILES()   do { LeaveCriticalSection(&MSVCRT_file_cs); } while (0)
 

Enumerations

enum  textmode { TEXTMODE_ANSI , TEXTMODE_UTF8 , TEXTMODE_UTF16LE }
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msvcrt)
 
int __cdecl _wstat64 (const wchar_t *, struct _stat64 *)
 
static BOOL ioinfo_is_crit_init (ioinfo *info)
 
static void ioinfo_set_crit_init (ioinfo *info)
 
static enum textmode ioinfo_get_textmode (ioinfo *info)
 
static void ioinfo_set_textmode (ioinfo *info, enum textmode mode)
 
static void ioinfo_set_unicode (ioinfo *info, BOOL unicode)
 
static FILEiob_get_file (int i)
 
static CRITICAL_SECTIONfile_get_cs (FILE *f)
 
static void msvcrt_stat64_to_stat (const struct _stat64 *buf64, struct _stat *buf)
 
static void msvcrt_stat64_to_stati64 (const struct _stat64 *buf64, struct _stati64 *buf)
 
static void msvcrt_stat64_to_stat32 (const struct _stat64 *buf64, struct _stat32 *buf)
 
static void msvcrt_stat64_to_stat64i32 (const struct _stat64 *buf64, struct _stat64i32 *buf)
 
static void msvcrt_stat64_to_stat32i64 (const struct _stat64 *buf64, struct _stat32i64 *buf)
 
static void time_to_filetime (__time64_t time, FILETIME *ft)
 
static ioinfoget_ioinfo_nolock (int fd)
 
static void init_ioinfo_cs (ioinfo *info)
 
static ioinfoget_ioinfo (int fd)
 
static BOOL alloc_pioinfo_block (int fd)
 
static ioinfoget_ioinfo_alloc_fd (int fd)
 
static ioinfoget_ioinfo_alloc (int *fd)
 
static 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)
 
static 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)
 
BOOL msvcrt_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)
 
static 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)
 
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)
 
static int msvcrt_flush_all_buffers (int mask)
 
int CDECL _flushall (void)
 
int CDECL fflush (FILE *file)
 
int CDECL _fflush_nolock (FILE *file)
 
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)
 
__msvcrt_long CDECL _lseek (int fd, __msvcrt_long offset, int whence)
 
void CDECL _lock_file (FILE *file)
 
void CDECL _unlock_file (FILE *file)
 
int CDECL _locking (int fd, int mode, __msvcrt_long nbytes)
 
int CDECL _fseeki64 (FILE *file, __int64 offset, int whence)
 
int CDECL _fseeki64_nolock (FILE *file, __int64 offset, int whence)
 
int CDECL fseek (FILE *file, __msvcrt_long offset, int whence)
 
int CDECL _fseek_nolock (FILE *file, __msvcrt_long offset, int whence)
 
int CDECL _chsize_s (int fd, __int64 size)
 
int CDECL _chsize (int fd, __msvcrt_long size)
 
void CDECL clearerr (FILE *file)
 
int CDECL clearerr_s (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)
 
__msvcrt_long CDECL _filelength (int fd)
 
__int64 CDECL _filelengthi64 (int fd)
 
int CDECL _fileno (FILE *file)
 
int CDECL _fstat64 (int fd, struct _stat64 *buf)
 
int CDECL _fstati64 (int fd, struct _stati64 *buf)
 
int CDECL _fstat (int fd, struct _stat *buf)
 
int CDECL _fstat32 (int fd, struct _stat32 *buf)
 
int CDECL _fstat32i64 (int fd, struct _stat32i64 *buf)
 
int CDECL _fstat64i32 (int fd, struct _stat64i32 *buf)
 
int CDECL _futime64 (int fd, struct __utimbuf64 *t)
 
int CDECL _futime32 (int fd, struct __utimbuf32 *t)
 
intptr_t CDECL _get_osfhandle (int fd)
 
int CDECL _mktemp_s (char *pattern, size_t size)
 
char *CDECL _mktemp (char *pattern)
 
int CDECL _wmktemp_s (wchar_t *pattern, size_t size)
 
wchar_t *CDECL _wmktemp (wchar_t *pattern)
 
static 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_dispatch (const wchar_t *path, int oflags, int shflags, int pmode, int *fd, int secure)
 
int CDECL _wsopen_s (int *fd, const wchar_t *path, int oflags, int shflags, int pmode)
 
int WINAPIV _wsopen (const wchar_t *path, int oflags, int shflags,...)
 
int CDECL _sopen_dispatch (const char *path, int oflags, int shflags, int pmode, int *fd, int secure)
 
int CDECL _sopen_s (int *fd, const char *path, int oflags, int shflags, int pmode)
 
int WINAPIV _sopen (const char *path, int oflags, int shflags,...)
 
int WINAPIV _open (const char *path, int flags,...)
 
int WINAPIV _wopen (const wchar_t *path, int flags,...)
 
int CDECL _creat (const char *path, int pmode)
 
int CDECL _wcreat (const wchar_t *path, int pmode)
 
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)
 
int CDECL _stat64 (const char *path, struct _stat64 *buf)
 
int CDECL _stati64 (const char *path, struct _stati64 *buf)
 
int CDECL _stat (const char *path, struct _stat *buf)
 
int CDECL _wstati64 (const wchar_t *path, struct _stati64 *buf)
 
int CDECL _wstat (const wchar_t *path, struct _stat *buf)
 
__msvcrt_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 _utime64 (const char *path, struct __utimbuf64 *t)
 
int CDECL _utime32 (const char *path, struct __utimbuf32 *t)
 
int CDECL _wutime64 (const wchar_t *path, struct __utimbuf64 *t)
 
int CDECL _wutime32 (const wchar_t *path, struct __utimbuf32 *t)
 
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 _fclose_nolock (FILE *file)
 
int CDECL feof (FILE *file)
 
int CDECL ferror (FILE *file)
 
int CDECL _filbuf (FILE *file)
 
int CDECL fgetc (FILE *file)
 
int CDECL _fgetc_nolock (FILE *file)
 
int CDECL _fgetchar (void)
 
char *CDECL fgets (char *s, int size, FILE *file)
 
wint_t CDECL fgetwc (FILE *file)
 
wint_t CDECL _fgetwc_nolock (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)
 
int CDECL _flsbuf (int c, FILE *file)
 
size_t CDECL fwrite (const void *ptr, size_t size, size_t nmemb, FILE *file)
 
size_t CDECL _fwrite_nolock (const void *ptr, size_t size, size_t nmemb, FILE *file)
 
wint_t CDECL fputwc (wint_t wc, FILE *file)
 
wint_t CDECL _fputwc_nolock (wint_t wc, FILE *file)
 
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 fputc (int c, FILE *file)
 
int CDECL _fputc_nolock (int c, FILE *file)
 
int CDECL _fputchar (int c)
 
size_t CDECL fread (void *ptr, size_t size, size_t nmemb, FILE *file)
 
size_t CDECL _fread_nolock (void *ptr, size_t size, size_t nmemb, FILE *file)
 
FILE *CDECL _wfreopen (const wchar_t *path, const wchar_t *mode, FILE *file)
 
int CDECL _wfreopen_s (FILE **pFile, const wchar_t *path, const wchar_t *mode, FILE *file)
 
FILE *CDECL freopen (const char *path, const char *mode, FILE *file)
 
errno_t CDECL freopen_s (FILE **pFile, const char *path, const char *mode, FILE *file)
 
int CDECL fsetpos (FILE *file, fpos_t *pos)
 
__int64 CDECL _ftelli64 (FILE *file)
 
__int64 CDECL _ftelli64_nolock (FILE *file)
 
__msvcrt_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_s (char *buf, size_t len)
 
char *CDECL gets (char *buf)
 
wchar_t *CDECL _getws (wchar_t *buf)
 
int CDECL putc (int c, FILE *file)
 
int CDECL putchar (int 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)
 
static int tmpnam_helper (char *s, size_t size, LONG *tmpnam_unique, int tmp_max)
 
int CDECL tmpnam_s (char *s, size_t size)
 
char *CDECL tmpnam (char *s)
 
static int wtmpnam_helper (wchar_t *s, size_t size, LONG *tmpnam_unique, int tmp_max)
 
int CDECL _wtmpnam_s (wchar_t *s, size_t size)
 
wchar_t *CDECL _wtmpnam (wchar_t *s)
 
FILE *CDECL tmpfile (void)
 
int CDECL tmpfile_s (FILE **file)
 
static int puts_clbk_file_a (void *file, int len, const char *str)
 
static int puts_clbk_file_w (void *file, int len, const wchar_t *str)
 
static int vfprintf_helper (DWORD options, FILE *file, const char *format, _locale_t locale, va_list valist)
 
static int vfwprintf_helper (DWORD options, FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
 
int CDECL _vfprintf_s_l (FILE *file, const char *format, _locale_t locale, va_list valist)
 
int CDECL _vfwprintf_s_l (FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
 
int CDECL vfprintf (FILE *file, const char *format, va_list valist)
 
int CDECL vfprintf_s (FILE *file, const char *format, va_list valist)
 
int CDECL vfwprintf (FILE *file, const wchar_t *format, va_list valist)
 
int CDECL vfwprintf_s (FILE *file, const wchar_t *format, va_list valist)
 
int CDECL _vfprintf_l (FILE *file, const char *format, _locale_t locale, va_list valist)
 
int CDECL _vfwprintf_l (FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
 
int CDECL _vfprintf_p_l (FILE *file, const char *format, _locale_t locale, va_list valist)
 
int CDECL _vfprintf_p (FILE *file, const char *format, va_list valist)
 
int CDECL _vfwprintf_p_l (FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
 
int CDECL _vfwprintf_p (FILE *file, const wchar_t *format, va_list valist)
 
int CDECL vprintf (const char *format, va_list valist)
 
int CDECL vprintf_s (const char *format, va_list valist)
 
int CDECL vwprintf (const wchar_t *format, va_list valist)
 
int CDECL vwprintf_s (const wchar_t *format, va_list valist)
 
int WINAPIV fprintf (FILE *file, const char *format,...)
 
int WINAPIV fprintf_s (FILE *file, const char *format,...)
 
int WINAPIV _fprintf_l (FILE *file, const char *format, _locale_t locale,...)
 
int WINAPIV _fprintf_p (FILE *file, const char *format,...)
 
int WINAPIV _fprintf_p_l (FILE *file, const char *format, _locale_t locale,...)
 
int WINAPIV _fprintf_s_l (FILE *file, const char *format, _locale_t locale,...)
 
int WINAPIV fwprintf (FILE *file, const wchar_t *format,...)
 
int WINAPIV fwprintf_s (FILE *file, const wchar_t *format,...)
 
int WINAPIV _fwprintf_l (FILE *file, const wchar_t *format, _locale_t locale,...)
 
int WINAPIV _fwprintf_p (FILE *file, const wchar_t *format,...)
 
int WINAPIV _fwprintf_p_l (FILE *file, const wchar_t *format, _locale_t locale,...)
 
int WINAPIV _fwprintf_s_l (FILE *file, const wchar_t *format, _locale_t locale,...)
 
int WINAPIV printf (const char *format,...)
 
int WINAPIV printf_s (const char *format,...)
 
int CDECL ungetc (int c, FILE *file)
 
int CDECL _ungetc_nolock (int c, FILE *file)
 
wint_t CDECL ungetwc (wint_t wc, FILE *file)
 
wint_t CDECL _ungetwc_nolock (wint_t wc, FILE *file)
 
int WINAPIV wprintf (const wchar_t *format,...)
 
int WINAPIV wprintf_s (const wchar_t *format,...)
 
int CDECL _getmaxstdio (void)
 
int CDECL _setmaxstdio (int newmax)
 

Variables

static char utf8_bom [3] = { 0xef, 0xbb, 0xbf }
 
static char utf16_bom [2] = { 0xff, 0xfe }
 
ioinfo MSVCRT___badioinfo = { INVALID_HANDLE_VALUE, WX_TEXT }
 
ioinfoMSVCRT___pioinfo [MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { 0 }
 
FILE MSVCRT__iob [_IOB_ENTRIES] = { { 0 } }
 
static file_critMSVCRT_fstream [MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE]
 
static int MSVCRT_max_streams = 512
 
static int MSVCRT_stream_idx
 
static int MSVCRT_umask = 0
 
static LONG tmpnam_unique
 
static LONG tmpnam_s_unique
 
static const ULONGLONG WCEXE = TOUL('e') << 32 | TOUL('x') << 16 | TOUL('e')
 
static const ULONGLONG WCBAT = TOUL('b') << 32 | TOUL('a') << 16 | TOUL('t')
 
static const ULONGLONG WCCMD = TOUL('c') << 32 | TOUL('m') << 16 | TOUL('d')
 
static const ULONGLONG WCCOM = TOUL('c') << 32 | TOUL('o') << 16 | TOUL('m')
 
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

◆ ALL_S_IEXEC

#define ALL_S_IEXEC   (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))

Definition at line 73 of file file.c.

◆ ALL_S_IREAD

#define ALL_S_IREAD   (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))

Definition at line 71 of file file.c.

◆ ALL_S_IWRITE

#define ALL_S_IWRITE   (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))

Definition at line 72 of file file.c.

◆ EF_CRIT_INIT

#define EF_CRIT_INIT   0x04

Definition at line 198 of file file.c.

◆ EF_UNK_UNICODE

#define EF_UNK_UNICODE   0x08

Definition at line 199 of file file.c.

◆ EF_UTF16

#define EF_UTF16   0x02

Definition at line 197 of file file.c.

◆ EF_UTF8

#define EF_UTF8   0x01

Definition at line 196 of file file.c.

◆ LOCK_FILES

#define LOCK_FILES ( )    do { EnterCriticalSection(&MSVCRT_file_cs); } while (0)

Definition at line 306 of file file.c.

◆ MSVCRT_FD_BLOCK_SIZE

#define MSVCRT_FD_BLOCK_SIZE   32

Definition at line 126 of file file.c.

◆ MSVCRT_INTERNAL_BUFSIZ

#define MSVCRT_INTERNAL_BUFSIZ   4096

Definition at line 92 of file file.c.

◆ MSVCRT_MAX_FILES

#define MSVCRT_MAX_FILES   2048

Definition at line 125 of file file.c.

◆ MSVCRT_R_OK

#define MSVCRT_R_OK   0x04

Definition at line 77 of file file.c.

◆ MSVCRT_W_OK

#define MSVCRT_W_OK   0x02

Definition at line 76 of file file.c.

◆ TOUL

#define TOUL (   x)    (ULONGLONG)(x)

Definition at line 288 of file file.c.

◆ UNLOCK_FILES

#define UNLOCK_FILES ( )    do { LeaveCriticalSection(&MSVCRT_file_cs); } while (0)

Definition at line 307 of file file.c.

◆ WX_APPEND

#define WX_APPEND   0x20

Definition at line 85 of file file.c.

◆ WX_ATEOF

#define WX_ATEOF   0x02

Definition at line 81 of file file.c.

◆ WX_DONTINHERIT

#define WX_DONTINHERIT   0x10

Definition at line 84 of file file.c.

◆ WX_OPEN

#define WX_OPEN   0x01

Definition at line 80 of file file.c.

◆ WX_PIPE

#define WX_PIPE   0x08

Definition at line 83 of file file.c.

◆ WX_READNL

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

Definition at line 82 of file file.c.

◆ WX_TEXT

#define WX_TEXT   0x80

Definition at line 87 of file file.c.

◆ WX_TTY

#define WX_TTY   0x40

Definition at line 86 of file file.c.

Enumeration Type Documentation

◆ textmode

Enumerator
TEXTMODE_ANSI 
TEXTMODE_UTF8 
TEXTMODE_UTF16LE 

Definition at line 94 of file file.c.

95{
99};
@ TEXTMODE_ANSI
Definition: file.c:96
@ TEXTMODE_UTF16LE
Definition: file.c:98
@ TEXTMODE_UTF8
Definition: file.c:97

Function Documentation

◆ __iob_func()

FILE *CDECL __iob_func ( void  )

Definition at line 972 of file file.c.

973{
974 return iob_get_file(0);
975}
static FILE * iob_get_file(int i)
Definition: file.c:265

Referenced by Test__iob().

◆ _access()

int CDECL _access ( const char filename,
int  mode 
)

Definition at line 990 of file file.c.

991{
992 wchar_t *filenameW = NULL;
993 int ret;
994
995 if (filename && !(filenameW = wstrdupa_utf8(filename))) return -1;
998 return ret;
999}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
int CDECL _waccess(const wchar_t *filename, int mode)
Definition: file.c:1017
static wchar_t * wstrdupa_utf8(const char *str)
Definition: msvcrt.h:440
return ret
Definition: mutex.c:146
GLenum mode
Definition: glext.h:6217
const char * filename
Definition: ioapi.h:137
static const WCHAR filenameW[]
Definition: amstream.c:41

Referenced by _access_s(), _searchenv_s(), access(), HaveSpool(), and MkDirs().

◆ _access_s()

int CDECL _access_s ( const char filename,
int  mode 
)

Definition at line 1004 of file file.c.

1005{
1006 if (!MSVCRT_CHECK_PMT(filename != NULL)) return *_errno();
1007 if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return *_errno();
1008
1009 if (_access(filename, mode) == -1)
1010 return *_errno();
1011 return 0;
1012}
int *CDECL _errno(void)
Definition: errno.c:215
#define MSVCRT_W_OK
Definition: file.c:76
#define MSVCRT_R_OK
Definition: file.c:77
int CDECL _access(const char *filename, int mode)
Definition: file.c:990
#define MSVCRT_CHECK_PMT(x)
Definition: msvcrt.h:378

◆ _chmod()

int CDECL _chmod ( const char path,
int  flags 
)

Definition at line 1052 of file file.c.

1053{
1054 wchar_t *pathW = NULL;
1055 int ret;
1056
1057 if (path && !(pathW = wstrdupa_utf8(path))) return -1;
1058 ret = _wchmod(pathW, flags);
1059 free(pathW);
1060 return ret;
1061}
int CDECL _wchmod(const wchar_t *path, int flags)
Definition: file.c:1066
GLbitfield flags
Definition: glext.h:7161

Referenced by chmod(), LoadFirewallPrefs(), OpenBookmarkFile(), OpenTmpBookmarkFile(), OpenTrace(), rw(), SaveHistory(), test_file_write_read(), and test_utf8().

◆ _chsize()

int CDECL _chsize ( int  fd,
__msvcrt_long  size 
)

Definition at line 1663 of file file.c.

1664{
1665 /* _chsize_s returns errno on failure but _chsize should return -1 */
1666 return _chsize_s( fd, size ) == 0 ? 0 : -1;
1667}
int CDECL _chsize_s(int fd, __int64 size)
Definition: file.c:1626
GLsizeiptr size
Definition: glext.h:5919
static int fd
Definition: io.c:51

Referenced by chsize(), ftruncate(), rw(), and test_chsize().

◆ _chsize_s()

int CDECL _chsize_s ( int  fd,
__int64  size 
)

Definition at line 1626 of file file.c.

1627{
1628 ioinfo *info;
1629 __int64 cur, pos;
1630 BOOL ret = FALSE;
1631
1632 TRACE("(fd=%d, size=%#I64x)\n", fd, size);
1633
1634 if (!MSVCRT_CHECK_PMT(size >= 0)) return EINVAL;
1635
1636
1637 info = get_ioinfo(fd);
1638 if (info->handle != INVALID_HANDLE_VALUE)
1639 {
1640 /* save the current file pointer */
1641 cur = _lseeki64(fd, 0, SEEK_CUR);
1642 if (cur >= 0)
1643 {
1645 if (pos >= 0)
1646 {
1647 ret = SetEndOfFile(info->handle);
1649 }
1650
1651 /* restore the file pointer */
1653 }
1654 }
1655
1657 return ret ? 0 : *_errno();
1658}
#define FALSE
Definition: types.h:117
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
__int64 CDECL _lseeki64(int fd, __int64 offset, int whence)
Definition: file.c:1432
static ioinfo * get_ioinfo(int fd)
Definition: file.c:417
static void release_ioinfo(ioinfo *info)
Definition: file.c:514
#define __int64
Definition: corecrt.h:72
#define EINVAL
Definition: errno.h:44
#define SEEK_CUR
Definition: stdio.h:44
unsigned int BOOL
Definition: ntddk_ex.h:94
FxCollectionEntry * cur
#define SEEK_SET
Definition: jmemansi.c:26
#define msvcrt_set_errno
Definition: heap.c:50
#define TRACE(s)
Definition: solgame.cpp:4
Definition: file.c:128
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by _chsize().

◆ _close()

int CDECL _close ( int  fd)

Definition at line 1219 of file file.c.

1220{
1222 int ret;
1223
1224 TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1225
1226 if (fd == MSVCRT_NO_CONSOLE_FD) {
1227 *_errno() = EBADF;
1228 ret = -1;
1229 } else if (!MSVCRT_CHECK_PMT_ERR(info->wxflag & WX_OPEN, EBADF)) {
1230 ret = -1;
1231 } else if (fd == STDOUT_FILENO &&
1234 ret = 0;
1235 } else if (fd == STDERR_FILENO &&
1238 ret = 0;
1239 } else {
1240 ret = CloseHandle(info->handle) ? 0 : -1;
1242 if (ret) {
1243 WARN(":failed-last error (%ld)\n", GetLastError());
1245 }
1246 }
1248 return ret;
1249}
#define WARN(fmt,...)
Definition: precomp.h:61
#define CloseHandle
Definition: compat.h:739
#define WX_OPEN
Definition: file.c:80
static void msvcrt_free_fd(int fd)
Definition: file.c:547
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:394
#define EBADF
Definition: errno.h:32
#define STDOUT_FILENO
Definition: stdio.h:25
#define STDERR_FILENO
Definition: stdio.h:26
#define MSVCRT_NO_CONSOLE_FD
Definition: msvcrt.h:327
#define MSVCRT_CHECK_PMT_ERR(x, err)
Definition: msvcrt.h:377

Referenced by _dup2(), _fclose_nolock(), _pipe(), _Success_(), _tutime(), _utime64(), _wfsopen(), _wpopen(), _wutime64(), anonymous_namespace{stat.cpp}::file_handle_traits::close(), close(), common_popen(), common_popen_nolock(), common_utime(), compat_close(), fclose(), install_from_unix_file(), main(), rd_close_file(), run_open_osfhandle(), rw(), test__creat(), test__popen(), test__sopen_dispatch(), test__sopen_s(), test_chsize(), test_file_write_read(), test_get_osfhandle(), test_lseek(), test_setmode(), and tmpfile().

◆ _commit()

int CDECL _commit ( int  fd)

Definition at line 1112 of file file.c.

1113{
1115 int ret;
1116
1117 TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1118
1119 if (info->handle == INVALID_HANDLE_VALUE)
1120 ret = -1;
1121 else if (!FlushFileBuffers(info->handle))
1122 {
1124 {
1125 /* FlushFileBuffers fails for console handles
1126 * so we ignore this error.
1127 */
1128 ret = 0;
1129 }
1130 else
1131 {
1132 TRACE(":failed-last error (%ld)\n", GetLastError());
1134 ret = -1;
1135 }
1136 }
1137 else
1138 {
1139 TRACE(":ok\n");
1140 ret = 0;
1141 }
1142
1144 return ret;
1145}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25

Referenced by _fflush_nolock(), and _fflush_nolock_internal().

◆ _creat()

int CDECL _creat ( const char path,
int  pmode 
)

Definition at line 2693 of file file.c.

2694{
2695 int flags = _O_CREAT | _O_TRUNC | _O_RDWR;
2696 return _open(path, flags, pmode);
2697}
#define _O_RDWR
Definition: cabinet.h:39
#define _O_TRUNC
Definition: cabinet.h:47
#define _O_CREAT
Definition: cabinet.h:46
int WINAPIV _open(const char *path, int flags,...)
Definition: file.c:2655

Referenced by creat(), test__creat(), and test_lseek().

◆ _dup()

int CDECL _dup ( int  od)

Definition at line 1317 of file file.c.

1318{
1319 int fd, ret;
1321
1322 if (_dup2(od, fd) == 0)
1323 ret = fd;
1324 else
1325 ret = -1;
1327 return ret;
1328}
int CDECL _dup2(int od, int nd)
Definition: file.c:1258
static ioinfo * get_ioinfo_alloc(int *fd)
Definition: file.c:481

Referenced by _wpopen(), DllMain(), dup(), test_std_stream_buffering(), test_std_stream_open(), and test_stdin().

◆ _dup2()

int CDECL _dup2 ( int  od,
int  nd 
)

Definition at line 1258 of file file.c.

1259{
1260 ioinfo *info_od, *info_nd;
1261 int ret;
1262
1263 TRACE("(od=%d, nd=%d)\n", od, nd);
1264
1265 if (od < nd)
1266 {
1267 info_od = get_ioinfo(od);
1268 info_nd = get_ioinfo_alloc_fd(nd);
1269 }
1270 else
1271 {
1272 info_nd = get_ioinfo_alloc_fd(nd);
1273 info_od = get_ioinfo(od);
1274 }
1275
1276 if (info_nd == &MSVCRT___badioinfo)
1277 {
1278 *_errno() = EBADF;
1279 ret = -1;
1280 }
1281 else if (info_od->wxflag & WX_OPEN)
1282 {
1283 HANDLE handle;
1284
1287 {
1288 int wxflag = info_od->wxflag & ~WX_DONTINHERIT;
1289
1290 if (info_nd->wxflag & WX_OPEN)
1291 _close(nd);
1292
1293 msvcrt_set_fd(info_nd, handle, wxflag);
1294 /* _dup2 returns 0, not nd, on success */
1295 ret = 0;
1296 }
1297 else
1298 {
1299 ret = -1;
1301 }
1302 }
1303 else
1304 {
1305 *_errno() = EBADF;
1306 ret = -1;
1307 }
1308
1309 release_ioinfo(info_od);
1310 release_ioinfo(info_nd);
1311 return ret;
1312}
#define TRUE
Definition: types.h:120
#define GetCurrentProcess()
Definition: compat.h:759
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
static ioinfo * get_ioinfo_alloc_fd(int fd)
Definition: file.c:467
ioinfo MSVCRT___badioinfo
Definition: file.c:148
int CDECL _close(int fd)
Definition: file.c:1219
static void msvcrt_set_fd(ioinfo *fdinfo, HANDLE hand, int flag)
Definition: file.c:576
unsigned char wxflag
Definition: file.c:130
HANDLE handle
Definition: file.c:129
#define DUPLICATE_SAME_ACCESS

Referenced by _dup(), _tWinMain(), DllMain(), dup2(), test_dup2(), test_stat(), test_std_stream_buffering(), test_std_stream_open(), and test_stdin().

◆ _eof()

int CDECL _eof ( int  fd)

Definition at line 1333 of file file.c.

1334{
1336 DWORD curpos,endpos;
1337 LONG hcurpos,hendpos;
1338
1339 TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1340
1341 if (info->handle == INVALID_HANDLE_VALUE)
1342 {
1344 return -1;
1345 }
1346
1347 if (info->wxflag & WX_ATEOF)
1348 {
1350 return TRUE;
1351 }
1352
1353 /* Otherwise we do it the hard way */
1354 hcurpos = hendpos = 0;
1355 curpos = SetFilePointer(info->handle, 0, &hcurpos, FILE_CURRENT);
1356 endpos = SetFilePointer(info->handle, 0, &hendpos, FILE_END);
1357
1358 if (curpos == endpos && hcurpos == hendpos)
1359 {
1360 /* FIXME: shouldn't WX_ATEOF be set here? */
1362 return TRUE;
1363 }
1364
1365 SetFilePointer(info->handle, curpos, &hcurpos, FILE_BEGIN);
1367 return FALSE;
1368}
#define FILE_BEGIN
Definition: compat.h:761
#define SetFilePointer
Definition: compat.h:743
#define WX_ATEOF
Definition: file.c:81
unsigned long DWORD
Definition: ntddk_ex.h:95
long LONG
Definition: pedump.c:60
#define FILE_END
Definition: winbase.h:116
#define FILE_CURRENT
Definition: winbase.h:115

Referenced by eof().

◆ _fclose_nolock()

int CDECL _fclose_nolock ( FILE file)

Definition at line 3773 of file file.c.

3774{
3775 int r, flag;
3776
3777 if (!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
3778
3779 if(!(file->_flag & (_IOREAD | _IOWRT | _IORW)))
3780 {
3781 file->_flag = 0;
3782 return EOF;
3783 }
3784
3785 flag = file->_flag;
3786 free(file->_tmpfname);
3787 file->_tmpfname = NULL;
3788 /* flush stdio buffers */
3789 if(file->_flag & _IOWRT)
3791 if(file->_flag & _IOMYBUF)
3792 free(file->_base);
3793
3794 r=_close(file->_file);
3795 file->_flag = 0;
3796
3797 return ((r == -1) || (flag & _IOERR) ? EOF : 0);
3798}
int CDECL _fflush_nolock(FILE *file)
Definition: file.c:1201
#define _IOMYBUF
Definition: stdio.h:17
#define _IOWRT
Definition: stdio.h:16
#define EOF
Definition: stdio.h:33
#define _IOREAD
Definition: stdio.h:15
#define _IORW
Definition: stdio.h:21
#define _IOERR
Definition: stdio.h:19
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLsizei GLenum const GLvoid GLsizei GLenum 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 flag
Definition: glfuncs.h:52
Definition: fci.c:127

Referenced by _rmtmp(), common_freopen(), and fclose().

◆ _fcloseall()

int CDECL _fcloseall ( void  )

Definition at line 1373 of file file.c.

1374{
1375 int num_closed = 0, i;
1376 FILE *file;
1377
1378 LOCK_FILES();
1379 for (i = 3; i < MSVCRT_stream_idx; i++) {
1381
1382 if (file->_flag && !fclose(file))
1383 num_closed++;
1384 }
1385 UNLOCK_FILES();
1386
1387 TRACE(":closed (%d) handles\n",num_closed);
1388 return num_closed;
1389}
#define LOCK_FILES()
Definition: file.c:306
int CDECL fclose(FILE *file)
Definition: file.c:3757
#define UNLOCK_FILES()
Definition: file.c:307
static FILE * msvcrt_get_file(int i)
Definition: file.c:520
static int MSVCRT_stream_idx
Definition: file.c:279
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by __acrt_uninitialize_stdio(), msvcrt_free_io(), and test_fopen_fclose_fcloseall().

◆ _fdopen()

FILE *CDECL _fdopen ( int  fd,
const char mode 
)

Definition at line 1847 of file file.c.

1848{
1849 FILE *ret;
1850 wchar_t *modeW = NULL;
1851
1852 if (mode && !(modeW = msvcrt_wstrdupa(mode))) return NULL;
1853
1854 ret = _wfdopen(fd, modeW);
1855
1856 free(modeW);
1857 return ret;
1858}
wchar_t * msvcrt_wstrdupa(const char *str)
Definition: data.c:373
FILE *CDECL _wfdopen(int fd, const wchar_t *mode)
Definition: file.c:1863

Referenced by _tWinMain(), ConStreamSetOSHandle(), and FTPRebuildConnectionInfo().

◆ _fflush_nolock()

int CDECL _fflush_nolock ( FILE file)

Definition at line 1201 of file file.c.

1202{
1203 int res;
1204
1205 if(!file) {
1207 return 0;
1208 }
1209
1211 if(!res && (file->_flag & MSVCRT__IOCOMMIT))
1212 res = _commit(file->_file) ? EOF : 0;
1213 return res;
1214}
int CDECL _commit(int fd)
Definition: file.c:1112
static int msvcrt_flush_buffer(FILE *file)
Definition: file.c:835
static int msvcrt_flush_all_buffers(int mask)
Definition: file.c:1148
#define MSVCRT__IOCOMMIT
Definition: msvcrt.h:337
GLuint res
Definition: glext.h:9613

Referenced by _fclose_nolock(), fflush(), and setvbuf().

◆ _fgetc_nolock()

int CDECL _fgetc_nolock ( FILE file)

Definition at line 3877 of file file.c.

3878{
3879 unsigned char *i;
3880 unsigned int j;
3881
3882 if (file->_cnt>0) {
3883 file->_cnt--;
3884 i = (unsigned char *)file->_ptr++;
3885 j = *i;
3886 } else
3887 j = _filbuf(file);
3888
3889 return j;
3890}
int CDECL _filbuf(FILE *file)
Definition: file.c:3819
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250

◆ _fgetchar()

int CDECL _fgetchar ( void  )

Definition at line 3895 of file file.c.

3896{
3897 return fgetc(stdin);
3898}
int CDECL fgetc(FILE *file)
Definition: file.c:3863
#define stdin

◆ _fgetwc_nolock()

wint_t CDECL _fgetwc_nolock ( FILE file)

Definition at line 3949 of file file.c.

3950{
3951 wint_t ret;
3952 int ch;
3953
3955 || !(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) {
3956 char *p;
3957
3958 for(p=(char*)&ret; (wint_t*)p<&ret+1; p++) {
3960 if(ch == EOF) {
3961 ret = WEOF;
3962 break;
3963 }
3964 *p = (char)ch;
3965 }
3966 }else {
3967 char mbs[MB_LEN_MAX];
3968 int len = 0;
3969
3971 if(ch != EOF) {
3972 mbs[0] = (char)ch;
3973 if(isleadbyte((unsigned char)mbs[0])) {
3975 if(ch != EOF) {
3976 mbs[1] = (char)ch;
3977 len = 2;
3978 }
3979 }else {
3980 len = 1;
3981 }
3982 }
3983
3984 if(!len || mbtowc(&ret, mbs, len)==-1)
3985 ret = WEOF;
3986 }
3987
3988 return ret;
3989}
unsigned char ch[4][2]
Definition: console.c:118
static enum textmode ioinfo_get_textmode(ioinfo *info)
Definition: file.c:211
#define WX_TEXT
Definition: file.c:87
unsigned short wint_t
Definition: corecrt.h:243
#define WEOF
#define MB_LEN_MAX
Definition: limits.h:7
unsigned char
Definition: typeof.h:29
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
#define _fgetc_nolock(_stream)
Definition: stdio.h:1142
#define isleadbyte(_c)
Definition: wchar.h:598
#define mbtowc(wp, cp, len)
Definition: wchar.h:155
char mbs[5]

Referenced by _getws(), fgetwc(), and fgetws().

◆ _fgetwchar()

wint_t CDECL _fgetwchar ( void  )

Definition at line 4027 of file file.c.

4028{
4029 return fgetwc(stdin);
4030}
wint_t CDECL fgetwc(FILE *file)
Definition: file.c:3935

Referenced by fgetwchar(), and getwchar().

◆ _filbuf()

int CDECL _filbuf ( FILE file)

Definition at line 3819 of file file.c.

3820{
3821 unsigned char c;
3822
3823 if(file->_flag & _IOSTRG)
3824 return EOF;
3825
3826 /* Allocate buffer if needed */
3827 if(!(file->_flag & (MSVCRT__NOBUF | _IOMYBUF | MSVCRT__USERBUF)))
3829
3830 if(!(file->_flag & _IOREAD)) {
3831 if(file->_flag & _IORW)
3832 file->_flag |= _IOREAD;
3833 else
3834 return EOF;
3835 }
3836
3837 if(!(file->_flag & (_IOMYBUF | MSVCRT__USERBUF))) {
3838 int r;
3839 if ((r = _read(file->_file,&c,1)) != 1) {
3840 file->_flag |= (r == 0) ? _IOEOF : _IOERR;
3841 return EOF;
3842 }
3843
3844 return c;
3845 } else {
3846 file->_cnt = _read(file->_file, file->_base, file->_bufsiz);
3847 if(file->_cnt<=0) {
3848 file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR;
3849 file->_cnt = 0;
3850 return EOF;
3851 }
3852
3853 file->_cnt--;
3854 file->_ptr = file->_base+1;
3855 c = *(unsigned char *)file->_base;
3856 return c;
3857 }
3858}
int CDECL _read(int fd, void *buf, unsigned int count)
Definition: file.c:3127
static BOOL msvcrt_alloc_buffer(FILE *file)
Definition: file.c:866
#define _IOEOF
Definition: stdio.h:18
#define _IOSTRG
Definition: stdio.h:20
#define MSVCRT__NOBUF
Definition: msvcrt.h:51
#define MSVCRT__USERBUF
Definition: msvcrt.h:336
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

Referenced by _fgetc_nolock(), fgetc(), and test_filbuf().

◆ _filelength()

__msvcrt_long CDECL _filelength ( int  fd)

Definition at line 1887 of file file.c.

1888{
1889 LONG curPos = _lseek(fd, 0, SEEK_CUR);
1890 if (curPos != -1)
1891 {
1892 LONG endPos = _lseek(fd, 0, SEEK_END);
1893 if (endPos != -1)
1894 {
1895 if (endPos != curPos)
1896 _lseek(fd, curPos, SEEK_SET);
1897 return endPos;
1898 }
1899 }
1900 return -1;
1901}
#define SEEK_END
Definition: cabinet.c:29
__msvcrt_long CDECL _lseek(int fd, __msvcrt_long offset, int whence)
Definition: file.c:1479

Referenced by filelength(), File::length(), and test_chsize().

◆ _filelengthi64()

__int64 CDECL _filelengthi64 ( int  fd)

Definition at line 1906 of file file.c.

1907{
1908 __int64 curPos = _lseeki64(fd, 0, SEEK_CUR);
1909 if (curPos != -1)
1910 {
1911 __int64 endPos = _lseeki64(fd, 0, SEEK_END);
1912 if (endPos != -1)
1913 {
1914 if (endPos != curPos)
1915 _lseeki64(fd, curPos, SEEK_SET);
1916 return endPos;
1917 }
1918 }
1919 return -1;
1920}

◆ _fileno()

◆ _flsbuf()

int CDECL _flsbuf ( int  c,
FILE file 
)

Definition at line 4075 of file file.c.

4076{
4077 /* Flush output buffer */
4078 if(!(file->_flag & (MSVCRT__NOBUF | _IOMYBUF | MSVCRT__USERBUF))) {
4080 }
4081
4082 if(!(file->_flag & _IOWRT)) {
4083 if(!(file->_flag & _IORW)) {
4084 file->_flag |= _IOERR;
4085 *_errno() = EBADF;
4086 return EOF;
4087 }
4088 file->_flag |= _IOWRT;
4089 }
4090 if(file->_flag & _IOREAD) {
4091 if(!(file->_flag & _IOEOF)) {
4092 file->_flag |= _IOERR;
4093 return EOF;
4094 }
4095 file->_cnt = 0;
4096 file->_ptr = file->_base;
4097 file->_flag &= ~(_IOREAD | _IOEOF);
4098 }
4099
4100 if(file->_flag & (_IOMYBUF | MSVCRT__USERBUF)) {
4101 int res = 0;
4102
4103 if(file->_cnt <= 0) {
4105 if(res)
4106 return res;
4107 file->_flag |= _IOWRT;
4108 file->_cnt=file->_bufsiz;
4109 }
4110 *file->_ptr++ = c;
4111 file->_cnt--;
4112 return c&0xff;
4113 } else {
4114 unsigned char cc=c;
4115 int len;
4116 /* set _cnt to 0 for unbuffered FILEs */
4117 file->_cnt = 0;
4118 len = _write(file->_file, &cc, 1);
4119 if (len == 1)
4120 return c & 0xff;
4121 file->_flag |= _IOERR;
4122 return EOF;
4123 }
4124}
int CDECL _write(int fd, const void *buf, unsigned int count)
Definition: file.c:3561
uint32_t cc
Definition: isohybrid.c:75

◆ _flushall()

int CDECL _flushall ( void  )

Definition at line 1174 of file file.c.

1175{
1177}

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

◆ _fprintf_l()

int WINAPIV _fprintf_l ( FILE file,
const char format,
_locale_t  locale,
  ... 
)

Definition at line 5575 of file file.c.

5576{
5578 int res;
5581 va_end(valist);
5582 return res;
5583}
Definition: _locale.h:75
int CDECL _vfprintf_l(FILE *file, const char *format, _locale_t locale, va_list valist)
Definition: file.c:5463
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
static va_list valist
Definition: printf.c:46
Definition: format.c:58

◆ _fprintf_p()

int WINAPIV _fprintf_p ( FILE file,
const char format,
  ... 
)

Definition at line 5589 of file file.c.

5590{
5592 int res;
5595 va_end(valist);
5596 return res;
5597}
int CDECL _vfprintf_p_l(FILE *file, const char *format, _locale_t locale, va_list valist)
Definition: file.c:5481

◆ _fprintf_p_l()

int WINAPIV _fprintf_p_l ( FILE file,
const char format,
_locale_t  locale,
  ... 
)

Definition at line 5602 of file file.c.

5603{
5605 int res;
5608 va_end(valist);
5609 return res;
5610}

◆ _fprintf_s_l()

int WINAPIV _fprintf_s_l ( FILE file,
const char format,
_locale_t  locale,
  ... 
)

Definition at line 5615 of file file.c.

5616{
5618 int res;
5621 va_end(valist);
5622 return res;
5623}
int CDECL _vfprintf_s_l(FILE *file, const char *format, _locale_t locale, va_list valist)
Definition: file.c:5331

◆ _fputc_nolock()

int CDECL _fputc_nolock ( int  c,
FILE file 
)

Definition at line 4374 of file file.c.

4375{
4376 int res;
4377
4378 if(file->_cnt>0) {
4379 *file->_ptr++=c;
4380 file->_cnt--;
4381 if (c == '\n')
4382 {
4384 return res ? res : c;
4385 }
4386 else {
4387 return c & 0xff;
4388 }
4389 } else {
4390 res = _flsbuf(c, file);
4391 return res;
4392 }
4393}
#define _flsbuf
Definition: _flswbuf.c:10

◆ _fputchar()

int CDECL _fputchar ( int  c)

Definition at line 4398 of file file.c.

4399{
4400 return fputc(c, stdout);
4401}
int CDECL fputc(int c, FILE *file)
Definition: file.c:4360
#define stdout

◆ _fputwc_nolock()

wint_t CDECL _fputwc_nolock ( wint_t  wc,
FILE file 
)

Definition at line 4217 of file file.c.

4218{
4219 wchar_t mwc=wc;
4220 ioinfo *fdinfo;
4221 wint_t ret;
4222
4223 fdinfo = get_ioinfo_nolock(file->_file);
4224
4225 if((fdinfo->wxflag&WX_TEXT) && ioinfo_get_textmode(fdinfo) == TEXTMODE_ANSI) {
4226 char buf[MB_LEN_MAX];
4227 int char_len;
4228
4229 char_len = wctomb(buf, mwc);
4230 if(char_len!=-1 && _fwrite_nolock(buf, char_len, 1, file)==1)
4231 ret = wc;
4232 else
4233 ret = WEOF;
4234 }else if(_fwrite_nolock(&mwc, sizeof(mwc), 1, file) == 1) {
4235 ret = wc;
4236 }else {
4237 ret = WEOF;
4238 }
4239
4240 return ret;
4241}
size_t CDECL _fwrite_nolock(const void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:4143
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define wctomb
Definition: wctomb.c:31

Referenced by _putws(), fputwc(), fputws(), and puts_clbk_file_w().

◆ _fputwchar()

wint_t CDECL _fputwchar ( wint_t  wc)

Definition at line 4246 of file file.c.

4247{
4248 return fputwc(wc, stdout);
4249}
wint_t CDECL fputwc(wint_t wc, FILE *file)
Definition: file.c:4203

Referenced by fputwchar().

◆ _fread_nolock()

size_t CDECL _fread_nolock ( void ptr,
size_t  size,
size_t  nmemb,
FILE file 
)

Definition at line 4420 of file file.c.

4421{
4422 size_t rcnt=size * nmemb;
4423 size_t read=0;
4424 size_t pread=0;
4425
4426 if(!rcnt)
4427 return 0;
4428
4429 /* first buffered data */
4430 if(file->_cnt>0) {
4431 int pcnt= (rcnt>file->_cnt)? file->_cnt:rcnt;
4432 memcpy(ptr, file->_ptr, pcnt);
4433 file->_cnt -= pcnt;
4434 file->_ptr += pcnt;
4435 read += pcnt ;
4436 rcnt -= pcnt ;
4437 ptr = (char*)ptr + pcnt;
4438 } else if(!(file->_flag & _IOREAD )) {
4439 if(file->_flag & _IORW) {
4440 file->_flag |= _IOREAD;
4441 } else {
4442 return 0;
4443 }
4444 }
4445
4446 if(rcnt>0 && !(file->_flag & (MSVCRT__NOBUF | _IOMYBUF | MSVCRT__USERBUF)))
4448
4449 while(rcnt>0)
4450 {
4451 int i;
4452 if (!file->_cnt && rcnt<file->_bufsiz && (file->_flag & (_IOMYBUF | MSVCRT__USERBUF))) {
4453 i = _read(file->_file, file->_base, file->_bufsiz);
4454 file->_ptr = file->_base;
4455 if (i != -1) {
4456 file->_cnt = i;
4457 if (i > rcnt) i = rcnt;
4458 }
4459 /* If the buffer fill reaches eof but fread wouldn't, clear eof. */
4460 if (i > 0 && i < file->_cnt) {
4461 get_ioinfo_nolock(file->_file)->wxflag &= ~WX_ATEOF;
4462 file->_flag &= ~_IOEOF;
4463 }
4464 if (i > 0) {
4465 memcpy(ptr, file->_ptr, i);
4466 file->_cnt -= i;
4467 file->_ptr += i;
4468 }
4469 } else if (rcnt > INT_MAX) {
4470 i = _read(file->_file, ptr, INT_MAX);
4471 } else if (rcnt < (file->_bufsiz ? file->_bufsiz : MSVCRT_INTERNAL_BUFSIZ)) {
4472 i = _read(file->_file, ptr, rcnt);
4473 } else {
4474 i = _read(file->_file, ptr, rcnt - rcnt % (file->_bufsiz ? file->_bufsiz : MSVCRT_INTERNAL_BUFSIZ));
4475 }
4476 pread += i;
4477 rcnt -= i;
4478 ptr = (char *)ptr+i;
4479 /* expose feof condition in the flags
4480 * MFC tests file->_flag for feof, and doesn't call feof())
4481 */
4482 if (get_ioinfo_nolock(file->_file)->wxflag & WX_ATEOF)
4483 file->_flag |= _IOEOF;
4484 else if (i == -1)
4485 {
4486 file->_flag |= _IOERR;
4487 pread = 0;
4488 rcnt = 0;
4489 }
4490 if (i < 1) break;
4491 }
4492 read+=pread;
4493 return read / size;
4494}
#define read
Definition: acwin.h:96
#define MSVCRT_INTERNAL_BUFSIZ
Definition: file.c:92
#define INT_MAX
Definition: limits.h:26
if(dx< 0)
Definition: linetemp.h:194
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
ssize_t pread(int fd, void *buf, size_t count, off_t offset)

Referenced by fread().

◆ _fseek_nolock()

int CDECL _fseek_nolock ( FILE file,
__msvcrt_long  offset,
int  whence 
)

Definition at line 1618 of file file.c.

1619{
1620 return _fseeki64_nolock( file, offset, whence );
1621}
int CDECL _fseeki64_nolock(FILE *file, __int64 offset, int whence)
Definition: file.c:1585
GLintptr offset
Definition: glext.h:5920

Referenced by rewind().

◆ _fseeki64()

int CDECL _fseeki64 ( FILE file,
__int64  offset,
int  whence 
)

Definition at line 1571 of file file.c.

1572{
1573 int ret;
1574
1576 ret = _fseeki64_nolock(file, offset, whence);
1578
1579 return ret;
1580}
void CDECL _lock_file(FILE *file)
Definition: file.c:1487
void CDECL _unlock_file(FILE *file)
Definition: file.c:1499

Referenced by fseek(), and fsetpos().

◆ _fseeki64_nolock()

int CDECL _fseeki64_nolock ( FILE file,
__int64  offset,
int  whence 
)

Definition at line 1585 of file file.c.

1586{
1587 int ret;
1588
1589 if(whence == SEEK_CUR && file->_flag & _IOREAD ) {
1590 whence = SEEK_SET;
1592 }
1593
1594 /* Flush output if needed */
1596 /* Reset direction of i/o */
1597 if(file->_flag & _IORW) {
1598 file->_flag &= ~(_IOREAD|_IOWRT);
1599 }
1600 /* Clear end of file flag */
1601 file->_flag &= ~_IOEOF;
1602 ret = (_lseeki64(file->_file,offset,whence) == -1)?-1:0;
1603
1604 return ret;
1605}
__int64 CDECL _ftelli64_nolock(FILE *file)
Definition: file.c:4686

Referenced by _fseek_nolock(), and _fseeki64().

◆ _fsopen()

FILE *CDECL _fsopen ( const char path,
const char mode,
int  share 
)

Definition at line 4288 of file file.c.

4289{
4290 wchar_t *pathW = NULL, *modeW = NULL;
4291 FILE *ret;
4292
4293 if (path && !(pathW = wstrdupa_utf8(path))) return NULL;
4294 if (mode && !(modeW = wstrdupa_utf8(mode)))
4295 {
4296 free(pathW);
4297 return NULL;
4298 }
4299
4300 ret = _wfsopen(pathW, modeW, share);
4301
4302 free(pathW);
4303 free(modeW);
4304 return ret;
4305}
FILE *CDECL _wfsopen(const wchar_t *path, const wchar_t *mode, int share)
Definition: file.c:4254

Referenced by fopen(), and test_fopen().

◆ _fstat()

int CDECL _fstat ( int  fd,
struct _stat buf 
)

Definition at line 2017 of file file.c.

2018{ int ret;
2019 struct _stat64 buf64;
2020
2021 ret = _fstat64(fd, &buf64);
2022 if (!ret)
2023 msvcrt_stat64_to_stat(&buf64, buf);
2024 return ret;
2025}
static void msvcrt_stat64_to_stat(const struct _stat64 *buf64, struct _stat *buf)
Definition: file.c:309
#define _fstat64
Definition: stat.h:181
Definition: stat.h:136

◆ _fstat32()

int CDECL _fstat32 ( int  fd,
struct _stat32 buf 
)

Definition at line 2030 of file file.c.

2031{
2032 int ret;
2033 struct _stat64 buf64;
2034
2035 ret = _fstat64(fd, &buf64);
2036 if (!ret)
2038 return ret;
2039}
static void msvcrt_stat64_to_stat32(const struct _stat64 *buf64, struct _stat32 *buf)
Definition: file.c:339

◆ _fstat32i64()

int CDECL _fstat32i64 ( int  fd,
struct _stat32i64 buf 
)

Definition at line 2044 of file file.c.

2045{
2046 int ret;
2047 struct _stat64 buf64;
2048
2049 ret = _fstat64(fd, &buf64);
2050 if (!ret)
2052 return ret;
2053}
static void msvcrt_stat64_to_stat32i64(const struct _stat64 *buf64, struct _stat32i64 *buf)
Definition: file.c:369

◆ _fstat64()

int CDECL _fstat64 ( int  fd,
struct _stat64 buf 
)

Definition at line 1934 of file file.c.

1935{
1937 DWORD dw;
1938 DWORD type;
1939
1940 TRACE(":fd (%d) stat (%p)\n", fd, buf);
1941 if (info->handle == INVALID_HANDLE_VALUE)
1942 {
1944 return -1;
1945 }
1946
1947 if (!buf)
1948 {
1949 WARN(":failed-NULL buf\n");
1952 return -1;
1953 }
1954
1955 memset(buf, 0, sizeof(struct _stat64));
1956 type = GetFileType(info->handle);
1957 if (type == FILE_TYPE_PIPE)
1958 {
1959 buf->st_dev = buf->st_rdev = fd;
1960 buf->st_mode = _S_IFIFO;
1961 buf->st_nlink = 1;
1962 }
1963 else if (type == FILE_TYPE_CHAR)
1964 {
1965 buf->st_dev = buf->st_rdev = fd;
1966 buf->st_mode = _S_IFCHR;
1967 buf->st_nlink = 1;
1968 }
1969 else /* FILE_TYPE_DISK etc. */
1970 {
1971 FILE_BASIC_INFORMATION basic_info;
1975
1976 if ((status = NtQueryInformationFile( info->handle, &io, &basic_info, sizeof(basic_info), FileBasicInformation )) ||
1977 (status = NtQueryInformationFile( info->handle, &io, &std_info, sizeof(std_info), FileStandardInformation )))
1978 {
1979 WARN(":failed-error %lx\n", status);
1982 return -1;
1983 }
1984 buf->st_mode = _S_IFREG | 0444;
1985 if (!(basic_info.FileAttributes & FILE_ATTRIBUTE_READONLY))
1986 buf->st_mode |= 0222;
1987 buf->st_size = std_info.EndOfFile.QuadPart;
1989 buf->st_atime = dw;
1991 buf->st_mtime = buf->st_ctime = dw;
1992 buf->st_nlink = std_info.NumberOfLinks;
1993 TRACE(":dwFileAttributes = %#lx, mode set to %#x\n",
1994 basic_info.FileAttributes, buf->st_mode);
1995 }
1997 return 0;
1998}
LONG NTSTATUS
Definition: precomp.h:26
#define _S_IFCHR
Definition: stat.h:21
#define _S_IFREG
Definition: stat.h:27
#define _S_IFIFO
Definition: stat.h:20
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
@ FileBasicInformation
Definition: from_kernel.h:65
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
BOOLEAN NTAPI RtlTimeToSecondsSince1970(PLARGE_INTEGER Time, PULONG ElapsedSeconds)
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:100
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
#define memset(x, y, z)
Definition: compat.h:39
#define FileStandardInformation
Definition: propsheet.cpp:61
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:944
LARGE_INTEGER LastAccessTime
Definition: nt_native.h:943
Definition: ps.c:97
LONGLONG QuadPart
Definition: typedefs.h:114
#define FILE_TYPE_CHAR
Definition: winbase.h:284
#define FILE_TYPE_PIPE
Definition: winbase.h:285

◆ _fstat64i32()

int CDECL _fstat64i32 ( int  fd,
struct _stat64i32 buf 
)

Definition at line 2058 of file file.c.

2059{
2060 int ret;
2061 struct _stat64 buf64;
2062
2063 ret = _fstat64(fd, &buf64);
2064 if (!ret)
2066 return ret;
2067}
static void msvcrt_stat64_to_stat64i32(const struct _stat64 *buf64, struct _stat64i32 *buf)
Definition: file.c:354

◆ _fstati64()

int CDECL _fstati64 ( int  fd,
struct _stati64 buf 
)

Definition at line 2003 of file file.c.

2004{
2005 int ret;
2006 struct _stat64 buf64;
2007
2008 ret = _fstat64(fd, &buf64);
2009 if (!ret)
2011 return ret;
2012}
static void msvcrt_stat64_to_stati64(const struct _stat64 *buf64, struct _stati64 *buf)
Definition: file.c:324

◆ _ftelli64()

__int64 CDECL _ftelli64 ( FILE file)

Definition at line 4672 of file file.c.

4673{
4674 __int64 ret;
4675
4679
4680 return ret;
4681}

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

◆ _ftelli64_nolock()

__int64 CDECL _ftelli64_nolock ( FILE file)

Definition at line 4686 of file file.c.

4687{
4688 __int64 pos;
4689
4690 pos = _telli64(file->_file);
4691 if(pos == -1)
4692 return -1;
4693 if(file->_flag & (_IOMYBUF | MSVCRT__USERBUF)) {
4694 if(file->_flag & _IOWRT) {
4695 pos += file->_ptr - file->_base;
4696
4697 if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) {
4698 char *p;
4699
4700 for(p=file->_base; p<file->_ptr; p++)
4701 if(*p == '\n')
4702 pos++;
4703 }
4704 } else if(!file->_cnt) { /* nothing to do */
4705 } else if(_lseeki64(file->_file, 0, SEEK_END)==pos) {
4706 int i;
4707
4708 pos -= file->_cnt;
4709 if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) {
4710 for(i=0; i<file->_cnt; i++)
4711 if(file->_ptr[i] == '\n')
4712 pos--;
4713 }
4714 } else {
4715 char *p;
4716
4717 if(_lseeki64(file->_file, pos, SEEK_SET) != pos)
4718 return -1;
4719
4720 pos -= file->_bufsiz;
4721 pos += file->_ptr - file->_base;
4722
4723 if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) {
4724 if(get_ioinfo_nolock(file->_file)->wxflag & WX_READNL)
4725 pos--;
4726
4727 for(p=file->_base; p<file->_ptr; p++)
4728 if(*p == '\n')
4729 pos++;
4730 }
4731 }
4732 }
4733
4734 return pos;
4735}
#define WX_READNL
Definition: file.c:82
__int64 CDECL _telli64(int fd)
Definition: file.c:3433

Referenced by _fseeki64_nolock(), and _ftelli64().

◆ _futime32()

int CDECL _futime32 ( int  fd,
struct __utimbuf32 t 
)

Definition at line 2101 of file file.c.

2102{
2103 if (t)
2104 {
2105 struct __utimbuf64 t64;
2106 t64.actime = t->actime;
2107 t64.modtime = t->modtime;
2108 return _futime64( fd, &t64 );
2109 }
2110 else
2111 return _futime64( fd, NULL );
2112}
int CDECL _futime64(int fd, struct __utimbuf64 *t)
Definition: file.c:2072
GLdouble GLdouble t
Definition: gl.h:2047
__time64_t actime
Definition: utime.h:41

◆ _futime64()

int CDECL _futime64 ( int  fd,
struct __utimbuf64 t 
)

Definition at line 2072 of file file.c.

2073{
2075 FILETIME at, wt;
2076
2077 if (!t)
2078 {
2079 time_to_filetime( _time64(NULL), &at );
2080 wt = at;
2081 }
2082 else
2083 {
2084 time_to_filetime( t->actime, &at );
2085 time_to_filetime( t->modtime, &wt );
2086 }
2087
2088 if (!SetFileTime(info->handle, NULL, &at, &wt))
2089 {
2092 return -1 ;
2093 }
2095 return 0;
2096}
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:948
static void time_to_filetime(__time64_t time, FILETIME *ft)
Definition: file.c:384
_ACRTIMP __time64_t __cdecl _time64(__time64_t *)
Definition: time.c:780

Referenced by _futime32(), _utime64(), and _wutime64().

◆ _fwprintf_l()

int WINAPIV _fwprintf_l ( FILE file,
const wchar_t format,
_locale_t  locale,
  ... 
)

Definition at line 5654 of file file.c.

5655{
5657 int res;
5660 va_end(valist);
5661 return res;
5662}
int CDECL _vfwprintf_l(FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
Definition: file.c:5472

◆ _fwprintf_p()

int WINAPIV _fwprintf_p ( FILE file,
const wchar_t format,
  ... 
)

Definition at line 5667 of file file.c.

5668{
5670 int res;
5673 va_end(valist);
5674 return res;
5675}
int CDECL _vfwprintf_p_l(FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
Definition: file.c:5499

◆ _fwprintf_p_l()

int WINAPIV _fwprintf_p_l ( FILE file,
const wchar_t format,
_locale_t  locale,
  ... 
)

Definition at line 5680 of file file.c.

5681{
5683 int res;
5686 va_end(valist);
5687 return res;
5688}

◆ _fwprintf_s_l()

int WINAPIV _fwprintf_s_l ( FILE file,
const wchar_t format,
_locale_t  locale,
  ... 
)

Definition at line 5693 of file file.c.

5694{
5696 int res;
5699 va_end(valist);
5700 return res;
5701}
int CDECL _vfwprintf_s_l(FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
Definition: file.c:5340

◆ _fwrite_nolock()

size_t CDECL _fwrite_nolock ( const void ptr,
size_t  size,
size_t  nmemb,
FILE file 
)

Definition at line 4143 of file file.c.

4144{
4145 size_t wrcnt=size * nmemb;
4146 int written = 0;
4147 if (size == 0)
4148 return 0;
4149
4150 while(wrcnt) {
4151 if(file->_cnt < 0) {
4152 WARN("negative file->_cnt value in %p\n", file);
4153 file->_flag |= _IOERR;
4154 break;
4155 } else if(file->_cnt) {
4156 int pcnt=(file->_cnt>wrcnt)? wrcnt: file->_cnt;
4157 memcpy(file->_ptr, ptr, pcnt);
4158 file->_cnt -= pcnt;
4159 file->_ptr += pcnt;
4160 written += pcnt;
4161 wrcnt -= pcnt;
4162 ptr = (const char*)ptr + pcnt;
4163 } else if((file->_flag & MSVCRT__NOBUF)
4164 || ((file->_flag & (_IOMYBUF | MSVCRT__USERBUF)) && wrcnt >= file->_bufsiz)
4165 || (!(file->_flag & (_IOMYBUF | MSVCRT__USERBUF)) && wrcnt >= MSVCRT_INTERNAL_BUFSIZ)) {
4166 size_t pcnt;
4167 int bufsiz;
4168
4169 if(file->_flag & MSVCRT__NOBUF)
4170 bufsiz = 1;
4171 else if(!(file->_flag & (_IOMYBUF | MSVCRT__USERBUF)))
4172 bufsiz = MSVCRT_INTERNAL_BUFSIZ;
4173 else
4174 bufsiz = file->_bufsiz;
4175
4176 pcnt = (wrcnt / bufsiz) * bufsiz;
4177
4179 break;
4180
4181 if(_write(file->_file, ptr, pcnt) <= 0) {
4182 file->_flag |= _IOERR;
4183 break;
4184 }
4185 written += pcnt;
4186 wrcnt -= pcnt;
4187 ptr = (const char*)ptr + pcnt;
4188 } else {
4189 if(_flsbuf(*(const char*)ptr, file) == EOF)
4190 break;
4191 written++;
4192 wrcnt--;
4193 ptr = (const char*)ptr + 1;
4194 }
4195 }
4196
4197 return written / size;
4198}

Referenced by _fputwc_nolock(), fputs(), fputws(), fwrite(), puts(), and puts_clbk_file_w().

◆ _get_osfhandle()

◆ _getmaxstdio()

int CDECL _getmaxstdio ( void  )

Definition at line 5862 of file file.c.

5863{
5864 return MSVCRT_max_streams;
5865}
static int MSVCRT_max_streams
Definition: file.c:279

◆ _getw()

int CDECL _getw ( FILE file)

Definition at line 3994 of file file.c.

3995{
3996 char *ch;
3997 int i, k;
3998 unsigned int j;
3999 ch = (char *)&i;
4000
4002 for (j=0; j<sizeof(int); j++) {
4003 k = _fgetc_nolock(file);
4004 if (k == EOF) {
4005 file->_flag |= _IOEOF;
4007 return EOF;
4008 }
4009 ch[j] = k;
4010 }
4011
4013 return i;
4014}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
int k
Definition: mpi.c:3369

Referenced by test_readmode().

◆ _getws()

wchar_t *CDECL _getws ( wchar_t buf)

Definition at line 4879 of file file.c.

4880{
4881 wint_t cc;
4882 wchar_t* ws = buf;
4883
4885 for (cc = _fgetwc_nolock(stdin); cc != WEOF && cc != '\n';
4887 {
4888 if (cc != '\r')
4889 *buf++ = (wchar_t)cc;
4890 }
4892
4893 if ((cc == WEOF) && (ws == buf))
4894 {
4895 TRACE(":nothing read\n");
4896 return NULL;
4897 }
4898 *buf = '\0';
4899
4900 TRACE("got %s\n", debugstr_w(ws));
4901 return ws;
4902}
wint_t CDECL _fgetwc_nolock(FILE *file)
Definition: file.c:3949
#define debugstr_w
Definition: kernel32.h:32
#define wchar_t
Definition: wchar.h:102
const char * ws
Definition: skip_ws.cpp:7

◆ _isatty()

int CDECL _isatty ( int  fd)

◆ _lock_file()

◆ _locking()

int CDECL _locking ( int  fd,
int  mode,
__msvcrt_long  nbytes 
)

Definition at line 1513 of file file.c.

1514{
1516 BOOL ret;
1517 DWORD cur_locn;
1518
1519 TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1520 if (info->handle == INVALID_HANDLE_VALUE)
1521 {
1523 return -1;
1524 }
1525
1526 if (mode < 0 || mode > 4)
1527 {
1529 *_errno() = EINVAL;
1530 return -1;
1531 }
1532
1533 TRACE(":fd (%d) by %#lx mode %s\n",
1534 fd, nbytes, (mode == _LK_UNLCK) ? "_LK_UNLCK" :
1535 (mode == _LK_LOCK) ? "_LK_LOCK" :
1536 (mode == _LK_NBLCK) ? "_LK_NBLCK" :
1537 (mode == _LK_RLCK) ? "_LK_RLCK" :
1538 (mode == _LK_NBRLCK) ? "_LK_NBRLCK" :
1539 "UNKNOWN");
1540
1541 if ((cur_locn = SetFilePointer(info->handle, 0L, NULL, FILE_CURRENT)) == INVALID_SET_FILE_POINTER)
1542 {
1544 FIXME("Seek failed\n");
1545 *_errno() = EINVAL; /* FIXME */
1546 return -1;
1547 }
1548 if (mode == _LK_LOCK || mode == _LK_RLCK)
1549 {
1550 int nretry = 10;
1551 ret = 1; /* just to satisfy gcc */
1552 while (nretry--)
1553 {
1554 ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L);
1555 if (ret) break;
1556 Sleep(1);
1557 }
1558 }
1559 else if (mode == _LK_UNLCK)
1560 ret = UnlockFile(info->handle, cur_locn, 0L, nbytes, 0L);
1561 else
1562 ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L);
1563 /* FIXME - what about error settings? */
1565 return ret ? 0 : -1;
1566}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
BOOL WINAPI LockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh)
Definition: lock.c:25
BOOL WINAPI DECLSPEC_HOTPATCH UnlockFile(HANDLE file, DWORD offset_low, DWORD offset_high, DWORD count_low, DWORD count_high)
Definition: file.c:3863
#define _LK_LOCK
Definition: locking.h:27
#define _LK_UNLCK
Definition: locking.h:26
#define _LK_RLCK
Definition: locking.h:29
#define _LK_NBRLCK
Definition: locking.h:30
#define _LK_NBLCK
Definition: locking.h:28
#define L(x)
Definition: resources.c:13
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790

Referenced by locking().

◆ _lseek()

__msvcrt_long CDECL _lseek ( int  fd,
__msvcrt_long  offset,
int  whence 
)

Definition at line 1479 of file file.c.

1480{
1481 return _lseeki64(fd, offset, whence);
1482}

Referenced by _filelength(), _tell(), _write(), lseek(), rd_lseek_file(), rw(), test__creat(), test_chsize(), test_fflush(), test_file_write_read(), and test_lseek().

◆ _lseeki64()

__int64 CDECL _lseeki64 ( int  fd,
__int64  offset,
int  whence 
)

Definition at line 1432 of file file.c.

1433{
1435 LARGE_INTEGER ofs;
1436
1437 TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
1438
1439 if (info->handle == INVALID_HANDLE_VALUE)
1440 {
1441 *_errno() = EBADF;
1443 return -1;
1444 }
1445
1446 if (whence < 0 || whence > 2)
1447 {
1449 *_errno() = EINVAL;
1450 return -1;
1451 }
1452
1453 TRACE(":fd (%d) to %#I64x pos %s\n",
1454 fd, offset, (whence == SEEK_SET) ? "SEEK_SET" :
1455 (whence == SEEK_CUR) ? "SEEK_CUR" :
1456 (whence == SEEK_END) ? "SEEK_END" : "UNKNOWN");
1457
1458 /* The MoleBox protection scheme expects msvcrt to use SetFilePointer only,
1459 * so a LARGE_INTEGER offset cannot be passed directly via SetFilePointerEx. */
1460 ofs.QuadPart = offset;
1461 if ((ofs.u.LowPart = SetFilePointer(info->handle, ofs.u.LowPart, &ofs.u.HighPart, whence)) != INVALID_SET_FILE_POINTER ||
1463 {
1464 info->wxflag &= ~WX_ATEOF;
1465 /* FIXME: What if we seek _to_ EOF - is EOF set? */
1466
1468 return ofs.QuadPart;
1469 }
1471 TRACE(":error-last error (%ld)\n", GetLastError());
1473 return -1;
1474}
#define ERROR_SUCCESS
Definition: deptool.c:10
struct _LARGE_INTEGER::@2493 u

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

◆ _mktemp()

char *CDECL _mktemp ( char pattern)

Definition at line 2176 of file file.c.

2177{
2178 wchar_t *pathW, *p;
2179 int numX = 0;
2180 char *retVal = pattern;
2181 int id;
2182 char letter = 'a';
2183
2184 if(!pattern)
2185 return NULL;
2186
2187 while(*pattern)
2188 numX = (*pattern++ == 'X')? numX + 1 : 0;
2189 if (numX < 6)
2190 return NULL;
2191 pattern--;
2192 id = GetCurrentProcessId();
2193 numX = 6;
2194 while(numX--)
2195 {
2196 int tempNum = id / 10;
2197 *pattern-- = id - (tempNum * 10) + '0';
2198 id = tempNum;
2199 }
2200 pattern++;
2201 if (!(pathW = wstrdupa_utf8(retVal)))
2202 return NULL;
2203 p = pathW + wcslen(pathW) - 6;
2204 do
2205 {
2206 *p = letter++;
2208 {
2209 *pattern = *p;
2210 free(pathW);
2211 return retVal;
2212 }
2213 } while(letter <= 'z');
2214 free(pathW);
2215 return NULL;
2216}
DWORD WINAPI DECLSPEC_HOTPATCH GetFileAttributesW(LPCWSTR name)
Definition: file.c:1671
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
GLubyte * pattern
Definition: glext.h:7787
GLuint id
Definition: glext.h:5910
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158

Referenced by mktemp(), test_mktemp(), and test_utf8().

◆ _mktemp_s()

int CDECL _mktemp_s ( char pattern,
size_t  size 
)

Definition at line 2130 of file file.c.

2131{
2132 DWORD len, wlen, xno, id;
2133 wchar_t *pathW;
2134
2136 return EINVAL;
2137
2138 for(len=0; len<size; len++)
2139 if(!pattern[len])
2140 break;
2141 if(!MSVCRT_CHECK_PMT(len!=size && len>=6)) {
2142 if(size)
2143 pattern[0] = 0;
2144 return EINVAL;
2145 }
2146
2147 for(xno=1; xno<=6; xno++)
2148 if(!MSVCRT_CHECK_PMT(pattern[len-xno] == 'X'))
2149 return EINVAL;
2150
2151 id = GetCurrentProcessId();
2152 for(xno=1; xno<6; xno++) {
2153 pattern[len-xno] = id%10 + '0';
2154 id /= 10;
2155 }
2156
2157 if(!(pathW = wstrdupa_utf8(pattern))) return *_errno();
2158 wlen = wcslen(pathW);
2159 for(pathW[wlen-6]='a'; pathW[wlen-6]<='z'; pathW[wlen-6]++) {
2161 pattern[len-6] = pathW[wlen-6];
2162 free(pathW);
2163 return 0;
2164 }
2165 }
2166 free(pathW);
2167
2168 pattern[0] = 0;
2169 *_errno() = EEXIST;
2170 return EEXIST;
2171}
#define EEXIST
Definition: errno.h:39

Referenced by test_utf8().

◆ _open()

int WINAPIV _open ( const char path,
int  flags,
  ... 
)

Definition at line 2655 of file file.c.

2656{
2657 va_list ap;
2658
2659 if (flags & _O_CREAT)
2660 {
2661 int pmode;
2662 va_start(ap, flags);
2663 pmode = va_arg(ap, int);
2664 va_end(ap);
2665 return _sopen( path, flags, _SH_DENYNO, pmode );
2666 }
2667 else
2668 return _sopen( path, flags, _SH_DENYNO);
2669}
int WINAPIV _sopen(const char *path, int oflags, int shflags,...)
Definition: file.c:2633
#define _SH_DENYNO
Definition: share.h:40
#define va_arg(v, l)
Definition: stdarg.h:27
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by _creat(), _utime64(), compat_open(), install_from_unix_file(), main(), rd_open_file(), rw(), test__popen(), test__sopen_s(), test_chsize(), test_file_write_read(), test_get_osfhandle(), test_ioinfo_flags(), test_setmode(), and tmpfile().

◆ _open_osfhandle()

int CDECL _open_osfhandle ( intptr_t  handle,
int  oflags 
)

Definition at line 2711 of file file.c.

2712{
2713 DWORD flags;
2714 int fd;
2715
2716 /* _O_RDONLY (0) always matches, so set the read flag
2717 * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
2718 * file, so set the write flag. It also only sets _O_TEXT if it wants
2719 * text - it never sets _O_BINARY.
2720 */
2721 /* don't let split_oflags() decide the mode if no mode is passed */
2722 if (!(oflags & (_O_BINARY | _O_TEXT)))
2723 oflags |= _O_BINARY;
2724
2727 {
2729 return -1;
2730 }
2731
2732 if (flags == FILE_TYPE_CHAR)
2733 flags = WX_TTY;
2734 else if (flags == FILE_TYPE_PIPE)
2735 flags = WX_PIPE;
2736 else
2737 flags = 0;
2738 flags |= split_oflags(oflags);
2739
2741 TRACE(":handle (%Iu) fd (%d) flags %#lx\n", handle, fd, flags);
2742 return fd;
2743}
#define NO_ERROR
Definition: dderror.h:5
#define _O_BINARY
Definition: cabinet.h:51
#define _O_TEXT
Definition: cabinet.h:50
static unsigned split_oflags(unsigned oflags)
Definition: file.c:2293
static int msvcrt_alloc_fd(HANDLE hand, int flag)
Definition: file.c:598
#define WX_PIPE
Definition: file.c:83
#define FILE_TYPE_UNKNOWN
Definition: winbase.h:282

Referenced by _tWinMain(), ConStreamSetOSHandle(), run_open_osfhandle(), test__open_osfhandle(), and test_close().

◆ _pipe()

int CDECL _pipe ( int pfds,
unsigned int  psize,
int  textmode 
)

Definition at line 2323 of file file.c.

2324{
2325 int ret = -1;
2327 HANDLE readHandle, writeHandle;
2328
2329 if (!pfds)
2330 {
2331 *_errno() = EINVAL;
2332 return -1;
2333 }
2334
2335 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
2336 sa.bInheritHandle = !(textmode & _O_NOINHERIT);
2337 sa.lpSecurityDescriptor = NULL;
2338 if (CreatePipe(&readHandle, &writeHandle, &sa, psize))
2339 {
2340 unsigned int wxflags = split_oflags(textmode);
2341 int fd;
2342
2343 fd = msvcrt_alloc_fd(readHandle, wxflags|WX_PIPE);
2344 if (fd != -1)
2345 {
2346 pfds[0] = fd;
2347 fd = msvcrt_alloc_fd(writeHandle, wxflags|WX_PIPE);
2348 if (fd != -1)
2349 {
2350 pfds[1] = fd;
2351 ret = 0;
2352 }
2353 else
2354 {
2355 _close(pfds[0]);
2356 CloseHandle(writeHandle);
2357 *_errno() = EMFILE;
2358 }
2359 }
2360 else
2361 {
2362 CloseHandle(readHandle);
2363 CloseHandle(writeHandle);
2364 *_errno() = EMFILE;
2365 }
2366 }
2367 else
2369
2370 return ret;
2371}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define _O_NOINHERIT
Definition: cabinet.h:45
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
textmode
Definition: file.c:95
#define EMFILE
Definition: errno.h:46
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569

Referenced by _wpopen(), common_popen(), fork_helper(), test_file_inherit(), test_pipes(), and test_stat().

◆ _putw()

int CDECL _putw ( int  val,
FILE file 
)

Definition at line 3738 of file file.c.

3739{
3740 int len;
3741
3743 len = _write(file->_file, &val, sizeof(val));
3744 if (len == sizeof(val)) {
3746 return val;
3747 }
3748
3749 file->_flag |= _IOERR;
3751 return EOF;
3752}
GLuint GLfloat * val
Definition: glext.h:7180

◆ _putws()

int CDECL _putws ( const wchar_t s)

Definition at line 4942 of file file.c.

4943{
4944 int ret;
4945
4947 ret = fputws(s, stdout);
4948 if(ret >= 0)
4949 ret = _fputwc_nolock('\n', stdout);
4951 return ret >= 0 ? 0 : WEOF;
4952}
wint_t CDECL _fputwc_nolock(wint_t wc, FILE *file)
Definition: file.c:4217
int CDECL fputws(const wchar_t *s, FILE *file)
Definition: file.c:4783
GLdouble s
Definition: gl.h:2039

Referenced by Wait().

◆ _read()

int CDECL _read ( int  fd,
void buf,
unsigned int  count 
)

Definition at line 3127 of file file.c.

3128{
3129 ioinfo *info;
3130 int num_read;
3131
3132 if(fd == MSVCRT_NO_CONSOLE_FD) {
3133 *_errno() = EBADF;
3134 return -1;
3135 }
3136
3137 info = get_ioinfo(fd);
3138 num_read = read_i(fd, info, buf, count);
3140 return num_read;
3141}
static int read_i(int fd, ioinfo *fdinfo, void *buf, unsigned int count)
Definition: file.c:2964
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by _filbuf(), _fread_nolock(), common_refill_and_read_nolock(), fread(), rd_read_file(), read(), read_pipe_thread(), rw(), test__creat(), and test_file_write_read().

◆ _rmtmp()

int CDECL _rmtmp ( void  )

Definition at line 2748 of file file.c.

2749{
2750 int num_removed = 0, i;
2751 FILE *file;
2752
2753 LOCK_FILES();
2754 for (i = 3; i < MSVCRT_stream_idx; i++) {
2756
2757 if (file->_tmpfname)
2758 {
2759 fclose(file);
2760 num_removed++;
2761 }
2762 }
2763 UNLOCK_FILES();
2764
2765 if (num_removed)
2766 TRACE(":removed (%d) temp files\n",num_removed);
2767 return num_removed;
2768}

◆ _setmaxstdio()

int CDECL _setmaxstdio ( int  newmax)

Definition at line 5870 of file file.c.

5871{
5872 TRACE("%d\n", newmax);
5873
5874 if(newmax<_IOB_ENTRIES || newmax>MSVCRT_MAX_FILES || newmax<MSVCRT_stream_idx)
5875 return -1;
5876
5877 MSVCRT_max_streams = newmax;
5878 return MSVCRT_max_streams;
5879}
#define MSVCRT_MAX_FILES
Definition: file.c:125

◆ _setmode()

int CDECL _setmode ( int  fd,
int  mode 
)

Definition at line 3146 of file file.c.

3147{
3149 int ret = info->wxflag & WX_TEXT ? _O_TEXT : _O_BINARY;
3150
3152 ret = _O_WTEXT;
3153
3155 && mode!=_O_U16TEXT && mode!=_O_U8TEXT) {
3156 *_errno() = EINVAL;
3158 return -1;
3159 }
3160
3161 if(info == &MSVCRT___badioinfo) {
3162 *_errno() = EBADF;
3163 return EOF;
3164 }
3165
3166 if(mode == _O_BINARY) {
3167 info->wxflag &= ~WX_TEXT;
3170 return ret;
3171 }
3172
3173 info->wxflag |= WX_TEXT;
3174 if(mode == _O_TEXT)
3176 else if(mode == _O_U8TEXT)
3178 else
3180
3182 return ret;
3183}
static void ioinfo_set_textmode(ioinfo *info, enum textmode mode)
Definition: file.c:220
#define _O_WTEXT
Definition: fcntl.h:30
#define _O_U8TEXT
Definition: fcntl.h:32
#define _O_U16TEXT
Definition: fcntl.h:31

◆ _sopen()

int WINAPIV _sopen ( const char path,
int  oflags,
int  shflags,
  ... 
)

Definition at line 2633 of file file.c.

2634{
2635 int pmode;
2636 int fd;
2637
2638 if (oflags & _O_CREAT)
2639 {
2640 va_list ap;
2641
2642 va_start(ap, shflags);
2643 pmode = va_arg(ap, int);
2644 va_end(ap);
2645 }
2646 else
2647 pmode = 0;
2648
2649 return _sopen_dispatch(path, oflags, shflags, pmode, &fd, 0) ? -1 : fd;
2650}
int CDECL _sopen_dispatch(const char *path, int oflags, int shflags, int pmode, int *fd, int secure)
Definition: file.c:2606

Referenced by _open(), and test_get_osfhandle().

◆ _sopen_dispatch()

int CDECL _sopen_dispatch ( const char path,
int  oflags,
int  shflags,
int  pmode,
int fd,
int  secure 
)

Definition at line 2606 of file file.c.

2608{
2609 wchar_t *pathW = NULL;
2610 int ret;
2611
2612 if (!MSVCRT_CHECK_PMT(fd != NULL))
2613 return EINVAL;
2614 *fd = -1;
2615 if (path && !(pathW = wstrdupa_utf8(path))) return *_errno();
2616
2617 ret = _wsopen_dispatch(pathW, oflags, shflags, pmode, fd, secure);
2618 free(pathW);
2619 return ret;
2620}
int CDECL _wsopen_dispatch(const wchar_t *path, int oflags, int shflags, int pmode, int *fd, int secure)
Definition: file.c:2397
static int secure
Definition: server.c:157

Referenced by _sopen(), _sopen_s(), and test__sopen_dispatch().

◆ _sopen_s()

int CDECL _sopen_s ( int fd,
const char path,
int  oflags,
int  shflags,
int  pmode 
)

Definition at line 2625 of file file.c.

2626{
2627 return _sopen_dispatch(path, oflags, shflags, pmode, fd, 1);
2628}

Referenced by _sopen(), _Success_(), and test__sopen_s().

◆ _stat()

int CDECL _stat ( const char path,
struct _stat buf 
)

Definition at line 3216 of file file.c.

3217{
3218 int ret;
3219 struct _stat64 buf64;
3220
3221 ret = _stat64( path, &buf64);
3222 if (!ret)
3223 msvcrt_stat64_to_stat(&buf64, buf);
3224 return ret;
3225}
#define _stat64
Definition: stat.h:182

◆ _stat64()

int CDECL _stat64 ( const char path,
struct _stat64 buf 
)

Definition at line 3188 of file file.c.

3189{
3190 wchar_t *pathW = NULL;
3191 int ret;
3192
3193 if (path && !(pathW = wstrdupa_utf8(path))) return -1;
3194 ret = _wstat64(pathW, buf);
3195 free(pathW);
3196 return ret;
3197}
#define _wstat64
Definition: stat.h:185

◆ _stati64()

int CDECL _stati64 ( const char path,
struct _stati64 buf 
)

Definition at line 3202 of file file.c.

3203{
3204 int ret;
3205 struct _stat64 buf64;
3206
3207 ret = _stat64(path, &buf64);
3208 if (!ret)
3210 return ret;
3211}

◆ _tell()

__msvcrt_long CDECL _tell ( int  fd)

Definition at line 3425 of file file.c.

3426{
3427 return _lseek(fd, 0, SEEK_CUR);
3428}

Referenced by tell(), and test__creat().

◆ _telli64()

__int64 CDECL _telli64 ( int  fd)

Definition at line 3433 of file file.c.

3434{
3435 return _lseeki64(fd, 0, SEEK_CUR);
3436}

Referenced by _ftelli64(), _ftelli64_nolock(), and test_std_stream_buffering().

◆ _tempnam()

char *CDECL _tempnam ( const char dir,
const char prefix 
)

Definition at line 3441 of file file.c.

3442{
3443 wchar_t *dirW = NULL, *prefixW = NULL, *retW;
3444 char *ret;
3445
3446 if (dir && !(dirW = wstrdupa_utf8(dir))) return NULL;
3447 if (prefix && !(prefixW = wstrdupa_utf8(prefix)))
3448 {
3449 free(dirW);
3450 return NULL;
3451 }
3452 retW = _wtempnam(dirW, prefixW);
3453 free(dirW);
3454 free(prefixW);
3455 /* TODO: don't do the conversion */
3456 ret = astrdupw_utf8(retW);
3457 free(retW);
3458 return ret;
3459}
unsigned int dir
Definition: maze.c:112
wchar_t *CDECL _wtempnam(const wchar_t *dir, const wchar_t *prefix)
Definition: file.c:3464
static char * astrdupw_utf8(const wchar_t *wstr)
Definition: msvcrt.h:452
Character const *const prefix
Definition: tempnam.cpp:195

Referenced by test__popen(), test__sopen_dispatch(), test__sopen_s(), test_chsize(), test_ctrlz(), test_fflush(), test_fgetc(), test_fgetwc(), test_file_put_get(), test_file_write_read(), test_flsbuf(), test_fputc(), test_iobuf_layout(), test_ioinfo_flags(), test_utf8(), test_write_flush(), and tmpfile().

◆ _umask()

int CDECL _umask ( int  umask)

Definition at line 3486 of file file.c.

3487{
3488 int old_umask = MSVCRT_umask;
3489 TRACE("(%d)\n",umask);
3491 return old_umask;
3492}
static int MSVCRT_umask
Definition: file.c:282
static int umask(int fd)
Definition: io.h:31

Referenced by umask().

◆ _ungetc_nolock()

int CDECL _ungetc_nolock ( int  c,
FILE file 
)

Definition at line 5748 of file file.c.

5749{
5750 if(!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
5751
5752 if (c == EOF || !(file->_flag&_IOREAD ||
5753 (file->_flag&_IORW && !(file->_flag&_IOWRT))))
5754 return EOF;
5755
5756 if((!(file->_flag & (MSVCRT__NOBUF | _IOMYBUF | MSVCRT__USERBUF))
5758 || (!file->_cnt && file->_ptr==file->_base))
5759 file->_ptr++;
5760
5761 if(file->_ptr>file->_base) {
5762 file->_ptr--;
5763 if(file->_flag & _IOSTRG) {
5764 if(*file->_ptr != c) {
5765 file->_ptr++;
5766 return EOF;
5767 }
5768 }else {
5769 *file->_ptr = c;
5770 }
5771 file->_cnt++;
5772 file->_flag &= ~(_IOERR | _IOEOF);
5773 file->_flag |= _IOREAD;
5774 return c;
5775 }
5776
5777 return EOF;
5778}

Referenced by _ungetwc_nolock(), and ungetc().

◆ _ungetwc_nolock()

wint_t CDECL _ungetwc_nolock ( wint_t  wc,
FILE file 
)

Definition at line 5799 of file file.c.

5800{
5801 wchar_t mwc = wc;
5802
5803 if(!MSVCRT_CHECK_PMT(file != NULL)) return WEOF;
5804 if (wc == WEOF)
5805 return WEOF;
5806
5808 || !(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) {
5809 unsigned char * pp = (unsigned char *)&mwc;
5810 int i;
5811
5812 for(i=sizeof(wchar_t)-1;i>=0;i--) {
5813 if(pp[i] != _ungetc_nolock(pp[i],file))
5814 return WEOF;
5815 }
5816 }else {
5817 char mbs[MB_LEN_MAX];
5818 int len;
5819
5820 len = wctomb(mbs, mwc);
5821 if(len == -1)
5822 return WEOF;
5823
5824 for(len--; len>=0; len--) {
5825 if(mbs[len] != _ungetc_nolock(mbs[len], file))
5826 return WEOF;
5827 }
5828 }
5829
5830 return mwc;
5831}
int CDECL _ungetc_nolock(int c, FILE *file)
Definition: file.c:5748

Referenced by ungetwc().

◆ _unlink()

int CDECL _unlink ( const char path)

Definition at line 1085 of file file.c.

1086{
1087 wchar_t *pathW = NULL;
1088 int ret;
1089
1090 if (path && !(pathW = wstrdupa_utf8(path))) return -1;
1091 ret = _wunlink(pathW);
1092 free(pathW);
1093 return ret;
1094}
int CDECL _wunlink(const wchar_t *path)
Definition: file.c:1099

Referenced by remove(), test___getmainargs(), test___getmainargs_parent(), test__popen(), test__wfopen_s(), test_chsize(), test_fopen_fclose_fcloseall(), test_fopen_s(), test_fputwc(), test_get_osfhandle(), test_setmode(), test_unlink(), and unlink().

◆ _unlock_file()

◆ _utime32()

int CDECL _utime32 ( const char path,
struct __utimbuf32 t 
)

Definition at line 3513 of file file.c.

3514{
3515 if (t)
3516 {
3517 struct __utimbuf64 t64;
3518 t64.actime = t->actime;
3519 t64.modtime = t->modtime;
3520 return _utime64( path, &t64 );
3521 }
3522 else
3523 return _utime64( path, NULL );
3524}
int CDECL _utime64(const char *path, struct __utimbuf64 *t)
Definition: file.c:3497

◆ _utime64()

int CDECL _utime64 ( const char path,
struct __utimbuf64 t 
)

Definition at line 3497 of file file.c.

3498{
3499 int fd = _open(path, _O_WRONLY | _O_BINARY);
3500
3501 if (fd > 0)
3502 {
3503 int retVal = _futime64(fd, t);
3504 _close(fd);
3505 return retVal;
3506 }
3507 return -1;
3508}
#define _O_WRONLY
Definition: cabinet.h:38

Referenced by _utime32().

◆ _vfprintf_l()

int CDECL _vfprintf_l ( FILE file,
const char format,
_locale_t  locale,
va_list  valist 
)

Definition at line 5463 of file file.c.

5465{
5466 return vfprintf_helper(0, file, format, locale, valist);
5467}
static int vfprintf_helper(DWORD options, FILE *file, const char *format, _locale_t locale, va_list valist)
Definition: file.c:5264

Referenced by _fprintf_l().

◆ _vfprintf_p()

int CDECL _vfprintf_p ( FILE file,
const char format,
va_list  valist 
)

Definition at line 5491 of file file.c.

5492{
5493 return _vfprintf_p_l(file, format, NULL, valist);
5494}

◆ _vfprintf_p_l()

int CDECL _vfprintf_p_l ( FILE file,
const char format,
_locale_t  locale,
va_list  valist 
)

Definition at line 5481 of file file.c.

5483{
5486}
#define MSVCRT_PRINTF_POSITIONAL_PARAMS
Definition: msvcrt.h:409
#define MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
Definition: msvcrt.h:410

Referenced by _fprintf_p(), _fprintf_p_l(), and _vfprintf_p().

◆ _vfprintf_s_l()

int CDECL _vfprintf_s_l ( FILE file,
const char format,
_locale_t  locale,
va_list  valist 
)

Definition at line 5331 of file file.c.

Referenced by _fprintf_s_l(), and vfprintf_s().

◆ _vfwprintf_l()

int CDECL _vfwprintf_l ( FILE file,
const wchar_t format,
_locale_t  locale,
va_list  valist 
)

Definition at line 5472 of file file.c.

5474{
5476}
static int vfwprintf_helper(DWORD options, FILE *file, const wchar_t *format, _locale_t locale, va_list valist)
Definition: file.c:5296

Referenced by _fwprintf_l().

◆ _vfwprintf_p()

int CDECL _vfwprintf_p ( FILE file,
const wchar_t format,
va_list  valist 
)

Definition at line 5509 of file file.c.

5510{
5512}

◆ _vfwprintf_p_l()

int CDECL _vfwprintf_p_l ( FILE file,
const wchar_t format,
_locale_t  locale,
va_list  valist 
)

◆ _vfwprintf_s_l()

int CDECL _vfwprintf_s_l ( FILE file,
const wchar_t format,
_locale_t  locale,
va_list  valist 
)

Definition at line 5340 of file file.c.

Referenced by _fwprintf_s_l(), and vfwprintf_s().

◆ _waccess()

int CDECL _waccess ( const wchar_t filename,
int  mode 
)

Definition at line 1017 of file file.c.

1018{
1020
1021 TRACE("(%s,%d) %ld\n", debugstr_w(filename), mode, attr);
1022
1024 {
1026 return -1;
1027 }
1029 {
1031 return -1;
1032 }
1033 return 0;
1034}
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
Definition: cookie.c:202

Referenced by _access(), and _waccess_s().

◆ _waccess_s()

int CDECL _waccess_s ( const wchar_t filename,
int  mode 
)

Definition at line 1039 of file file.c.

1040{
1041 if (!MSVCRT_CHECK_PMT(filename != NULL)) return *_errno();
1042 if (!MSVCRT_CHECK_PMT((mode & ~(MSVCRT_R_OK | MSVCRT_W_OK)) == 0)) return *_errno();
1043
1044 if (_waccess(filename, mode) == -1)
1045 return *_errno();
1046 return 0;
1047}

Referenced by _access_s().

◆ _wchmod()

int CDECL _wchmod ( const wchar_t path,
int  flags 
)

Definition at line 1066 of file file.c.

1067{
1068 DWORD oldFlags = GetFileAttributesW(path);
1069
1070 if (oldFlags != INVALID_FILE_ATTRIBUTES)
1071 {
1072 DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY:
1073 oldFlags | FILE_ATTRIBUTE_READONLY;
1074
1075 if (newFlags == oldFlags || SetFileAttributesW(path, newFlags))
1076 return 0;
1077 }
1079 return -1;
1080}
#define _S_IWRITE
Definition: stat.h:85
BOOL WINAPI DECLSPEC_HOTPATCH SetFileAttributesW(LPCWSTR name, DWORD attributes)
Definition: file.c:2918

Referenced by _chmod().

◆ _wcreat()

int CDECL _wcreat ( const wchar_t path,
int  pmode 
)

Definition at line 2702 of file file.c.

2703{
2704 int flags = _O_CREAT | _O_TRUNC | _O_RDWR;
2705 return _wopen(path, flags, pmode);
2706}
int WINAPIV _wopen(const wchar_t *path, int flags,...)
Definition: file.c:2674

◆ _wfdopen()

FILE *CDECL _wfdopen ( int  fd,
const wchar_t mode 
)

Definition at line 1863 of file file.c.

1864{
1865 int open_flags, stream_flags;
1866 FILE* file;
1867
1868 if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) return NULL;
1869
1870 LOCK_FILES();
1871 if (!(file = msvcrt_alloc_fp()))
1872 file = NULL;
1873 else if (msvcrt_init_fp(file, fd, stream_flags) == -1)
1874 {
1875 file->_flag = 0;
1876 file = NULL;
1877 }
1878 else TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file);
1879 UNLOCK_FILES();
1880
1881 return file;
1882}
static FILE * msvcrt_alloc_fp(void)
Definition: file.c:615
static int msvcrt_get_flags(const wchar_t *mode, int *open_flags, int *stream_flags)
Definition: file.c:1722
static int msvcrt_init_fp(FILE *file, int fd, unsigned stream_flags)
Definition: file.c:649

Referenced by _fdopen(), and _wpopen().

◆ _wfopen()

◆ _wfopen_s()

int CDECL _wfopen_s ( FILE **  pFile,
const wchar_t filename,
const wchar_t mode 
)

Definition at line 4343 of file file.c.

4345{
4346 if (!MSVCRT_CHECK_PMT(pFile != NULL)) return EINVAL;
4347 if (!MSVCRT_CHECK_PMT(filename != NULL)) return EINVAL;
4348 if (!MSVCRT_CHECK_PMT(mode != NULL)) return EINVAL;
4349
4351
4352 if(!*pFile)
4353 return *_errno();
4354 return 0;
4355}
FILE *CDECL _wfopen(const wchar_t *path, const wchar_t *mode)
Definition: file.c:4335
MdFileObject pFile

◆ _wfreopen()

FILE *CDECL _wfreopen ( const wchar_t path,
const wchar_t mode,
FILE file 
)

Definition at line 4578 of file file.c.

4579{
4580 int open_flags, stream_flags, fd;
4581
4582 TRACE(":path (%s) mode (%s) file (%p) fd (%d)\n", debugstr_w(path), debugstr_w(mode), file, file ? file->_file : -1);
4583
4584 LOCK_FILES();
4585 if (file)
4586 {
4587 fclose(file);
4588 if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1)
4589 file = NULL;
4590 else if((fd = _wopen(path, open_flags, _S_IREAD | _S_IWRITE)) < 0)
4591 file = NULL;
4592 else if(msvcrt_init_fp(file, fd, stream_flags) == -1)
4593 {
4594 file->_flag = 0;
4595 file = NULL;
4596 }
4597 }
4598 UNLOCK_FILES();
4599 return file;
4600}
#define _S_IREAD
Definition: stat.h:84

Referenced by _wfreopen_s(), DllMain(), and freopen().

◆ _wfreopen_s()

int CDECL _wfreopen_s ( FILE **  pFile,
const wchar_t path,
const wchar_t mode,
FILE file 
)

Definition at line 4605 of file file.c.

4607{
4608 if (!MSVCRT_CHECK_PMT(pFile != NULL)) return EINVAL;
4609 if (!MSVCRT_CHECK_PMT(path != NULL)) return EINVAL;
4610 if (!MSVCRT_CHECK_PMT(mode != NULL)) return EINVAL;
4611 if (!MSVCRT_CHECK_PMT(file != NULL)) return EINVAL;
4612
4614
4615 if(!*pFile)
4616 return *_errno();
4617 return 0;
4618}
FILE *CDECL _wfreopen(const wchar_t *path, const wchar_t *mode, FILE *file)
Definition: file.c:4578

◆ _wfsopen()

FILE *CDECL _wfsopen ( const wchar_t path,
const wchar_t mode,
int  share 
)

Definition at line 4254 of file file.c.

4255{
4256 FILE* file;
4257 int open_flags, stream_flags, fd;
4258
4259 TRACE("(%s,%s)\n", debugstr_w(path), debugstr_w(mode));
4260
4261 /* map mode string to open() flags. "man fopen" for possibilities. */
4262 if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1)
4263 return NULL;
4264
4265 LOCK_FILES();
4266 fd = _wsopen(path, open_flags, share, _S_IREAD | _S_IWRITE);
4267 if (fd < 0)
4268 file = NULL;
4269 else if ((file = msvcrt_alloc_fp()) && msvcrt_init_fp(file, fd, stream_flags)
4270 != -1)
4271 TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file);
4272 else if (file)
4273 {
4274 file->_flag = 0;
4275 file = NULL;
4276 }
4277
4278 TRACE(":got (%p)\n",file);
4279 if (fd >= 0 && !file)
4280 _close(fd);
4281 UNLOCK_FILES();
4282 return file;
4283}
int WINAPIV _wsopen(const wchar_t *path, int oflags, int shflags,...)
Definition: file.c:2583

Referenced by _fsopen(), _wfopen(), LoadIniFile(), test_fopen(), and WriteIniFile().

◆ _wmktemp()

wchar_t *CDECL _wmktemp ( wchar_t pattern)

Definition at line 2260 of file file.c.

2261{
2262 int numX = 0;
2263 wchar_t *retVal = pattern;
2264 int id;
2265 wchar_t letter = 'a';
2266
2267 if(!pattern)
2268 return NULL;
2269
2270 while(*pattern)
2271 numX = (*pattern++ == 'X')? numX + 1 : 0;
2272 if (numX < 6)
2273 return NULL;
2274 pattern--;
2275 id = GetCurrentProcessId();
2276 numX = 6;
2277 while(numX--)
2278 {
2279 int tempNum = id / 10;
2280 *pattern-- = id - (tempNum * 10) + '0';
2281 id = tempNum;
2282 }
2283 pattern++;
2284 do
2285 {
2287 return retVal;
2288 *pattern = letter++;
2289 } while(letter != '|');
2290 return NULL;
2291}

◆ _wmktemp_s()

int CDECL _wmktemp_s ( wchar_t pattern,
size_t  size 
)

Definition at line 2221 of file file.c.

2222{
2223 DWORD len, xno, id;
2224
2226 return EINVAL;
2227
2228 for(len=0; len<size; len++)
2229 if(!pattern[len])
2230 break;
2231 if(!MSVCRT_CHECK_PMT(len!=size && len>=6)) {
2232 if(size)
2233 pattern[0] = 0;
2234 return EINVAL;
2235 }
2236
2237 for(xno=1; xno<=6; xno++)
2238 if(!MSVCRT_CHECK_PMT(pattern[len-xno] == 'X'))
2239 return EINVAL;
2240
2241 id = GetCurrentProcessId();
2242 for(xno=1; xno<6; xno++) {
2243 pattern[len-xno] = id%10 + '0';
2244 id /= 10;
2245 }
2246
2247 for(pattern[len-6]='a'; pattern[len-6]<='z'; pattern[len-6]++) {
2249 return 0;
2250 }
2251
2252 pattern[0] = 0;
2253 *_errno() = EEXIST;
2254 return EEXIST;
2255}

◆ _wopen()

int WINAPIV _wopen ( const wchar_t path,
int  flags,
  ... 
)

Definition at line 2674 of file file.c.

2675{
2676 va_list ap;
2677
2678 if (flags & _O_CREAT)
2679 {
2680 int pmode;
2681 va_start(ap, flags);
2682 pmode = va_arg(ap, int);
2683 va_end(ap);
2684 return _wsopen( path, flags, _SH_DENYNO, pmode );
2685 }
2686 else
2687 return _wsopen( path, flags, _SH_DENYNO);
2688}

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

◆ _wremove()

int CDECL _wremove ( const wchar_t path)

Definition at line 4965 of file file.c.

4966{
4967 return _wunlink(path);
4968}

Referenced by remove(), and START_TEST().

◆ _wrename()

int CDECL _wrename ( const wchar_t oldpath,
const wchar_t newpath 
)

Definition at line 4993 of file file.c.

4994{
4995 TRACE(":from %s to %s\n", debugstr_w(oldpath), debugstr_w(newpath));
4996 if (MoveFileExW(oldpath, newpath, MOVEFILE_COPY_ALLOWED))
4997 return 0;
4998 TRACE(":failed (%ld)\n", GetLastError());
5000 return -1;
5001}
BOOL WINAPI MoveFileExW(const WCHAR *source, const WCHAR *dest, DWORD flag)
Definition: file.c:2531
#define MOVEFILE_COPY_ALLOWED
Definition: filesup.h:29

Referenced by rename().

◆ _write()

int CDECL _write ( int  fd,
const void buf,
unsigned int  count 
)

Definition at line 3561 of file file.c.

3562{
3564 HANDLE hand = info->handle;
3565 DWORD num_written, i;
3566 BOOL console = FALSE;
3567
3569 {
3570 *_errno() = EBADF;
3572 return -1;
3573 }
3574
3576 {
3577 *_errno() = EINVAL;
3579 return -1;
3580 }
3581
3582 /* If appending, go to EOF */
3583 if (info->wxflag & WX_APPEND)
3584 _lseek(fd, 0, FILE_END);
3585
3586 if (!(info->wxflag & WX_TEXT))
3587 {
3588 if (!WriteFile(hand, buf, count, &num_written, NULL)
3589 || num_written != count)
3590 {
3591 TRACE("WriteFile (fd %d, hand %p) failed-last error (%ld)\n", fd,
3592 hand, GetLastError());
3595 *_errno() = EBADF;
3596 num_written = -1;
3597 }
3598
3600 return num_written;
3601 }
3602
3603 if (_isatty(fd)) console = VerifyConsoleIoHandle(hand);
3604 for (i = 0; i < count;)
3605 {
3606 const char *s = buf;
3607 char lfbuf[2048];
3608 DWORD j = 0;
3609
3610 if (ioinfo_get_textmode(info) == TEXTMODE_ANSI && console)
3611 {
3612 char conv[sizeof(lfbuf)];
3613 size_t len = 0;
3614
3615#if _MSVCR_VER >= 80
3616 if (info->dbcsBufferUsed)
3617 {
3618 conv[j++] = info->dbcsBuffer[0];
3619 info->dbcsBufferUsed = FALSE;
3620 conv[j++] = s[i++];
3621 len++;
3622 }
3623#endif
3624
3625 for (; i < count && j < sizeof(conv)-1 &&
3626 len < (sizeof(lfbuf) - 1) / sizeof(WCHAR); i++, j++, len++)
3627 {
3628 if (isleadbyte((unsigned char)s[i]))
3629 {
3630 conv[j++] = s[i++];
3631
3632 if (i == count)
3633 {
3634#if _MSVCR_VER >= 80
3635 info->dbcsBuffer[0] = conv[j-1];
3636 info->dbcsBufferUsed = TRUE;
3637 break;
3638#else
3639 *_errno() = EINVAL;
3641 return -1;
3642#endif
3643 }
3644 }
3645 else if (s[i] == '\n')
3646 {
3647 conv[j++] = '\r';
3648 len++;
3649 }
3650 conv[j] = s[i];
3651 }
3652
3653 len = mbstowcs((WCHAR*)lfbuf, conv, len);
3654 if (len == -1)
3655 {
3658 return -1;
3659 }
3660 j = len * 2;
3661 }
3663 {
3664 for (j = 0; i < count && j < sizeof(lfbuf)-1; i++, j++)
3665 {
3666 if (s[i] == '\n')
3667 lfbuf[j++] = '\r';
3668 lfbuf[j] = s[i];
3669 }
3670 }
3671 else if (ioinfo_get_textmode(info) == TEXTMODE_UTF16LE || console)
3672 {
3673 for (j = 0; i < count && j < sizeof(lfbuf)-3; i++, j++)
3674 {
3675 if (s[i] == '\n' && !s[i+1])
3676 {
3677 lfbuf[j++] = '\r';
3678 lfbuf[j++] = 0;
3679 }
3680 lfbuf[j++] = s[i++];
3681 lfbuf[j] = s[i];
3682 }
3683 }
3684 else
3685 {
3686 char conv[sizeof(lfbuf)/4];
3687
3688 for (j = 0; i < count && j < sizeof(conv)-3; i++, j++)
3689 {
3690 if (s[i] == '\n' && !s[i+1])
3691 {
3692 conv[j++] = '\r';
3693 conv[j++] = 0;
3694 }
3695 conv[j++] = s[i++];
3696 conv[j] = s[i];
3697 }
3698
3699 j = WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)conv, j/2, lfbuf, sizeof(lfbuf), NULL, NULL);
3700 if (!j)
3701 {
3704 return -1;
3705 }
3706 }
3707
3708 if (console)
3709 {
3710 j = j/2;
3711 if (!WriteConsoleW(hand, lfbuf, j, &num_written, NULL))
3712 num_written = -1;
3713 }
3714 else if (!WriteFile(hand, lfbuf, j, &num_written, NULL))
3715 {
3716 num_written = -1;
3717 }
3718
3719 if (num_written != j)
3720 {
3721 TRACE("WriteFile/WriteConsoleW (fd %d, hand %p) failed-last error (%ld)\n", fd,
3722 hand, GetLastError());
3725 *_errno() = EBADF;
3727 return -1;
3728 }
3729 }
3730
3732 return count;
3733}
#define WideCharToMultiByte
Definition: compat.h:111
BOOL WINAPI DECLSPEC_HOTPATCH VerifyConsoleIoHandle(HANDLE hIoHandle)
Definition: console.c:1112
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1447
BOOL WINAPI DECLSPEC_HOTPATCH WriteFile(HANDLE file, LPCVOID buffer, DWORD count, LPDWORD result, LPOVERLAPPED overlapped)
Definition: file.c:3896
int CDECL _isatty(int fd)
Definition: file.c:858
#define WX_APPEND
Definition: file.c:85
#define CP_UTF8
Definition: nls.h:20
mbstowcs
Definition: stdlib.h:925
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by _flsbuf(), _fwrite_nolock(), _putw(), configure_text_mode(), fwrite(), msvcrt_flush_buffer(), perror(), rd_write_file(), rw(), test__creat(), test_chsize(), test_file_inherit(), test_file_write_read(), test_lseek(), and write().

◆ _wsopen()

int WINAPIV _wsopen ( const wchar_t path,
int  oflags,
int  shflags,
  ... 
)

Definition at line 2583 of file file.c.

2584{
2585 int pmode;
2586 int fd;
2587
2588 if (oflags & _O_CREAT)
2589 {
2590 va_list ap;
2591
2592 va_start(ap, shflags);
2593 pmode = va_arg(ap, int);
2594 va_end(ap);
2595 }
2596 else
2597 pmode = 0;
2598
2599 return _wsopen_dispatch(path, oflags, shflags, pmode, &fd, 0) ? -1 : fd;
2600}

Referenced by _wfsopen(), and _wopen().

◆ _wsopen_dispatch()

int CDECL _wsopen_dispatch ( const wchar_t path,
int  oflags,
int  shflags,
int  pmode,
int fd,
int  secure 
)

Definition at line 2397 of file file.c.

2399{
2400 DWORD access = 0, creation = 0, attrib;
2403 int wxflag;
2404 HANDLE hand;
2405
2406 TRACE("path: (%s) oflags: %#x shflags: %#x pmode: %#x fd*: %p secure: %d\n",
2407 debugstr_w(path), oflags, shflags, pmode, fd, secure);
2408
2409 if (!MSVCRT_CHECK_PMT( fd != NULL )) return EINVAL;
2410 *fd = -1;
2411 if (!MSVCRT_CHECK_PMT(path != NULL)) return EINVAL;
2412
2413 wxflag = split_oflags(oflags);
2414 switch (oflags & (_O_RDONLY | _O_WRONLY | _O_RDWR))
2415 {
2416 case _O_RDONLY: access |= GENERIC_READ; break;
2417 case _O_WRONLY: access |= GENERIC_WRITE; break;
2418 case _O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break;
2419 }
2420
2421 if (oflags & _O_CREAT)
2422 {
2423 if (secure && !MSVCRT_CHECK_PMT(!(pmode & ~(_S_IREAD | _S_IWRITE))))
2424 return EINVAL;
2425
2426 if (oflags & _O_EXCL)
2427 creation = CREATE_NEW;
2428 else if (oflags & _O_TRUNC)
2429 creation = CREATE_ALWAYS;
2430 else
2431 creation = OPEN_ALWAYS;
2432 }
2433 else /* no _O_CREAT */
2434 {
2435 if (oflags & _O_TRUNC)
2436 creation = TRUNCATE_EXISTING;
2437 else
2438 creation = OPEN_EXISTING;
2439 }
2440
2441 switch( shflags )
2442 {
2443 case _SH_DENYRW:
2444 sharing = 0L;
2445 break;
2446 case _SH_DENYWR:
2448 break;
2449 case _SH_DENYRD:
2451 break;
2452 case _SH_DENYNO:
2454 break;
2455 default:
2456 ERR( "Unhandled shflags %#x\n", shflags );
2457 return EINVAL;
2458 }
2459
2460 if (!(pmode & ~MSVCRT_umask & _S_IWRITE))
2461 attrib = FILE_ATTRIBUTE_READONLY;
2462 else
2463 attrib = FILE_ATTRIBUTE_NORMAL;
2464
2465 if (oflags & _O_TEMPORARY)
2466 {
2467 attrib |= FILE_FLAG_DELETE_ON_CLOSE;
2468 access |= DELETE;
2470 }
2471
2472 if (oflags & _O_RANDOM)
2473 attrib |= FILE_FLAG_RANDOM_ACCESS;
2474 if (oflags & _O_SEQUENTIAL)
2475 attrib |= FILE_FLAG_SEQUENTIAL_SCAN;
2476 if (oflags & _O_SHORT_LIVED)
2477 attrib |= FILE_ATTRIBUTE_TEMPORARY;
2478
2479 sa.nLength = sizeof( SECURITY_ATTRIBUTES );
2480 sa.lpSecurityDescriptor = NULL;
2481 sa.bInheritHandle = !(oflags & _O_NOINHERIT);
2482
2483 if ((oflags & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT))
2484 && (creation==OPEN_ALWAYS || creation==OPEN_EXISTING)
2485 && !(access&GENERIC_READ))
2486 {
2489 if (hand != INVALID_HANDLE_VALUE)
2490 {
2491 oflags = check_bom(hand, oflags, FALSE);
2492 CloseHandle(hand);
2493 }
2494 }
2495
2496 hand = CreateFileW(path, access, sharing, &sa, creation, attrib, 0);
2497 if (hand == INVALID_HANDLE_VALUE) {
2498 WARN(":failed-last error (%ld)\n", GetLastError());
2500 return *_errno();
2501 }
2502
2503 if (oflags & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT))
2504 {
2505 LARGE_INTEGER size = {{0}};
2506
2507 if ((access & GENERIC_WRITE) && (creation==OPEN_EXISTING || creation==OPEN_ALWAYS))
2508 GetFileSizeEx(hand, &size);
2509
2510 if ((access & GENERIC_WRITE) && (creation==CREATE_NEW
2511 || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING
2512 || ((creation==OPEN_EXISTING || creation==OPEN_ALWAYS) && !size.QuadPart)))
2513 {
2514 if (oflags & _O_U8TEXT)
2515 {
2516 DWORD written = 0, tmp;
2517
2518 while(written!=sizeof(utf8_bom) && WriteFile(hand, (char*)utf8_bom+written,
2519 sizeof(utf8_bom)-written, &tmp, NULL))
2520 written += tmp;
2521 if (written != sizeof(utf8_bom)) {
2522 WARN("error writing BOM\n");
2523 CloseHandle(hand);
2525 return *_errno();
2526 }
2527 }
2528 else
2529 {
2530 DWORD written = 0, tmp;
2531
2532 while(written!=sizeof(utf16_bom) && WriteFile(hand, (char*)utf16_bom+written,
2533 sizeof(utf16_bom)-written, &tmp, NULL))
2534 written += tmp;
2535 if (written != sizeof(utf16_bom))
2536 {
2537 WARN("error writing BOM\n");
2538 CloseHandle(hand);
2540 return *_errno();
2541 }
2542 oflags |= _O_U16TEXT;
2543 }
2544 }
2545 else if (access & GENERIC_READ)
2546 oflags = check_bom(hand, oflags, TRUE);
2547 }
2548
2549 type = GetFileType(hand);
2550 if (type == FILE_TYPE_CHAR)
2551 wxflag |= WX_TTY;
2552 else if (type == FILE_TYPE_PIPE)
2553 wxflag |= WX_PIPE;
2554
2555 *fd = msvcrt_alloc_fd(hand, wxflag);
2556 if (*fd == -1)
2557 return *_errno();
2558
2559 if (oflags & _O_WTEXT)
2561
2562 if (oflags & _O_U16TEXT)
2564 else if (oflags & _O_U8TEXT)
2566
2567 TRACE(":fd (%d) handle (%p)\n", *fd, hand);
2568 return 0;
2569}
#define ERR(fmt,...)
Definition: precomp.h:57
#define _O_SEQUENTIAL
Definition: cabinet.h:43
#define _O_SHORT_LIVED
Definition: cabinet.h:49
#define _O_TEMPORARY
Definition: cabinet.h:44
#define _O_RDONLY
Definition: cabinet.h:37
#define _O_EXCL
Definition: cabinet.h:48
#define _O_RANDOM
Definition: cabinet.h:42
#define OPEN_EXISTING
Definition: compat.h:775
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define GetFileSizeEx
Definition: compat.h:757
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
static int check_bom(HANDLE h, int oflags, BOOL seek)
Definition: file.c:2373
static char utf8_bom[3]
Definition: file.c:89
static char utf16_bom[2]
Definition: file.c:90
static void ioinfo_set_unicode(ioinfo *info, BOOL unicode)
Definition: file.c:236
#define _SH_DENYRW
Definition: share.h:37
#define _SH_DENYRD
Definition: share.h:39
#define _SH_DENYWR
Definition: share.h:38
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define CREATE_ALWAYS
Definition: disk.h:72
#define TRUNCATE_EXISTING
Definition: disk.h:71
#define FILE_FLAG_RANDOM_ACCESS
Definition: disk.h:44
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define CREATE_NEW
Definition: disk.h:69
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define DELETE
Definition: nt_native.h:57
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_ATTRIBUTE_TEMPORARY
Definition: nt_native.h:708
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG sharing
Definition: pipe.c:70

Referenced by _sopen_dispatch(), _wsopen(), and _wsopen_s().

◆ _wsopen_s()

int CDECL _wsopen_s ( int fd,
const wchar_t path,
int  oflags,
int  shflags,
int  pmode 
)

Definition at line 2575 of file file.c.

2576{
2577 return _wsopen_dispatch( path, oflags, shflags, pmode, fd, 1 );
2578}

Referenced by _sopen_s(), and _wsopen().

◆ _wstat()

int CDECL _wstat ( const wchar_t path,
struct _stat buf 
)

Definition at line 3366 of file file.c.

3367{
3368 int ret;
3369 struct _stat64 buf64;
3370
3371 ret = _wstat64( path, &buf64 );
3372 if (!ret) msvcrt_stat64_to_stat(&buf64, buf);
3373 return ret;
3374}

◆ _wstat64()

int CDECL _wstat64 ( const wchar_t path,
struct _stat64 buf 
)

Definition at line 3276 of file file.c.

3277{
3278 DWORD dw;
3280 unsigned short mode = ALL_S_IREAD;
3281 int plen;
3282
3283 TRACE(":file (%s) buf(%p)\n", debugstr_w(path), buf);
3284
3285 plen = wcslen(path);
3286 while (plen && path[plen-1]==' ')
3287 plen--;
3288
3289 if (plen==2 && path[1]==':')
3290 {
3291 *_errno() = ENOENT;
3292 return -1;
3293 }
3294
3295#if _MSVCR_VER<140
3296 if (plen>=2 && path[plen-2]!=':' && (path[plen-1]=='\\' || path[plen-1]=='/'))
3297 {
3298 *_errno() = ENOENT;
3299 return -1;
3300 }
3301#endif
3302
3304 {
3305 TRACE("failed (%ld)\n", GetLastError());
3306 *_errno() = ENOENT;
3307 return -1;
3308 }
3309
3310 memset(buf,0,sizeof(struct _stat64));
3311
3312 /* FIXME: rdev isn't drive num, despite what the docs says-what is it? */
3313 if (iswalpha(*path) && path[1] == ':')
3314 buf->st_dev = buf->st_rdev = towupper(*path) - 'A'; /* drive num */
3315 else
3316 buf->st_dev = buf->st_rdev = _getdrive() - 1;
3317
3318 /* Dir, or regular file? */
3320 mode |= (_S_IFDIR | ALL_S_IEXEC);
3321 else
3322 {
3323 mode |= _S_IFREG;
3324 /* executable? */
3325 if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */
3326 {
3327 ULONGLONG ext = towlower(path[plen-1]) | (towlower(path[plen-2]) << 16) |
3328 ((ULONGLONG)towlower(path[plen-3]) << 32);
3329 if (ext == WCEXE || ext == WCBAT || ext == WCCMD || ext == WCCOM)
3330 mode |= ALL_S_IEXEC;
3331 }
3332 }
3333
3335 mode |= ALL_S_IWRITE;
3336
3337 buf->st_mode = mode;
3338 buf->st_nlink = 1;
3339 buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow;
3341 buf->st_atime = dw;
3343 buf->st_mtime = buf->st_ctime = dw;
3344 TRACE("%d %d %#I64x %I64d %I64d %I64d\n", buf->st_mode, buf->st_nlink,
3345 buf->st_size, buf->st_atime, buf->st_mtime, buf->st_ctime);
3346 return 0;
3347}
#define _S_IFDIR
Definition: stat.h:23
static const WCHAR *const ext[]
Definition: module.c:53
BOOL WINAPI DECLSPEC_HOTPATCH GetFileAttributesExW(LPCWSTR name, GET_FILEEX_INFO_LEVELS level, void *ptr)
Definition: file.c:1721
int CDECL _getdrive(void)
Definition: dir.c:819
#define ALL_S_IEXEC
Definition: file.c:73
static const ULONGLONG WCCMD
Definition: file.c:291
#define ALL_S_IREAD
Definition: file.c:71
static const ULONGLONG WCBAT
Definition: file.c:290
#define ALL_S_IWRITE
Definition: file.c:72
static const ULONGLONG WCCOM
Definition: file.c:292
static const ULONGLONG WCEXE
Definition: file.c:289
#define ENOENT
Definition: errno.h:25
@ GetFileExInfoStandard
Definition: minwinbase.h:356
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define iswalpha(_c)
Definition: ctype.h:664
#define towlower(c)
Definition: wctype.h:97
#define towupper(c)
Definition: wctype.h:99
uint64_t ULONGLONG
Definition: typedefs.h:67

◆ _wstati64()

int CDECL _wstati64 ( const wchar_t path,
struct _stati64 buf 
)

Definition at line 3352 of file file.c.

3353{
3354 int ret;
3355 struct _stat64 buf64;
3356
3357 ret = _wstat64(path, &buf64);
3358 if (!ret)
3360 return ret;
3361}

◆ _wtempnam()

wchar_t *CDECL _wtempnam ( const wchar_t dir,
const wchar_t prefix 
)

Definition at line 3464 of file file.c.

3465{
3466 wchar_t tmpbuf[MAX_PATH];
3467 const wchar_t *tmp_dir = _wgetenv(L"TMP");
3468
3469 if (tmp_dir) dir = tmp_dir;
3470
3471 TRACE("dir (%s) prefix (%s)\n", debugstr_w(dir), debugstr_w(prefix));
3472 /* TODO: use whole prefix */
3473 if (GetTempFileNameW(dir,prefix,0,tmpbuf))
3474 {
3475 TRACE("got name (%s)\n", debugstr_w(tmpbuf));
3476 DeleteFileW(tmpbuf);
3477 return _wcsdup(tmpbuf);
3478 }
3479 TRACE("failed (%ld)\n", GetLastError());
3480 return NULL;
3481}
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI DECLSPEC_HOTPATCH GetTempFileNameW(LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer)
Definition: file.c:2355
BOOL WINAPI DECLSPEC_HOTPATCH DeleteFileW(LPCWSTR path)
Definition: file.c:1003
wchar_t *CDECL _wgetenv(const wchar_t *name)
Definition: environ.c:254
_ACRTIMP wchar_t *__cdecl _wcsdup(const wchar_t *) __WINE_DEALLOC(free) __WINE_MALLOC
Definition: wcs.c:81

Referenced by _tempnam().

◆ _wtmpnam()

wchar_t *CDECL _wtmpnam ( wchar_t s)

Definition at line 5182 of file file.c.

5183{
5184 if (!s) {
5186
5187 if(!data->wtmpnam_buffer)
5188 data->wtmpnam_buffer = malloc(sizeof(wchar_t[MAX_PATH]));
5189
5190 s = data->wtmpnam_buffer;
5191 }
5192
5193 return wtmpnam_helper(s, -1, &tmpnam_unique, TMP_MAX) ? NULL : s;
5194}
#define malloc
Definition: debug_ros.c:4
static LONG tmpnam_unique
Definition: file.c:285
static int wtmpnam_helper(wchar_t *s, size_t size, LONG *tmpnam_unique, int tmp_max)
Definition: file.c:5122
#define TMP_MAX
Definition: stdio.h:35
thread_data_t *CDECL msvcrt_get_thread_data(void)
Definition: thread.c:45
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

◆ _wtmpnam_s()

int CDECL _wtmpnam_s ( wchar_t s,
size_t  size 
)

Definition at line 5174 of file file.c.

5175{
5177}
static LONG tmpnam_s_unique
Definition: file.c:286
#define TMP_MAX_S
Definition: stdio.h:36

◆ _wunlink()

int CDECL _wunlink ( const wchar_t path)

Definition at line 1099 of file file.c.

1100{
1101 TRACE("(%s)\n", debugstr_w(path));
1102 if(DeleteFileW(path))
1103 return 0;
1104 TRACE("failed (%ld)\n", GetLastError());
1106 return -1;
1107}

Referenced by _unlink(), _wremove(), and test_utf8().

◆ _wutime32()

int CDECL _wutime32 ( const wchar_t path,
struct __utimbuf32 t 
)

Definition at line 3545 of file file.c.

3546{
3547 if (t)
3548 {
3549 struct __utimbuf64 t64;
3550 t64.actime = t->actime;
3551 t64.modtime = t->modtime;
3552 return _wutime64( path, &t64 );
3553 }
3554 else
3555 return _wutime64( path, NULL );
3556}
int CDECL _wutime64(const wchar_t *path, struct __utimbuf64 *t)
Definition: file.c:3529

◆ _wutime64()

int CDECL _wutime64 ( const wchar_t path,
struct __utimbuf64 t 
)

Definition at line 3529 of file file.c.

3530{
3531 int fd = _wopen(path, _O_WRONLY | _O_BINARY);
3532
3533 if (fd > 0)
3534 {
3535 int retVal = _futime64(fd, t);
3536 _close(fd);
3537 return retVal;
3538 }
3539 return -1;
3540}

Referenced by _wutime32().

◆ add_std_buffer()

static BOOL add_std_buffer ( FILE file)
static

Definition at line 893 of file file.c.

894{
895 static char buffers[2][BUFSIZ];
896
897 if((file->_file!=STDOUT_FILENO && file->_file!=STDERR_FILENO)
898 || (file->_flag & (MSVCRT__NOBUF | _IOMYBUF | MSVCRT__USERBUF))
899 || !_isatty(file->_file))
900 return FALSE;
901
902 file->_ptr = file->_base = buffers[file->_file == STDOUT_FILENO ? 0 : 1];
903 file->_bufsiz = file->_cnt = BUFSIZ;
904 file->_flag |= MSVCRT__USERBUF;
905 return TRUE;
906}
#define BUFSIZ
Definition: stdio.h:40
const GLuint * buffers
Definition: glext.h:5916

Referenced by fputws(), vfprintf_helper(), and vfwprintf_helper().

◆ alloc_pioinfo_block()

static BOOL alloc_pioinfo_block ( int  fd)
inlinestatic

Definition at line 427 of file file.c.

428{
429 ioinfo *block;
430 int i;
431
432 if(fd<0 || fd>=MSVCRT_MAX_FILES)
433 {
434 *_errno() = ENFILE;
435 return FALSE;
436 }
437
439 if(!block)
440 {
441 WARN(":out of memory!\n");
442 *_errno() = ENOMEM;
443 return FALSE;
444 }
445 for(i=0; i<MSVCRT_FD_BLOCK_SIZE; i++)
446 {
447 block[i].handle = INVALID_HANDLE_VALUE;
449 {
450 /* Initialize crit section on block allocation for _MSVC_VER >= 140,
451 * ioinfo_is_crit_init() is always TRUE. */
453 }
454 }
456 {
457 if (ioinfo_is_crit_init(&block[0]))
458 {
459 for(i = 0; i < MSVCRT_FD_BLOCK_SIZE; ++i)
461 }
462 free(block);
463 }
464 return TRUE;
465}
ioinfo * MSVCRT___pioinfo[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE]
Definition: file.c:155
static BOOL ioinfo_is_crit_init(ioinfo *info)
Definition: file.c:201
#define MSVCRT_FD_BLOCK_SIZE
Definition: file.c:126
#define ENFILE
Definition: errno.h:45
#define ENOMEM
Definition: errno.h:35
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
#define calloc
Definition: rosglue.h:14
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
static unsigned int block
Definition: xmlmemory.c:101

Referenced by get_ioinfo_alloc(), and get_ioinfo_alloc_fd().

◆ check_bom()

static int check_bom ( HANDLE  h,
int  oflags,
BOOL  seek 
)
static

Definition at line 2373 of file file.c.

2374{
2375 char bom[sizeof(utf8_bom)];
2376 DWORD r;
2377
2378 if (!ReadFile(h, bom, sizeof(utf8_bom), &r, NULL))
2379 return oflags;
2380
2381 if (r==sizeof(utf8_bom) && !memcmp(bom, utf8_bom, sizeof(utf8_bom))) {
2382 oflags = (oflags & ~(_O_WTEXT | _O_U16TEXT)) | _O_U8TEXT;
2383 }else if (r>=sizeof(utf16_bom) && !memcmp(bom, utf16_bom, sizeof(utf16_bom))) {
2384 if (seek && r>2)
2386 oflags = (oflags & ~(_O_WTEXT | _O_U8TEXT)) | _O_U16TEXT;
2387 }else if (seek) {
2389 }
2390
2391 return oflags;
2392}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
int seek(void *fd, ulong off, int mode)
Definition: pe.c:51

Referenced by _wsopen_dispatch(), _wsopen_s(), and configure_text_mode().

◆ clearerr()

void CDECL clearerr ( FILE file)

Definition at line 1672 of file file.c.

1673{
1674 TRACE(":file (%p) fd (%d)\n",file,file->_file);
1675
1677 file->_flag &= ~(_IOERR | _IOEOF);
1679}

Referenced by read_mbr_template(), rewind(), test_fileops(), and ungetc().

◆ clearerr_s()

int CDECL clearerr_s ( FILE file)

Definition at line 1684 of file file.c.

1685{
1686 TRACE(":file (%p)\n",file);
1687
1688 if (!MSVCRT_CHECK_PMT(file != NULL)) return EINVAL;
1689
1691 file->_flag &= ~(_IOERR | _IOEOF);
1693 return 0;
1694}

◆ fclose()

int CDECL fclose ( FILE file)

Definition at line 3757 of file file.c.

3758{
3759 int ret;
3760
3761 if (!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
3762
3766
3767 return ret;
3768}
int CDECL _fclose_nolock(FILE *file)
Definition: file.c:3773

Referenced by __CloseHandle(), _fcloseall(), _Filebuf_base::_M_close(), _pclose(), _rmtmp(), _wfreopen(), _wpopen(), abort(), CCabinet::AddFile(), check_atari(), check_bitmap_data(), check_file_size(), check_for_files(), CheckForNewV3User(), checkSsiByFilelist(), cleanReq(), File::close(), CCabinet::Close(), anonymous_namespace{popen.cpp}::stream_traits::close(), close_backing_store(), close_file(), close_log_files(), close_merge_image(), CloseBookmarkFile(), CloseFile(), CloseTrace(), CCabinet::CommitDisk(), compare_export_(), compat_fclose(), concat_files(), config_load(), copy_file(), create_cache(), create_nls_file(), create_output_file(), create_sic(), CreateCaseDiff(), CreateSpecFile(), DbgHelpAddLineNumber(), CCFDATAStorage::Destroy(), disk_cleanup(), DllMain(), DoCreateTestFile(), DoEntry(), DoParsing(), DosBIOSInitialize(), DoTestEntry(), EndLog(), endnetconfig(), endrpcent(), errconfig(), export_all(), export_key(), export_registry_key(), ExportBinaryHive(), extract_test(), CCabinet::ExtractFile(), fclose_file_func(), file_exists(), fileClient(), FileExists(), ForF(), gen_add_list(), Generate(), generate_xa_rr_attributes(), get_file_data(), get_ImageBase(), get_list_blocks(), get_subtests(), GetHostnameFromCommand(), getICMPStats(), getnetconfigent(), getnetid(), GetOurHostName(), getpublicandprivatekey(), getSection(), gl_check_inputrc_for_vi(), gl_histloadfile(), gl_histsavefile(), import_certs_from_file(), ImportRegistryFile(), InfHostOpenFile(), InfHostWriteFile(), init(), init_leases_list(), init_logger_addr(), TScript::initScript(), kbd_c(), kbd_def(), kbd_h(), kbd_rc(), CDFParser::Load(), Load_CP2Unicode_Table(), load_file(), Load_OEM2Unicode_Table(), LoadBootIni(), tinyxml2::XMLDocument::LoadFile(), LoadFile(), LoadFirewallPrefs(), LoadIniFile(), LoadPrefs(), LoadSystemIni(), log_file(), logMess(), LogOpen(), LogXfer(), lwip_fuzztest(), main(), MainWndProc(), myClose(), of_help(), open_input_file(), OpenBookmarkFile(), openSection(), OpenTmpBookmarkFile(), parse_switches(), parseAndPrintFile(), TANSIParser::ParseEscapeANSI(), PerformRegAction(), TANSIParser::PrintBuffer(), processRequest(), PutBookmark(), read_cache(), read_file(), read_input_file(), read_JPEG_file(), read_mbr_template(), read_quant_tables(), read_rcfile(), readAllPolygons(), readconfig(), ReadFromFile(), ReadHostsFile(), readSection(), recvrequest(), reg_import(), remglob(), ResourceToFile(), ResourceToFileW(), RunBookmarkEditor(), RunScript(), ruserpass(), tinyxml2::XMLDocument::SaveFile(), SavePrefs(), SdbCloseDatabase(), select_file_name(), send_file(), sendrequest(), ServiceMain(), set_LogFile(), CCabinet::SetCabinetReservedFile(), SHPropertyBag_OnIniFile(), SpoolX(), START_TEST(), FstreamTest::tellp(), test___getmainargs(), test___getmainargs_parent(), test__wfopen_s(), test_asciimode(), test_asciimode2(), test_ctrlz(), Test_DelNodeA(), Test_DelNodeW(), test_fdopen(), test_fflush(), test_fgetc(), test_fgetwc(), test_fgetwc_locale(), test_fgetwc_unicode(), test_filbuf(), test_file_put_get(), test_file_truncate(), test_filemodeT(), test_fileops(), test_flsbuf(), test_fopen(), test_fopen_exclusive(), test_fopen_fclose_fcloseall(), test_fopen_hints(), test_fopen_s(), test_fprintf(), test_fputc(), test_fputwc(), test_freopen(), test_fscanf(), test_fwprintf(), test_invalid_stdin_child(), test_iobuf_layout(), Test_PathProcessCommand(), test_pipes(), test_readboundary(), test_readmode(), test_searchenv(), TEST_Start(), test_std_stream_open(), test_unlink(), test_utf8(), test_write_flush(), CCFDATAStorage::Truncate(), txt_export_all(), txt_export_key(), unpack_iso(), verify_output_file(), wmain(), wpp_parse(), write_casemap_file(), write_client(), write_dlldata(), write_dlldata_list(), write_header(), write_id_data(), write_if_change(), write_JPEG_file(), write_local_stubs(), write_one_file(), write_proxies(), write_regscript(), write_server(), directedLine::writeAllPolygons(), CCabinet::WriteFileToScratchStorage(), WriteIniFile(), XCOPY_ProcessExcludeFile(), xkeymap_from_locale(), xkeymap_read(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemoryDump(), xsltDocumentElem(), CDFParser::~CDFParser(), FileReporter::~FileReporter(), and TANSIParser::~TANSIParser().

◆ feof()

◆ ferror()

◆ fflush()

int CDECL fflush ( FILE file)

Definition at line 1182 of file file.c.

1183{
1184 int ret;
1185
1186 if(!file) {
1188 ret = 0;
1189 } else {
1193 }
1194
1195 return ret;
1196}

Referenced by alarm_intr(), cd(), cdup(), check_blocks(), cmdabort(), cmdscanner(), CmpFileFlush(), command(), confirm(), dataconn(), delete(), disk_ioctl(), do_chmod(), domacro(), domap(), doproxy(), dprintf(), eprintf(), Error(), fclose(), fsetmode(), get_key(), GetCmd(), getit(), GetPass(), getreply(), globulize(), help(), hookup(), initconn(), InputChar(), InteractiveConsole(), lcd(), LocalListCmd(), log_debug(), log_hexdump(), login(), logMess(), ls(), lwip_fuzztest(), macdef(), main(), makedir(), mdelete(), mget(), mls(), modtime(), MonitorChildThread(), mput(), msvcrt_flush_all_buffers(), NcFTPConfirmResumeDownloadProc(), NcFTPConfirmResumeUploadProc(), newer(), OpenMsg(), OpenPager(), PrintF(), PrintStartupBanner(), PromptForBookmarkName(), proxtrans(), PrPhilBar(), PrStatBar(), ptransfer(), put(), PutCmd(), pwd(), query_done(), quote(), recvrequest(), remglob(), removedir(), rename_file(), renamefile(), restart(), rewrite_client_leases(), SaveCurrentAsBookmark(), SaveUnsavedBookmark(), sendrequest(), SendTelnetInterrupt(), serial_create(), setbell(), setcase(), setcr(), setdebug(), setform(), setglob(), sethash(), setnmap(), setntrans(), setpassive(), setpeer(), setport(), setprompt(), setrunique(), setstruct(), setsunique(), settrace(), settype(), setvbuf(), setverbose(), shell(), site(), sizecmd(), START_TEST(), status(), test_fflush(), test_std_stream_buffering(), test_write_flush_size(), throw(), usage(), user(), wintirpc_debug(), write_client_lease(), write_one_file(), WriteBmLine(), xdrstdio_destroy(), and FileReporter::~FileReporter().

◆ fgetc()

◆ fgetpos()

int CDECL fgetpos ( FILE file,
fpos_t pos 
)

Definition at line 4758 of file file.c.

4759{
4760 *pos = _ftelli64(file);
4761 if(*pos == -1)
4762 return -1;
4763 return 0;
4764}
__int64 CDECL _ftelli64(FILE *file)
Definition: file.c:4672

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

◆ fgets()

char *CDECL fgets ( char s,
int  size,
FILE file 
)

Definition at line 3903 of file file.c.

3904{
3905 int cc = EOF;
3906 char * buf_start = s;
3907
3908 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
3909 file,file->_file,s,size);
3910
3912
3913 while ((size >1) && (cc = _fgetc_nolock(file)) != EOF && cc != '\n')
3914 {
3915 *s++ = (char)cc;
3916 size --;
3917 }
3918 if ((cc == EOF) && (s == buf_start)) /* If nothing read, return 0*/
3919 {
3920 TRACE(":nothing read\n");
3922 return NULL;
3923 }
3924 if ((cc != EOF) && (size > 1))
3925 *s++ = cc;
3926 *s = '\0';
3927 TRACE(":got %s\n", debugstr_a(buf_start));
3929 return buf_start;
3930}
#define debugstr_a
Definition: kernel32.h:31

Referenced by _tmain(), check_atari(), CheckForNewV3User(), config_load(), create_cache(), create_sic(), CreateCaseDiff(), EndLog(), FGets(), fgetws(), find_str(), gen_add_list(), get_pnames(), GetHostnameFromCommand(), getICMPStats(), File::getline(), getnetconfig(), getnetconfigent(), getnetid(), GetOurHostName(), getpublicandprivatekey(), getrpcent(), getSection(), gl_check_inputrc_for_vi(), gl_histloadfile(), import_base64_certs_from_fp(), init_logger_addr(), InteractiveConsole(), Load_CP2Unicode_Table(), Load_OEM2Unicode_Table(), LocalListCmd(), log_file(), login(), main(), NcFTPConfirmResumeDownloadProc(), NcFTPConfirmResumeUploadProc(), NextLine(), openSection(), ProcessFirewallPrefFile(), ProcessPrefsFile(), read_cache(), read_password(), read_rcfile(), ReadHostsFile(), Readline(), readline(), readSection(), remglob(), rename_file(), SaveCurrentAsBookmark(), SaveUnsavedBookmark(), test__popen(), test__popen_read_child(), test_asciimode(), test_ctrlz(), test_file_put_get(), test_fileops(), test_fprintf(), test_fwprintf(), Test_popen(), test_readmode(), translate_files(), user(), widl_getline(), and xkeymap_read().

◆ fgetwc()

wint_t CDECL fgetwc ( FILE file)

Definition at line 3935 of file file.c.

3936{
3937 wint_t ret;
3938
3942
3943 return ret;
3944}

Referenced by _fgetwchar(), _getws(), fgetws(), getwc(), test_fgetwc_locale(), and test_fgetwc_unicode().

◆ fgetws()

wchar_t *CDECL fgetws ( wchar_t s,
int  size,
FILE file 
)

Definition at line 4043 of file file.c.

4044{
4045 wint_t cc = WEOF;
4046 wchar_t * buf_start = s;
4047
4048 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
4049 file,file->_file,s,size);
4050
4052
4053 while ((size >1) && (cc = _fgetwc_nolock(file)) != WEOF && cc != '\n')
4054 {
4055 *s++ = cc;
4056 size --;
4057 }
4058 if ((cc == WEOF) && (s == buf_start)) /* If nothing read, return 0*/
4059 {
4060 TRACE(":nothing read\n");
4062 return NULL;
4063 }
4064 if ((cc != WEOF) && (size > 1))
4065 *s++ = cc;
4066 *s = 0;
4067 TRACE(":got %s\n", debugstr_w(buf_start));
4069 return buf_start;
4070}

Referenced by DosBIOSInitialize(), FindString(), InterpretInteractive(), InterpretMain(), LoadBootIni(), LoadIniFile(), LoadSystemIni(), ReadFromFile(), RunScript(), test_fgetwc(), test_file_put_get(), test_fileops(), test_fwprintf(), wmain(), and XCOPY_ProcessExcludeFile().

◆ file_get_cs()

static CRITICAL_SECTION * file_get_cs ( FILE f)
static

Definition at line 270 of file file.c.

271{
272 if (f < iob_get_file(0) || f >= iob_get_file(_IOB_ENTRIES))
273 return &((file_crit*)f)->crit;
274 return NULL;
275}
#define _IOB_ENTRIES
Definition: mtdll.h:55
GLfloat f
Definition: glext.h:7540

Referenced by _lock_file(), _unlock_file(), msvcrt_alloc_fp(), msvcrt_free_io(), and msvcrt_init_io().

◆ fopen()

FILE *CDECL fopen ( const char path,
const char mode 
)

Definition at line 4310 of file file.c.

4311{
4312 return _fsopen( path, mode, _SH_DENYNO );
4313}
FILE *CDECL _fsopen(const char *path, const char *mode, int share)
Definition: file.c:4288

Referenced by CCabinet::AddFile(), tinyxml2::callfopen(), check_atari(), check_bitmap_data(), check_for_files(), CheckForNewV3User(), checkSsiByFilelist(), CCabinet::CommitDisk(), compare_export_(), compat_fopen(), concat_files(), config_load(), copy_file(), CCFDATAStorage::Create(), create_cache(), create_nls_file(), CreateCaseDiff(), DbgHelpAddLineNumber(), disk_openimage(), DoEntry(), DoTestEntry(), EndLog(), ExportBinaryHive(), extract_test(), CCabinet::ExtractFile(), file_exists(), fileClient(), FileExists(), FileReporter::FileReporter(), fopen_file_func(), fopen_s(), gen_add_list(), Generate(), generate_xa_rr_attributes(), get_file_data(), get_ImageBase(), get_list_blocks(), get_subtests(), GetHostnameFromCommand(), getICMPStats(), getnetconfigent(), getnetid(), GetOurHostName(), getpublicandprivatekey(), getrpcent(), getSection(), gl_check_inputrc_for_vi(), gl_histloadfile(), gl_histsavefile(), InfHostOpenFile(), InfHostWriteFile(), init(), init_client(), init_leases_list(), init_logger_addr(), init_proxy(), init_server(), TScript::initScript(), jpeg_open_backing_store(), kbd_c(), kbd_def(), kbd_h(), kbd_rc(), CDFParser::Load(), Load_CP2Unicode_Table(), load_file(), Load_OEM2Unicode_Table(), LoadFile(), LoadFirewallPrefs(), LoadPrefs(), log_file(), logMess(), LogOpen(), LogXfer(), lwip_fuzztest(), main(), MainWndProc(), CCabinet::Open(), File::open(), open_input_file(), open_log_files(), open_merge_image(), OpenBookmarkFile(), openSection(), OpenTmpBookmarkFile(), OpenTrace(), parse_switches(), parseAndPrintFile(), TANSIParser::ParseEscapeANSI(), pfopen(), pp_open_include(), processRequest(), read_cache(), read_file(), read_input_file(), read_JPEG_file(), read_mbr_template(), read_quant_tables(), read_rcfile(), readAllPolygons(), readconfig(), recvrequest(), remglob(), ResourceToFile(), rewrite_client_leases(), RunBookmarkEditor(), ruserpass(), SavePrefs(), SdbpCreate(), select_file_name(), send_file(), sendrequest(), set_LogFile(), CCabinet::SetCabinetReservedFile(), setnetconfig(), setrpcent(), SpoolX(), START_TEST(), TANSIParser::TANSIParser(), FstreamTest::tellp(), test___getmainargs(), test___getmainargs_parent(), test__wfopen_s(), test_asciimode(), test_asciimode2(), test_ctrlz(), Test_DelNodeA(), 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_exclusive(), test_fopen_fclose_fcloseall(), test_fopen_hints(), test_fopen_s(), test_fprintf(), test_fputc(), test_fputwc(), test_freopen(), test_fscanf(), test_fwprintf(), test_iobuf_layout(), test_readboundary(), test_searchenv(), test_std_stream_open(), test_unlink(), test_utf8(), test_write_flush(), CCFDATAStorage::Truncate(), unpack_iso(), wintirpc_debug(), wpp_parse(), write_casemap_file(), write_client_lease(), write_dlldata(), write_dlldata_list(), write_header(), write_id_data(), write_if_change(), write_JPEG_file(), write_local_stubs(), write_one_file(), write_regscript(), directedLine::writeAllPolygons(), CCabinet::WriteFileToScratchStorage(), CDFParser::WriteInfLine(), xkeymap_open(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemoryDump(), and xsltDocumentElem().

◆ fopen_s()

int CDECL fopen_s ( FILE **  pFile,
const char filename,
const char mode 
)

Definition at line 4318 of file file.c.

4320{
4321 if (!MSVCRT_CHECK_PMT(pFile != NULL)) return EINVAL;
4322 if (!MSVCRT_CHECK_PMT(filename != NULL)) return EINVAL;
4323 if (!MSVCRT_CHECK_PMT(mode != NULL)) return EINVAL;
4324
4325 *pFile = fopen(filename, mode);
4326
4327 if(!*pFile)
4328 return *_errno();
4329 return 0;
4330}
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310

Referenced by tinyxml2::callfopen(), CreateSpecFile(), and FileReporter::FileReporter().

◆ fprintf()

int WINAPIV fprintf ( FILE file,
const char format,
  ... 
)

Definition at line 5549 of file file.c.

5550{
5552 int res;
5555 va_end(valist);
5556 return res;
5557}
int CDECL vfprintf(FILE *file, const char *format, va_list valist)
Definition: file.c:5349

Referenced by __report_error(), __rpc_broadenable(), __rpcb_findaddr_timed(), __xprt_do_unregister(), _amsg_exit(), _assert(), _chm_decompress_block(), _getgroups(), _getopt_internal_r(), _svcauth_gss(), _TIFFPrettyPrintField(), _TIFFprintAsciiBounded(), _TIFFprintAsciiTag(), _TIFFPrintField(), _TIFFPrintFieldInfo(), _vwarnx(), aargh(), abort(), add_cache(), add_hash(), adns__vdiag(), adnsfail(), ApplyOrdinals(), arg_get_long(), arg_get_utf8(), assign_file_addresses(), assign_stub_out_args(), attributeDeclDebug(), authgss_create(), authgss_create_default(), authgss_destroy(), authgss_validate(), BackToTop(), bezierPatchMeshMake(), bezierPatchMeshNumTriangles(), bezierPatchMeshPutPatch(), buffered_fullread(), build_huffman_tree(), build_tree(), byte_till_end(), cdataBlockDebug(), change_section_attribs(), charactersDebug(), chat(), check_cache(), check_entropy(), check_for_files(), check_lame_tag(), CheckForNewV3User(), checkRecv(), CheckTestFile(), chmc_add_entry(), chmc_crunch_lzx(), chmc_section_create(), clear_output_vars(), ClickProc(), clnt_cb_thread(), clnt_pcreateerror(), clnt_perrno(), clnt_perror(), clnt_vc_create(), clnt_vc_destroy(), CloseTrace(), CommandShell(), commentDebug(), configparseerr(), ConvertCoffs(), ConvertStabs(), create_cache(), CreateOutputFile(), CreateSpecFile(), CreateTestDir(), CreateTestFile(), directedLine::cutoffPolygon(), dataconn(), DBG_check(), DbgHelpAddLineNumber(), DbgHelpAddStringToTable(), debug_error(), declare_stub_args(), decode_header(), decode_the_frame(), decodeA(), die(), disk_enum_devices(), display_dhcp_packet(), RdpClientUI::Display_DrawText(), DliFailureHook(), do_layer2(), do_rva(), do_write_c_method_def(), dprintf(), dump_tree(), dump_var_desc(), DumpCharacterFontData(), DumpFont(), dumpHex(), dumpStr(), dumptype(), elementDeclDebug(), encodeA(), FileReporter::end(), end_cplusplus_guard(), endDocumentDebug(), endElementDebug(), endElementNsDebug(), OpenGLSurfaceEvaluator::endmap2f(), endnetpath(), entityDeclDebug(), eprintf(), error(), FileReporter::error(), Error(), ErrorExit(), ErrorHook(), Slicer::evalStream(), ewmh_get_window_desktop(), ExecuteKill(), externalSubsetDebug(), failure_errno(), failure_status(), fatal_error(), Fatalv(), file_put_ascii(), file_write(), file_write_http_header(), fileClient(), fill_boot_desc(), find_lease(), find_match_at(), find_or_create_directory(), fputcSocket(), fputSocket(), frame_buffercheck(), frame_cpu_opt(), free_variable(), fs_flush(), FTC_MruNode_Prepend(), FTC_MruNode_Remove(), FTC_MruNode_Up(), FTPPerror(), gen_proxy(), gen_stub(), gen_stub_thunk(), Generate(), generate_one_directory(), generate_xa_rr_attributes(), generic_msg(), get_current_desktop(), get_current_workarea(), get_property_value(), getbits(), getclnthandle(), GetCmd(), getEntityDebug(), GetExportsFromFile(), getnetconfig(), getnetconfigent(), getnetid(), getopt(), Getopt(), getpacket(), getParameterEntityDebug(), getpublicandprivatekey(), gl_histsavefile(), gluNurbsSurface(), hasExternalSubsetDebug(), hasInternalSubsetDebug(), help(), HexDump(), hookup(), ignorableWhitespaceDebug(), III_get_side_info(), indent(), init_begin(), init_finish(), init_server(), InitConnectionInfo(), InitUserInfo(), insert_file_entry(), internalSubsetDebug(), iso_connect(), isohybrid_error(), isohybrid_warning(), isStandaloneDebug(), Jobs(), kbd_c(), kbd_def(), kbd_h(), kbd_rc(), KmtUnloadDriver(), KmtUnloadDriverKeepService(), LIBXML_ATTR_FORMAT(), ListCmd(), LocalChdirCmd(), LocalListCmd(), log_debug(), log_hexdump(), login(), logMess(), LogOpen(), LogXfer(), Ls(), Ls1(), LsC(), LsL(), lz_analyze_block(), lz_compress(), lzx_compress_block(), lzx_output_literal(), lzx_output_match(), lzx_write_bits(), lzx_write_compressed_literals(), lzx_write_compressed_tree(), main(), make_listening_socket(), make_temp_dir(), make_temp_file(), MakeArgv(), MC_sweepY(), merge_remaining_entries(), MergeStabsAndCoffs(), FileReporter::message(), MlsCmd(), mpg123_fmt2(), mpg123_fmt_all(), mpg123_fmt_none(), msg(), msg_spy_find_next_msg(), nanox_event(), nc_perror(), netfinger(), next_marker(), normalize(), notationDeclDebug(), OnCreate(), OOM(), OpenBookmarkFile(), OpenCmd(), OpenMsg(), OpenTmpBookmarkFile(), OpenTrace(), option_callback(), out_params(), OutOfMemory(), output_message(), Output_stublabel(), OutputAlias(), OutputError(), OutputHeader_asmstub(), OutputHeader_def(), OutputHeader_stub(), OutputLine_asmstub(), OutputLine_def(), OutputLine_def_GCC(), OutputLine_def_MS(), OutputLine_stub(), PageCmd(), parse_arguments(), parse_cmdlineargs(), parse_dhcp_options(), parse_new_id3(), parse_switches(), parseAndPrintFile(), ParseFile(), parsePath(), pdie(), pipeClient(), pipeServer(), PlotCharacter(), pp_add_macro(), pp_internal_error(), pp_pop_if(), pp_push_if(), PredictorPrintDir(), PreInit(), print(), print_access_mask(), print_condwait_status(), print_create_attributes(), print_disconnect_reason(), print_disposition(), print_dnsfail(), print_error(), print_file_id_both_dir_info(), print_hexbuf(), print_hexbuf_no_asci(), print_phase_basetype(), print_rpc_gss_sec(), print_share_mode(), print_sr_status_flags(), print_text_marker(), PrintHosts(), printline(), PrintName(), PrintNameOrImpName(), PrintNameTable(), printopts(), PrintStartupBanner(), FileReporter::printSummary(), PrintUsage(), process_comment(), process_data(), process_dhcp_packet(), process_extra(), process_file(), process_long_option(), process_picture(), RequestHandler::process_request(), process_text(), processingInstructionDebug(), ProcessRelocations(), proclog(), FileReporter::progress(), promote_framename(), proxy_free_variables(), PrPhilBar(), PrSizeAndRateMeter(), PrStatBar(), PutBookmark(), PutCmd(), rdp2vnc_connect(), rdpsnd_process_negotiate(), read_frame(), read_JPEG_file(), read_merging_directory(), read_password(), read_quant_tables(), read_rcfile(), read_stdin(), recvrequest(), referenceDebug(), registerNode(), release_lease(), resolveEntityDebug(), rpc_broadcast_exp(), WriterThread::Run(), run_rapps(), RunBatch(), RunBookmarkEditor(), ruserpass(), SaveCurrentAsBookmark(), SavePrefs(), scan_directory_tree(), search_tree_file(), select_transform(), sendrequest(), SendTelnetInterrupt(), ServeOneClient(), Server(), set_quant_slots(), set_sample_factors(), SetAnonPass(), SetAutoAscii(), SetAutoResume(), SetAutoSaveChangesToExistingBookmarks(), SetConfirmClose(), SetConnTimeout(), SetCtrlTimeout(), setDocumentLocatorDebug(), SetLogSize(), SetNoAds(), SetOneTimeMessages(), SetPager(), SetPassive(), SetRedialDelay(), SetSavePasswords(), SetSOBufsize(), SetStartupURL(), setup_tables(), SetXferTimeout(), SetXtermTitle(), SetXtTitle(), showVersion(), sic_list(), skip_junk(), sort_n_finish(), SpoolGetCmd(), SpoolPutCmd(), SpoolX(), start_cplusplus_guard(), START_TEST(), startDocumentDebug(), startElementDebug(), startElementNsDebug(), sunboot_write(), susage(), svc_getreqset(), svcauth_gss_accept_sec_context(), sweepY(), synth_ntom_set_step(), sysfail(), test_decodeNameConstraints(), test_fprintf(), test_fscanf(), test_iobuf_layout(), TEST_Start(), test_std_stream_buffering(), testSAX(), textAsk(), textDelta(), textStep(), TIFFPrintDirectory(), TIM_SORT_RESIZE(), Trace(), try_query_param(), try_start_stop(), tx_compress_dxtn(), ui_create_window(), ui_draw_text(), unimpl(), unixErrorHandler(), unixWarningHandler(), unparsedEntityDeclDebug(), RequestHandler::urldec(), usage(), Usage(), usageerr(), user(), userlist(), verr(), verrx(), vwarn(), vwarnx(), WaitForConnect(), warning(), wave_out_close(), wave_out_open(), wave_out_set_format(), wave_out_volume(), wave_out_write(), wetwork(), Win32ErrorHandler(), Win32WarningHandler(), WindowThreadProc(), WinMain(), wmain(), wpp_parse(), write_apicontract(), write_apicontract_guard_end(), write_apicontract_guard_start(), write_args(), write_checksums(), write_client_call_routine(), write_client_func_decl(), write_client_ifaces(), write_client_lease(), write_client_routines(), write_clientinterfacedecl(), write_coclass(), write_coclass_forward(), write_com_interface_end(), write_com_interface_start(), write_context_handle_rundowns(), write_cpp_method_def(), write_declaration(), write_dispatchtable(), write_dlldata_list(), write_endpoints(), write_enums(), write_exceptions(), write_expr(), write_expr_eval_routine_list(), write_expr_eval_routines(), write_fields(), write_files(), write_formatstringsdecl(), write_forward(), write_full_pointer_free(), write_full_pointer_init(), write_func_param_struct(), write_function_proto(), write_function_stub(), write_generic_handle_routines(), write_guid(), write_header(), write_header_stmts(), write_id_data(), write_id_guid(), write_if_change(), write_implicithandledecl(), write_import(), write_inline_wrappers(), write_ip_tfs(), write_JPEG_file(), write_library(), write_line(), write_local_stubs(), write_locals(), write_method_macro(), write_method_proto(), write_nonsimple_pointer(), write_one_file(), write_packet(), write_parameter_conf_or_var_exprs(), write_parameterized_implementation(), write_parameterized_type_forward(), write_parameters_init(), write_pointer_left(), write_proxy(), write_proxy_routines(), write_remoting_arg(), write_rpc_interface_end(), write_rpc_interface_start(), write_runtimeclass(), write_runtimeclass_forward(), write_serialize_function(), write_server_stmts(), write_serverinterfacedecl(), write_stdout(), write_stub_methods(), write_stubdescdecl(), write_stubdescriptor(), write_type_definition(), write_type_left(), write_type_right(), write_type_v(), write_typedef(), write_user_quad_list(), write_user_types(), write_uuid_decl(), write_widl_using_macros(), write_widl_using_method_macros(), directedLine::writeAllPolygons(), WriteBmLine(), WriteDefaultFirewallPrefs(), WriteTable(), xmalloc(), xmlCheckVersion(), xmlDictAddQString(), xmlDictAddString(), xmlDictCreate(), xmlDictCreateSub(), xmlDictGrow(), xmlInitializeGlobalState(), xmllintExternalEntityLoader(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemShow(), xmlPrintURI(), xprt_register(), xrealloc(), xsltDebugDumpExtensions(), xsltDebugDumpExtensionsCallback(), xsltDebugDumpExtModulesCallback(), xsltInitAllDocKeys(), xsltInitCtxtKey(), xsltInitCtxtKeys(), xsltInitDocKeyTable(), xsltPatPushState(), and xsltTestCompMatch().

◆ fprintf_s()

int WINAPIV fprintf_s ( FILE file,
const char format,
  ... 
)

Definition at line 5562 of file file.c.

5563{
5565 int res;
5568 va_end(valist);
5569 return res;
5570}
int CDECL vfprintf_s(FILE *file, const char *format, va_list valist)
Definition: file.c:5357

◆ fputc()

◆ fputs()

◆ fputwc()

wint_t CDECL fputwc ( wint_t  wc,
FILE file 
)

Definition at line 4203 of file file.c.

4204{
4205 wint_t ret;
4206
4208 ret = _fputwc_nolock(wc, file);
4210
4211 return ret;
4212}

Referenced by _fputwchar(), _putwch(), ConWrite(), fputws(), test_fgetwc(), test_fgetwc_unicode(), and test_fputwc().

◆ fputws()

_ACRTIMP int __cdecl fputws ( const wchar_t s,
FILE file 
)

Definition at line 4783 of file file.c.

4784{
4785 size_t i, len = wcslen(s);
4786 BOOL tmp_buf;
4787 int ret;
4788
4790 if (!(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) {
4791 ret = _fwrite_nolock(s,sizeof(*s),len,file) == len ? 0 : EOF;
4793 return ret;
4794 }
4795
4796 tmp_buf = add_std_buffer(file);
4797 for (i=0; i<len; i++) {
4798 if(_fputwc_nolock(s[i], file) == WEOF) {
4799 if(tmp_buf) remove_std_buffer(file);
4801 return WEOF;
4802 }
4803 }
4804
4805 if(tmp_buf) remove_std_buffer(file);
4807 return 0;
4808}
static void remove_std_buffer(FILE *file)
Definition: file.c:910
static BOOL add_std_buffer(FILE *file)
Definition: file.c:893

Referenced by _putws(), ConPuts(), ConResPuts(), test_fgetwc(), and WriteIniFile().

◆ fread()

◆ freopen()

FILE *CDECL freopen ( const char path,
const char mode,
FILE file 
)

Definition at line 4624 of file file.c.

4625{
4626 FILE *ret;
4627 wchar_t *pathW = NULL, *modeW = NULL;
4628
4629 if (path && !(pathW = wstrdupa_utf8(path))) return NULL;
4630 if (mode && !(modeW = msvcrt_wstrdupa(mode)))
4631 {
4632 free(pathW);
4633 return NULL;
4634 }
4635
4636 ret = _wfreopen(pathW, modeW, file);
4637
4638 free(pathW);
4639 free(modeW);
4640 return ret;
4641}

Referenced by freopen_s(), main(), test_freopen(), test_std_stream_buffering(), test_std_stream_open(), and xfwrite().

◆ freopen_s()

errno_t CDECL freopen_s ( FILE **  pFile,
const char path,
const char mode,
FILE file 
)

Definition at line 4646 of file file.c.

4648{
4649 if (!MSVCRT_CHECK_PMT(pFile != NULL)) return EINVAL;
4650 if (!MSVCRT_CHECK_PMT(path != NULL)) return EINVAL;
4651 if (!MSVCRT_CHECK_PMT(mode != NULL)) return EINVAL;
4652 if (!MSVCRT_CHECK_PMT(file != NULL)) return EINVAL;
4653
4654 *pFile = freopen(path, mode, file);
4655
4656 if(!*pFile)
4657 return *_errno();
4658 return 0;
4659}
FILE *CDECL freopen(const char *path, const char *mode, FILE *file)
Definition: file.c:4624

◆ fseek()

◆ fsetpos()

int CDECL fsetpos ( FILE file,
fpos_t pos 
)

Definition at line 4664 of file file.c.

4665{
4666 return _fseeki64(file,*pos,SEEK_SET);
4667}

Referenced by test_fileops().

◆ ftell()

◆ fwprintf()

int WINAPIV fwprintf ( FILE file,
const wchar_t format,
  ... 
)

Definition at line 5628 of file file.c.

5629{
5631 int res;
5634 va_end(valist);
5635 return res;
5636}
int CDECL vfwprintf(FILE *file, const wchar_t *format, va_list valist)
Definition: file.c:5365

Referenced by _wassert(), _wperror(), ConWrite(), CreatePerfWindows(), ProcessCommandLine(), test_fprintf(), and wWinMain().

◆ fwprintf_s()

int WINAPIV fwprintf_s ( FILE file,
const wchar_t format,
  ... 
)

Definition at line 5641 of file file.c.

5642{
5644 int res;
5647 va_end(valist);
5648 return res;
5649}
int CDECL vfwprintf_s(FILE *file, const wchar_t *format, va_list valist)
Definition: file.c:5373

◆ fwrite()

size_t CDECL fwrite ( const void ptr,
size_t  size,
size_t  nmemb,
FILE file 
)

◆ get_ioinfo()

static ioinfo * get_ioinfo ( int  fd)
inlinestatic

Definition at line 417 of file file.c.

418{
420 if(ret == &MSVCRT___badioinfo)
421 return ret;
424 return ret;
425}
static void init_ioinfo_cs(ioinfo *info)
Definition: file.c:405

Referenced by _chsize_s(), _close(), _commit(), _dup2(), _eof(), _fstat64(), _futime64(), _locking(), _lseeki64(), _read(), _setmode(), _write(), get_ioinfo_alloc_fd(), and msvcrt_free_fd().

◆ get_ioinfo_alloc()

static ioinfo * get_ioinfo_alloc ( int fd)
inlinestatic

Definition at line 481 of file file.c.

482{
483 int i;
484
485 *fd = -1;
486 for(i=0; i<MSVCRT_MAX_FILES; i++)
487 {
489
491 {
493 return &MSVCRT___badioinfo;
495 }
496
498 if(TryEnterCriticalSection(&info->crit))
499 {
500 if(info->handle == INVALID_HANDLE_VALUE)
501 {
502 *fd = i;
503 return info;
504 }
506 }
507 }
508
509 WARN(":files exhausted!\n");
510 *_errno() = ENFILE;
511 return &MSVCRT___badioinfo;
512}
static BOOL alloc_pioinfo_block(int fd)
Definition: file.c:427
BOOL WINAPI TryEnterCriticalSection(LPCRITICAL_SECTION)

Referenced by _dup(), and msvcrt_alloc_fd().

◆ get_ioinfo_alloc_fd()

static ioinfo * get_ioinfo_alloc_fd ( int  fd)
inlinestatic

Definition at line 467 of file file.c.

468{
469 ioinfo *ret;
470
471 ret = get_ioinfo(fd);
472 if(ret != &MSVCRT___badioinfo)
473 return ret;
474
476 return &MSVCRT___badioinfo;
477
478 return get_ioinfo(fd);
479}

Referenced by _dup2(), and msvcrt_init_io().

◆ get_ioinfo_nolock()

◆ get_utf8_char_len()

static int get_utf8_char_len ( char  ch)
inlinestatic

Definition at line 2770 of file file.c.

2771{
2772 if((ch&0xf8) == 0xf0)
2773 return 4;
2774 else if((ch&0xf0) == 0xe0)
2775 return 3;
2776 else if((ch&0xe0) == 0xc0)
2777 return 2;
2778 return 1;
2779}

Referenced by read_utf8().

◆ getc()

◆ getchar()

int CDECL getchar ( void  )

Definition at line 4813 of file file.c.

4814{
4815 return fgetc(stdin);
4816}

Referenced by FSE_normalizeCount(), get_key(), macdef(), main(), Main(), and printWindowsError().

◆ gets()

char *CDECL gets ( char buf)

Definition at line 4871 of file file.c.

4872{
4873 return gets_s(buf, -1);
4874}
char *CDECL gets_s(char *buf, size_t len)
Definition: file.c:4829

Referenced by cd(), cmdscanner(), confirm(), delete(), do_chmod(), domacro(), doproxy(), getit(), macdef(), main(), makedir(), mdelete(), mget(), mls(), modtime(), mput(), put(), quote(), removedir(), renamefile(), setnmap(), setpeer(), site(), sizecmd(), and user().

◆ gets_s()

char *CDECL gets_s ( char buf,
size_t  len 
)

Definition at line 4829 of file file.c.

4830{
4831 char *buf_start = buf;
4832 int cc;
4833
4834 if (!MSVCRT_CHECK_PMT(buf != NULL)) return NULL;
4835 if (!MSVCRT_CHECK_PMT(len != 0)) return NULL;
4836
4838 for(cc = _fgetc_nolock(stdin);
4839 len != 0 && cc != EOF && cc != '\n';
4841 {
4842 if (cc != '\r')
4843 {
4844 *buf++ = (char)cc;
4845 len--;
4846 }
4847 }
4849
4850 if (!len)
4851 {
4852 *buf_start = 0;
4854 return NULL;
4855 }
4856
4857 if ((cc == EOF) && (buf_start == buf))
4858 {
4859 TRACE(":nothing read\n");
4860 return NULL;
4861 }
4862 *buf = '\0';
4863
4864 TRACE("got '%s'\n", buf_start);
4865 return buf_start;
4866}
void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
Definition: errno.c:461

Referenced by gets().

◆ getwc()

wint_t CDECL getwc ( FILE file)

Definition at line 4019 of file file.c.

4020{
4021 return fgetwc(file);
4022}

◆ getwchar()

wint_t CDECL getwchar ( void  )

Definition at line 4035 of file file.c.

4036{
4037 return _fgetwchar();
4038}
wint_t CDECL _fgetwchar(void)
Definition: file.c:4027

◆ init_ioinfo_cs()

static void init_ioinfo_cs ( ioinfo info)
inlinestatic

Definition at line 405 of file file.c.

406{
408 LOCK_FILES();
412 }
413 UNLOCK_FILES();
414 }
415}
static void ioinfo_set_crit_init(ioinfo *info)
Definition: file.c:206

Referenced by get_ioinfo(), and get_ioinfo_alloc().

◆ iob_get_file()

static FILE * iob_get_file ( int  i)
static

Definition at line 265 of file file.c.

266{
267 return &MSVCRT__iob[i];
268}
FILE MSVCRT__iob[_IOB_ENTRIES]
Definition: file.c:263

Referenced by __iob_func(), _lock_file(), _unlock_file(), file_get_cs(), msvcrt_get_file(), and msvcrt_init_io().

◆ ioinfo_get_textmode()

static enum textmode ioinfo_get_textmode ( ioinfo info)
inlinestatic

Definition at line 211 of file file.c.

212{
213 if (info->exflag & EF_UTF8)
214 return TEXTMODE_UTF8;
215 if (info->exflag & EF_UTF16)
216 return TEXTMODE_UTF16LE;
217 return TEXTMODE_ANSI;
218}
#define EF_UTF8
Definition: file.c:196
#define EF_UTF16
Definition: file.c:197

Referenced by _fgetwc_nolock(), _fputwc_nolock(), _setmode(), _ungetwc_nolock(), _write(), and read_i().

◆ ioinfo_is_crit_init()

static BOOL ioinfo_is_crit_init ( ioinfo info)
inlinestatic

Definition at line 201 of file file.c.

202{
203 return info->exflag & EF_CRIT_INIT;
204}
#define EF_CRIT_INIT
Definition: file.c:198

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

◆ ioinfo_set_crit_init()

static void ioinfo_set_crit_init ( ioinfo info)
inlinestatic

Definition at line 206 of file file.c.

207{
208 info->exflag |= EF_CRIT_INIT;
209}

Referenced by init_ioinfo_cs().

◆ ioinfo_set_textmode()

static void ioinfo_set_textmode ( ioinfo info,
enum textmode  mode 
)
inlinestatic

Definition at line 220 of file file.c.

221{
222 info->exflag &= EF_CRIT_INIT | EF_UNK_UNICODE;
223 switch (mode)
224 {
225 case TEXTMODE_ANSI:
226 break;
227 case TEXTMODE_UTF8:
228 info->exflag |= EF_UTF8;
229 break;
230 case TEXTMODE_UTF16LE:
231 info->exflag |= EF_UTF16;
232 break;
233 }
234}
#define EF_UNK_UNICODE
Definition: file.c:199

Referenced by _setmode(), _wsopen_dispatch(), and msvcrt_set_fd().

◆ ioinfo_set_unicode()

static void ioinfo_set_unicode ( ioinfo info,
BOOL  unicode 
)
inlinestatic

Definition at line 236 of file file.c.

237{
238 if (unicode)
239 info->exflag |= EF_UNK_UNICODE;
240 else
241 info->exflag &= ~EF_UNK_UNICODE;
242}

Referenced by _wsopen_dispatch(), and msvcrt_set_fd().

◆ msvcrt_alloc_buffer()

static BOOL msvcrt_alloc_buffer ( FILE file)
static

Definition at line 866 of file file.c.

867{
868#if _MSVCR_VER >= 140
869 if((file->_file==STDOUT_FILENO && _isatty(file->_file))
870 || file->_file == STDERR_FILENO)
871 return FALSE;
872#else
873 if((file->_file==STDOUT_FILENO || file->_file==STDERR_FILENO)
874 && _isatty(file->_file))
875 return FALSE;
876#endif
877
879 if(file->_base) {
880 file->_bufsiz = MSVCRT_INTERNAL_BUFSIZ;
881 file->_flag |= _IOMYBUF;
882 } else {
883 file->_base = (char*)(&file->_charbuf);
884 file->_bufsiz = 2;
885 file->_flag |= MSVCRT__NOBUF;
886 }
887 file->_ptr = file->_base;
888 file->_cnt = 0;
889 return TRUE;
890}

Referenced by _filbuf(), _flsbuf(), _fread_nolock(), _ungetc_nolock(), fread(), and ungetc().

◆ msvcrt_alloc_fd()

static int msvcrt_alloc_fd ( HANDLE  hand,
int  flag 
)
static

Definition at line 598 of file file.c.

599{
600 int fd;
602
603 TRACE(":handle (%p) allocating fd (%d)\n", hand, fd);
604
606 return -1;
607
608 msvcrt_set_fd(info, hand, flag);
610 return fd;
611}

Referenced by _open_osfhandle(), _pipe(), _wsopen_dispatch(), and _wsopen_s().

◆ msvcrt_alloc_fp()

static FILE * msvcrt_alloc_fp ( void  )
static

Definition at line 615 of file file.c.

616{
617 int i = 0;
618 FILE *file;
619
620#if _MSVCR_VER >= 140
621 i = 3;
622#endif
623 for (; i < MSVCRT_max_streams; i++)
624 {
626 if (!file)
627 return NULL;
628
629 if (file->_flag == 0)
630 {
631 if (i == MSVCRT_stream_idx)
632 {
634 if (cs)
635 {
637 cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": file_crit.crit");
638 }
640 }
641 return file;
642 }
643 }
644
645 return NULL;
646}
BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
Definition: sync.c:107
#define DWORD_PTR
Definition: treelist.c:76
#define RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO
Definition: winnt_old.h:1146

Referenced by _wfdopen(), _wfsopen(), and tmpfile().

◆ msvcrt_create_io_inherit_block()

BOOL msvcrt_create_io_inherit_block ( WORD size,
BYTE **  block 
)

Definition at line 675 of file file.c.

676{
677 int fd, last_fd;
678 char* wxflag_ptr;
679 HANDLE* handle_ptr;
680 ioinfo* fdinfo;
681
682 for (last_fd=MSVCRT_MAX_FILES-1; last_fd>=0; last_fd--)
684 break;
685 last_fd++;
686
687 *size = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * last_fd;
688 *block = calloc(1, *size);
689 if (!*block)
690 {
691 *size = 0;
692 return FALSE;
693 }
694 wxflag_ptr = (char*)*block + sizeof(unsigned);
695 handle_ptr = (HANDLE*)(wxflag_ptr + last_fd);
696
697 *(unsigned*)*block = last_fd;
698 for (fd = 0; fd < last_fd; fd++)
699 {
700 /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
701 fdinfo = get_ioinfo_nolock(fd);
702 if ((fdinfo->wxflag & (WX_OPEN | WX_DONTINHERIT)) == WX_OPEN)
703 {
704 *wxflag_ptr = fdinfo->wxflag;
705 *handle_ptr = fdinfo->handle;
706 }
707 else
708 {
709 *wxflag_ptr = 0;
710 *handle_ptr = INVALID_HANDLE_VALUE;
711 }
712 wxflag_ptr++; handle_ptr++;
713 }
714 return TRUE;
715}
#define WX_DONTINHERIT
Definition: file.c:84
static unsigned(__cdecl *hash_bstr)(bstr_t s)
PVOID HANDLE
Definition: typedefs.h:73

Referenced by msvcrt_spawn().

◆ msvcrt_flush_all_buffers()

static int msvcrt_flush_all_buffers ( int  mask)
static

Definition at line 1148 of file file.c.

1149{
1150 int i, num_flushed = 0;
1151 FILE *file;
1152
1153 LOCK_FILES();
1154 for (i = 0; i < MSVCRT_stream_idx; i++) {
1156
1157 if (file->_flag)
1158 {
1159 if(file->_flag & mask) {
1160 fflush(file);
1161 num_flushed++;
1162 }
1163 }
1164 }
1165 UNLOCK_FILES();
1166
1167 TRACE(":flushed (%d) handles\n",num_flushed);
1168 return num_flushed;
1169}
int CDECL fflush(FILE *file)
Definition: file.c:1182
GLenum GLint GLuint mask
Definition: glext.h:6028

Referenced by _fflush_nolock(), _flushall(), and fflush().

◆ msvcrt_flush_buffer()

static int msvcrt_flush_buffer ( FILE file)
static

Definition at line 835 of file file.c.

836{
837 int ret = 0;
838
839 if((file->_flag & (_IOREAD|_IOWRT)) == _IOWRT &&
840 file->_flag & (_IOMYBUF|MSVCRT__USERBUF)) {
841 int cnt=file->_ptr-file->_base;
842 if(cnt>0 && _write(file->_file, file->_base, cnt) != cnt) {
843 file->_flag |= _IOERR;
844 ret = EOF;
845 } else if(file->_flag & _IORW) {
846 file->_flag &= ~_IOWRT;
847 }
848 }
849
850 file->_ptr=file->_base;
851 file->_cnt=0;
852 return ret;
853}
_In_ size_t cnt
Definition: wcstombs.cpp:43

Referenced by _fflush_nolock(), _flsbuf(), _fputc_nolock(), _fseeki64(), _fseeki64_nolock(), _fwrite_nolock(), fflush(), fputc(), fsetpos(), fwrite(), and remove_std_buffer().

◆ msvcrt_free_fd()

static void msvcrt_free_fd ( int  fd)
static

Definition at line 547 of file file.c.

548{
549 ioinfo *fdinfo = get_ioinfo(fd);
550
551 if(fdinfo != &MSVCRT___badioinfo)
552 {
554 fdinfo->wxflag = 0;
555 }
556 TRACE(":fd (%d) freed\n",fd);
557
558 if (fd < 3)
559 {
560 switch (fd)
561 {
562 case 0:
564 break;
565 case 1:
567 break;
568 case 2:
570 break;
571 }
572 }
573 release_ioinfo(fdinfo);
574}
BOOL WINAPI DECLSPEC_HOTPATCH SetStdHandle(DWORD nStdHandle, HANDLE hHandle)
Definition: console.c:1215
#define STD_OUTPUT_HANDLE
Definition: winbase.h:292
#define STD_INPUT_HANDLE
Definition: winbase.h:291
#define STD_ERROR_HANDLE
Definition: winbase.h:293

Referenced by _close().

◆ msvcrt_free_io()

void msvcrt_free_io ( void  )

Definition at line 1392 of file file.c.

1393{
1394 unsigned int i;
1395 int j;
1396
1397 _flushall();
1398 _fcloseall();
1399
1400 for(i=0; i<ARRAY_SIZE(MSVCRT___pioinfo); i++)
1401 {
1402 if(!MSVCRT___pioinfo[i])
1403 continue;
1404
1405 for(j=0; j<MSVCRT_FD_BLOCK_SIZE; j++)
1406 {
1409 }
1411 }
1412
1413 for(j=0; j<MSVCRT_stream_idx; j++)
1414 {
1417
1418 if(cs)
1419 {
1420 cs->DebugInfo->Spare[0] = 0;
1422 }
1423 }
1424
1425 for(i=0; i<ARRAY_SIZE(MSVCRT_fstream); i++)
1427}
#define ARRAY_SIZE(A)
Definition: main.h:20
static file_crit * MSVCRT_fstream[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE]
Definition: file.c:278
int CDECL _fcloseall(void)
Definition: file.c:1373
int CDECL _flushall(void)
Definition: file.c:1174

Referenced by DllMain().

◆ msvcrt_get_file()

static FILE * msvcrt_get_file ( int  i)
inlinestatic

Definition at line 520 of file file.c.

521{
522 file_crit *ret;
523
524 if(i >= MSVCRT_max_streams)
525 return NULL;
526
527 if(i < _IOB_ENTRIES)
528 return iob_get_file(i);
529
531 if(!ret) {
534 ERR("out of memory\n");
535 *_errno() = ENOMEM;
536 return NULL;
537 }
538
540 } else
542
543 return &ret->file;
544}

Referenced by _fcloseall(), _rmtmp(), fclose(), msvcrt_alloc_fp(), msvcrt_flush_all_buffers(), and msvcrt_free_io().

◆ msvcrt_get_flags()

static int msvcrt_get_flags ( const wchar_t mode,
int open_flags,
int stream_flags 
)
static

Definition at line 1722 of file file.c.

1723{
1724 int plus = wcschr(mode, '+') != NULL;
1725
1726 TRACE("%s\n", debugstr_w(mode));
1727
1728 while(*mode == ' ') mode++;
1729
1730 switch(*mode++)
1731 {
1732 case 'R': case 'r':
1733 *open_flags = plus ? _O_RDWR : _O_RDONLY;
1734 *stream_flags = plus ? _IORW : _IOREAD;
1735 break;
1736 case 'W': case 'w':
1737 *open_flags = _O_CREAT | _O_TRUNC | (plus ? _O_RDWR : _O_WRONLY);
1738 *stream_flags = plus ? _IORW : _IOWRT;
1739 break;
1740 case 'A': case 'a':
1741 *open_flags = _O_CREAT | _O_APPEND | (plus ? _O_RDWR : _O_WRONLY);
1742 *stream_flags = plus ? _IORW : _IOWRT;
1743 break;
1744 default:
1746 return -1;
1747 }
1748
1749 *stream_flags |= MSVCRT__commode;
1750
1751 while (*mode && *mode!=',')
1752 switch (*mode++)
1753 {
1754 case 'B': case 'b':
1755 *open_flags |= _O_BINARY;
1756 *open_flags &= ~_O_TEXT;
1757 break;
1758 case 't':
1759 *open_flags |= _O_TEXT;
1760 *open_flags &= ~_O_BINARY;
1761 break;
1762#if _MSVCR_VER>=140
1763 case 'x':
1764 if(!MSVCRT_CHECK_PMT((*open_flags & (_O_CREAT | _O_APPEND)) == _O_CREAT))
1765 return -1;
1766 *open_flags |= _O_EXCL;
1767 break;
1768#endif
1769 case 'D':
1770 *open_flags |= _O_TEMPORARY;
1771 break;
1772 case 'T':
1773 *open_flags |= _O_SHORT_LIVED;
1774 break;
1775 case 'c':
1776 *stream_flags |= MSVCRT__IOCOMMIT;
1777 break;
1778 case 'n':
1779 *stream_flags &= ~MSVCRT__IOCOMMIT;
1780 break;
1781 case 'N':
1782 *open_flags |= _O_NOINHERIT;
1783 break;
1784 case '+':
1785 case ' ':
1786 case 'a':
1787 case 'w':
1788 break;
1789 case 'S':
1790 if (!(*open_flags & _O_RANDOM))
1791 *open_flags |= _O_SEQUENTIAL;
1792 break;
1793 case 'R':
1794 if (!(*open_flags & _O_SEQUENTIAL))
1795 *open_flags |= _O_RANDOM;
1796 break;
1797 default:
1798 ERR("incorrect mode flag: %c\n", mode[-1]);
1799 break;
1800 }
1801
1802 if(*mode == ',')
1803 {
1804 mode++;
1805 while(*mode == ' ') mode++;
1806 if(!MSVCRT_CHECK_PMT(!wcsncmp(L"ccs", mode, 3)))
1807 return -1;
1808 mode += 3;
1809 while(*mode == ' ') mode++;
1810 if(!MSVCRT_CHECK_PMT(*mode == '='))
1811 return -1;
1812 mode++;
1813 while(*mode == ' ') mode++;
1814
1815 if(!_wcsnicmp(L"utf-8", mode, 5))
1816 {
1817 *open_flags |= _O_U8TEXT;
1818 mode += 5;
1819 }
1820 else if(!_wcsnicmp(L"utf-16le", mode, 8))
1821 {
1822 *open_flags |= _O_U16TEXT;
1823 mode += 8;
1824 }
1825 else if(!_wcsnicmp(L"unicode", mode, 7))
1826 {
1827 *open_flags |= _O_WTEXT;
1828 mode += 7;
1829 }
1830 else
1831 {
1833 return -1;
1834 }
1835
1836 while(*mode == ' ') mode++;
1837 }
1838
1839 if(!MSVCRT_CHECK_PMT(*mode == 0))
1840 return -1;
1841 return 0;
1842}
#define _O_APPEND
Definition: cabinet.h:41
#define wcschr
Definition: compat.h:17
unsigned int MSVCRT__commode
Definition: data.c:33
_ACRTIMP int __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:518
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:195
#define MSVCRT_INVALID_PMT(x, err)
Definition: msvcrt.h:376

Referenced by _wfdopen(), _wfreopen(), and _wfsopen().

◆ msvcrt_init_fp()

static int msvcrt_init_fp ( FILE file,
int  fd,
unsigned  stream_flags 
)
static

Definition at line 649 of file file.c.

650{
651 TRACE(":fd (%d) allocating FILE*\n",fd);
652 if (!(get_ioinfo_nolock(fd)->wxflag & WX_OPEN))
653 {
654 WARN(":invalid fd %d\n",fd);
655 *__doserrno() = 0;
656 *_errno() = EBADF;
657 return -1;
658 }
659 file->_ptr = file->_base = NULL;
660 file->_cnt = 0;
661 file->_file = fd;
662 file->_flag = stream_flags;
663 file->_tmpfname = NULL;
664
665 TRACE(":got FILE* (%p)\n",file);
666 return 0;
667}
__msvcrt_ulong *CDECL __doserrno(void)
Definition: errno.c:223

Referenced by _wfdopen(), _wfreopen(), _wfsopen(), and tmpfile().

◆ msvcrt_init_io()

void msvcrt_init_io ( void  )

Definition at line 720 of file file.c.

721{
722 STARTUPINFOA si;
723 int i;
724 ioinfo *fdinfo;
725
726 GetStartupInfoA(&si);
727 if (si.cbReserved2 >= sizeof(unsigned int) && si.lpReserved2 != NULL)
728 {
729 BYTE* wxflag_ptr;
730 HANDLE* handle_ptr;
731 unsigned int count;
732
733 count = *(unsigned*)si.lpReserved2;
734 wxflag_ptr = si.lpReserved2 + sizeof(unsigned);
735 handle_ptr = (HANDLE*)(wxflag_ptr + count);
736
737 count = min(count, (si.cbReserved2 - sizeof(unsigned)) / (sizeof(HANDLE) + 1));
739 for (i = 0; i < count; i++)
740 {
741 if ((*wxflag_ptr & WX_OPEN) && GetFileType(*handle_ptr) != FILE_TYPE_UNKNOWN)
742 {
743 fdinfo = get_ioinfo_alloc_fd(i);
744 if(fdinfo != &MSVCRT___badioinfo)
745 msvcrt_set_fd(fdinfo, *handle_ptr, *wxflag_ptr);
746 release_ioinfo(fdinfo);
747 }
748
749 wxflag_ptr++; handle_ptr++;
750 }
751 }
752
754 if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) {
758
759 if (type == FILE_TYPE_UNKNOWN) {
761 flags |= WX_TTY;
762 } else if ((type & 0xf) == FILE_TYPE_CHAR) {
763 flags |= WX_TTY;
764 } else if ((type & 0xf) == FILE_TYPE_PIPE) {
765 flags |= WX_PIPE;
766 }
767
768 msvcrt_set_fd(fdinfo, h, flags);
769 }
770 release_ioinfo(fdinfo);
771
773 if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) {
777
778 if (type == FILE_TYPE_UNKNOWN) {
780 flags |= WX_TTY;
781 } else if ((type & 0xf) == FILE_TYPE_CHAR) {
782 flags |= WX_TTY;
783 } else if ((type & 0xf) == FILE_TYPE_PIPE) {
784 flags |= WX_PIPE;
785 }
786
787 msvcrt_set_fd(fdinfo, h, flags);
788 }
789 release_ioinfo(fdinfo);
790
792 if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) {
796
797 if (type == FILE_TYPE_UNKNOWN) {
799 flags |= WX_TTY;
800 } else if ((type & 0xf) == FILE_TYPE_CHAR) {
801 flags |= WX_TTY;
802 } else if ((type & 0xf) == FILE_TYPE_PIPE) {
803 flags |= WX_PIPE;
804 }
805
806 msvcrt_set_fd(fdinfo, h, flags);
807 }
808 release_ioinfo(fdinfo);
809
810 TRACE(":handles (%p)(%p)(%p)\n", get_ioinfo_nolock(STDIN_FILENO)->handle,
813
814 for (i = 0; i < 3; i++)
815 {
816 FILE *f = iob_get_file(i);
818
819 /* FILE structs for stdin/out/err are static and never deleted */
822 f->_tmpfname = NULL;
823 f->_flag = (i == 0) ? _IOREAD : _IOWRT;
824
825 if (cs)
826 {
828 cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": file_crit.crit");
829 }
830 }
832}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
VOID WINAPI GetStartupInfoA(IN LPSTARTUPINFOA lpStartupInfo)
Definition: proc.c:1320
#define STDIN_FILENO
Definition: stdio.h:24
#define MSVCRT_NO_CONSOLE
Definition: msvcrt.h:328
#define min(a, b)
Definition: monoChain.cc:55
unsigned char BYTE
Definition: xxhash.c:193

Referenced by DllMain().

◆ msvcrt_int_to_base32()

static int msvcrt_int_to_base32 ( int  num,
char str 
)
static

Definition at line 919 of file file.c.

920{
921 char *p;
922 int n = num;
923 int digits = 0;
924
925 while (n != 0)
926 {
927 n >>= 5;
928 digits++;
929 }
930 p = str + digits;
931 *p = 0;
932 while (--p >= str)
933 {
934 *p = (num & 31) + '0';
935 if (*p > '9')
936 *p += ('a' - '0' - 10);
937 num >>= 5;
938 }
939
940 return digits;
941}
GLdouble n
Definition: glext.h:7729
GLuint GLuint num
Definition: glext.h:9618
static const int digits[]
Definition: decode.c:71
const WCHAR * str

Referenced by tmpnam(), and tmpnam_helper().

◆ msvcrt_int_to_base32_w()

static int msvcrt_int_to_base32_w ( int  num,
wchar_t str 
)
static

Definition at line 944 of file file.c.

945{
946 wchar_t *p;
947 int n = num;
948 int digits = 0;
949
950 while (n != 0)
951 {
952 n >>= 5;
953 digits++;
954 }
955 p = str + digits;
956 *p = 0;
957 while (--p >= str)
958 {
959 *p = (num & 31) + '0';
960 if (*p > '9')
961 *p += ('a' - '0' - 10);
962 num >>= 5;
963 }
964
965 return digits;
966}

Referenced by _wtmpnam(), and wtmpnam_helper().

◆ msvcrt_set_fd()

static void msvcrt_set_fd ( ioinfo fdinfo,
HANDLE  hand,
int  flag 
)
static

Definition at line 576 of file file.c.

577{
578 fdinfo->handle = hand;
580 fdinfo->lookahead[0] = '\n';
581 fdinfo->lookahead[1] = '\n';
582 fdinfo->lookahead[2] = '\n';
583 ioinfo_set_unicode(fdinfo, FALSE);
585
586 if (hand != MSVCRT_NO_CONSOLE)
587 {
588 switch (fdinfo-MSVCRT___pioinfo[0])
589 {
590 case 0: SetStdHandle(STD_INPUT_HANDLE, hand); break;
591 case 1: SetStdHandle(STD_OUTPUT_HANDLE, hand); break;
592 case 2: SetStdHandle(STD_ERROR_HANDLE, hand); break;
593 }
594 }
595}
char lookahead[3]
Definition: file.c:131

Referenced by _dup2(), msvcrt_alloc_fd(), and msvcrt_init_io().

◆ msvcrt_stat64_to_stat()

static void msvcrt_stat64_to_stat ( const struct _stat64 buf64,
struct _stat buf 
)
static

Definition at line 309 of file file.c.

310{
311 buf->st_dev = buf64->st_dev;
312 buf->st_ino = buf64->st_ino;
313 buf->st_mode = buf64->st_mode;
314 buf->st_nlink = buf64->st_nlink;
315 buf->st_uid = buf64->st_uid;
316 buf->st_gid = buf64->st_gid;
317 buf->st_rdev = buf64->st_rdev;
318 buf->st_size = buf64->st_size;
319 buf->st_atime = buf64->st_atime;
320 buf->st_mtime = buf64->st_mtime;
321 buf->st_ctime = buf64->st_ctime;
322}
__int64 st_size
Definition: stat.h:78
__time64_t st_ctime
Definition: stat.h:147
__time64_t st_mtime
Definition: stat.h:146
short st_uid
Definition: stat.h:141
__time64_t st_atime
Definition: stat.h:145
_dev_t st_dev
Definition: stat.h:137
short st_gid
Definition: stat.h:142
unsigned short st_mode
Definition: stat.h:139
short st_nlink
Definition: stat.h:140
_dev_t st_rdev
Definition: stat.h:143
_ino_t st_ino
Definition: stat.h:138

Referenced by _fstat(), _stat(), and _wstat().

◆ msvcrt_stat64_to_stat32()

static void msvcrt_stat64_to_stat32 ( const struct _stat64 buf64,
struct _stat32 buf 
)
static

Definition at line 339 of file file.c.

340{
341 buf->st_dev = buf64->st_dev;
342 buf->st_ino = buf64->st_ino;
343 buf->st_mode = buf64->st_mode;
344 buf->st_nlink = buf64->st_nlink;
345 buf->st_uid = buf64->st_uid;
346 buf->st_gid = buf64->st_gid;
347 buf->st_rdev = buf64->st_rdev;
348 buf->st_size = buf64->st_size;
349 buf->st_atime = buf64->st_atime;
350 buf->st_mtime = buf64->st_mtime;
351 buf->st_ctime = buf64->st_ctime;
352}

Referenced by _fstat32().

◆ msvcrt_stat64_to_stat32i64()

static void msvcrt_stat64_to_stat32i64 ( const struct _stat64 buf64,
struct _stat32i64 buf 
)
static

Definition at line 369 of file file.c.

370{
371 buf->st_dev = buf64->st_dev;
372 buf->st_ino = buf64->st_ino;
373 buf->st_mode = buf64->st_mode;
374 buf->st_nlink = buf64->st_nlink;
375 buf->st_uid = buf64->st_uid;
376 buf->st_gid = buf64->st_gid;
377 buf->st_rdev = buf64->st_rdev;
378 buf->st_size = buf64->st_size;
379 buf->st_atime = buf64->st_atime;
380 buf->st_mtime = buf64->st_mtime;
381 buf->st_ctime = buf64->st_ctime;
382}

Referenced by _fstat32i64().

◆ msvcrt_stat64_to_stat64i32()

static void msvcrt_stat64_to_stat64i32 ( const struct _stat64 buf64,
struct _stat64i32 buf 
)
static

Definition at line 354 of file file.c.

355{
356 buf->st_dev = buf64->st_dev;
357 buf->st_ino = buf64->st_ino;
358 buf->st_mode = buf64->st_mode;
359 buf->st_nlink = buf64->st_nlink;
360 buf->st_uid = buf64->st_uid;
361 buf->st_gid = buf64->st_gid;
362 buf->st_rdev = buf64->st_rdev;
363 buf->st_size = buf64->st_size;
364 buf->st_atime = buf64->st_atime;
365 buf->st_mtime = buf64->st_mtime;
366 buf->st_ctime = buf64->st_ctime;
367}

Referenced by _fstat64i32().

◆ msvcrt_stat64_to_stati64()

static void msvcrt_stat64_to_stati64 ( const struct _stat64 buf64,
struct _stati64 buf 
)
static

Definition at line 324 of file file.c.

325{
326 buf->st_dev = buf64->st_dev;
327 buf->st_ino = buf64->st_ino;
328 buf->st_mode = buf64->st_mode;
329 buf->st_nlink = buf64->st_nlink;
330 buf->st_uid = buf64->st_uid;
331 buf->st_gid = buf64->st_gid;
332 buf->st_rdev = buf64->st_rdev;
333 buf->st_size = buf64->st_size;
334 buf->st_atime = buf64->st_atime;
335 buf->st_mtime = buf64->st_mtime;
336 buf->st_ctime = buf64->st_ctime;
337}

Referenced by _fstati64(), _stati64(), and _wstati64().

◆ printf()

int WINAPIV printf ( const char format,
  ... 
)

Definition at line 5706 of file file.c.

5707{
5709 int res;
5712 va_end(valist);
5713 return res;
5714}

◆ printf_s()

int WINAPIV printf_s ( const char format,
  ... 
)

Definition at line 5719 of file file.c.

5720{
5722 int res;
5725 va_end(valist);
5726 return res;
5727}
int CDECL vprintf_s(const char *format, va_list valist)
Definition: file.c:5525

◆ putc()

int CDECL putc ( int  c,
FILE file 
)

◆ putchar()

int CDECL putchar ( int  c)

Definition at line 4915 of file file.c.

4916{
4917 return fputc(c, stdout);
4918}

◆ puts()

int CDECL puts ( const char s)

Definition at line 4923 of file file.c.

4924{
4925 size_t len = strlen(s);
4926 int ret;
4927
4929 if(_fwrite_nolock(s, sizeof(*s), len, stdout) != len) {
4931 return EOF;
4932 }
4933
4934 ret = _fwrite_nolock("\n",1,1,stdout) == 1 ? 0 : EOF;
4936 return ret;
4937}

◆ puts_clbk_file_a()

static int puts_clbk_file_a ( void file,
int  len,
const char str 
)
static

Definition at line 5236 of file file.c.

5237{
5238 return fwrite(str, sizeof(char), len, file);
5239}
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:4129

Referenced by vfprintf_helper().

◆ puts_clbk_file_w()

static int puts_clbk_file_w ( void file,
int  len,
const wchar_t str 
)
static

Definition at line 5241 of file file.c.

5242{
5243 int i, ret;
5244
5246
5247 if(!(get_ioinfo_nolock(((FILE*)file)->_file)->wxflag & WX_TEXT)) {
5248 ret = _fwrite_nolock(str, sizeof(wchar_t), len, file);
5250 return ret;
5251 }
5252
5253 for(i=0; i<len; i++) {
5254 if(_fputwc_nolock(str[i], file) == WEOF) {
5256 return -1;
5257 }
5258 }
5259
5261 return len;
5262}

Referenced by vfwprintf_helper().

◆ read_i()

static int read_i ( int  fd,
ioinfo fdinfo,
void buf,
unsigned int  count 
)
static

Definition at line 2964 of file file.c.

2965{
2966 DWORD num_read, utf16;
2967 char *bufstart = buf;
2968
2969 if (count == 0)
2970 return 0;
2971
2972 if (fdinfo->wxflag & WX_ATEOF) {
2973 TRACE("already at EOF, returning 0\n");
2974 return 0;
2975 }
2976 /* Don't trace small reads, it gets *very* annoying */
2977 if (count > 4)
2978 TRACE(":fd (%d) handle (%p) buf (%p) len (%d)\n", fd, fdinfo->handle, buf, count);
2979 if (fdinfo->handle == INVALID_HANDLE_VALUE)
2980 {
2981 *_errno() = EBADF;
2982 return -1;
2983 }
2984
2985 utf16 = ioinfo_get_textmode(fdinfo) == TEXTMODE_UTF16LE;
2986 if (ioinfo_get_textmode(fdinfo) != TEXTMODE_ANSI && count&1)
2987 {
2988 *_errno() = EINVAL;
2989 return -1;
2990 }
2991
2992 if((fdinfo->wxflag&WX_TEXT) && ioinfo_get_textmode(fdinfo) == TEXTMODE_UTF8)
2993 return read_utf8(fdinfo, buf, count);
2994
2995 if (fdinfo->lookahead[0]!='\n' || ReadFile(fdinfo->handle, bufstart, count, &num_read, NULL))
2996 {
2997 if (fdinfo->lookahead[0] != '\n')
2998 {
2999 bufstart[0] = fdinfo->lookahead[0];
3000 fdinfo->lookahead[0] = '\n';
3001
3002 if (utf16)
3003 {
3004 bufstart[1] = fdinfo->lookahead[1];
3005 fdinfo->lookahead[1] = '\n';
3006 }
3007
3008 if(count>1+utf16 && ReadFile(fdinfo->handle, bufstart+1+utf16, count-1-utf16, &num_read, NULL))
3009 num_read += 1+utf16;
3010 else
3011 num_read = 1+utf16;
3012 }
3013
3014 if(utf16 && (num_read&1))
3015 {
3016 /* msvcr90 uses uninitialized value from the buffer in this case */
3017 /* msvcrt ignores additional data */
3018 ERR("got odd number of bytes in UTF16 mode\n");
3019 num_read--;
3020 }
3021
3022 if (count != 0 && num_read == 0)
3023 {
3024 fdinfo->wxflag |= WX_ATEOF;
3025 TRACE(":EOF %s\n",debugstr_an(buf,num_read));
3026 }
3027 else if (fdinfo->wxflag & WX_TEXT)
3028 {
3029 DWORD i, j;
3030
3031 if (bufstart[0]=='\n' && (!utf16 || bufstart[1]==0))
3032 fdinfo->wxflag |= WX_READNL;
3033 else
3034 fdinfo->wxflag &= ~WX_READNL;
3035
3036 for (i=0, j=0; i<num_read; i+=1+utf16)
3037 {
3038 /* in text mode, a ctrl-z signals EOF */
3039 if (bufstart[i]==0x1a && (!utf16 || bufstart[i+1]==0))
3040 {
3041 fdinfo->wxflag |= WX_ATEOF;
3042 TRACE(":^Z EOF %s\n",debugstr_an(buf,num_read));
3043 break;
3044 }
3045
3046 /* in text mode, strip \r if followed by \n */
3047 if (bufstart[i]=='\r' && (!utf16 || bufstart[i+1]==0) && i+1+utf16==num_read)
3048 {
3049 char lookahead[2];
3050 DWORD len;
3051
3052 lookahead[1] = '\n';
3053 if (ReadFile(fdinfo->handle, lookahead, 1+utf16, &len, NULL) && len)
3054 {
3055 if(lookahead[0]=='\n' && (!utf16 || lookahead[1]==0) && j==0)
3056 {
3057 bufstart[j++] = '\n';
3058 if(utf16) bufstart[j++] = 0;
3059 }
3060 else
3061 {
3062 if(lookahead[0]!='\n' || (utf16 && lookahead[1]!=0))
3063 {
3064 bufstart[j++] = '\r';
3065 if(utf16) bufstart[j++] = 0;
3066 }
3067
3068 if (fdinfo->wxflag & (WX_PIPE | WX_TTY))
3069 {
3070 if (lookahead[0]=='\n' && (!utf16 || !lookahead[1]))
3071 {
3072 bufstart[j++] = '\n';
3073 if (utf16) bufstart[j++] = 0;
3074 }
3075 else
3076 {
3077 fdinfo->lookahead[0] = lookahead[0];
3078 fdinfo->lookahead[1] = lookahead[1];
3079 }
3080 }
3081 else
3082 SetFilePointer(fdinfo->handle, -1-utf16, NULL, FILE_CURRENT);
3083 }
3084 }
3085 else
3086 {
3087 bufstart[j++] = '\r';
3088 if(utf16) bufstart[j++] = 0;
3089 }
3090 }
3091 else if((bufstart[i]!='\r' || (utf16 && bufstart[i+1]!=0))
3092 || (bufstart[i+1+utf16]!='\n' || (utf16 && bufstart[i+3]!=0)))
3093 {
3094 bufstart[j++] = bufstart[i];
3095 if(utf16) bufstart[j++] = bufstart[i+1];
3096 }
3097 }
3098 num_read = j;
3099 }
3100 }
3101 else
3102 {
3104 {
3105 TRACE(":end-of-pipe\n");
3106 fdinfo->wxflag |= WX_ATEOF;
3107 return 0;
3108 }
3109 else
3110 {
3111 TRACE(":failed-last error (%ld)\n", GetLastError());
3114 *_errno() = EBADF;
3115 return -1;
3116 }
3117 }
3118
3119 if (count > 4)
3120 TRACE("(%lu), %s\n", num_read, debugstr_an(buf, num_read));
3121 return num_read;
3122}
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
static int read_utf8(ioinfo *fdinfo, wchar_t *buf, unsigned int count)
Definition: file.c:2784
#define ERROR_BROKEN_PIPE
Definition: winerror.h:305

Referenced by _read().

◆ read_utf8()

static int read_utf8 ( ioinfo fdinfo,
wchar_t buf,
unsigned int  count 
)
static

Definition at line 2784 of file file.c.

2785{
2786 HANDLE hand = fdinfo->handle;
2787 char min_buf[4], *readbuf, lookahead;
2788 DWORD readbuf_size, pos=0, num_read=1, char_len, i, j;
2789
2790 /* make the buffer big enough to hold at least one character */
2791 /* read bytes have to fit to output and lookahead buffers */
2792 count /= 2;
2793 readbuf_size = count < 4 ? 4 : count;
2794 if(readbuf_size<=4 || !(readbuf = malloc(readbuf_size))) {
2795 readbuf_size = 4;
2796 readbuf = min_buf;
2797 }
2798
2799 if(fdinfo->lookahead[0] != '\n') {
2800 readbuf[pos++] = fdinfo->lookahead[0];
2801 fdinfo->lookahead[0] = '\n';
2802
2803 if(fdinfo->lookahead[1] != '\n') {
2804 readbuf[pos++] = fdinfo->lookahead[1];
2805 fdinfo->lookahead[1] = '\n';
2806
2807 if(fdinfo->lookahead[2] != '\n') {
2808 readbuf[pos++] = fdinfo->lookahead[2];
2809 fdinfo->lookahead[2] = '\n';
2810 }
2811 }
2812 }
2813
2814 /* NOTE: this case is broken in native dll, reading
2815 * sometimes fails when small buffer is passed
2816 */
2817 if(count < 4) {
2818 if(!pos && !ReadFile(hand, readbuf, 1, &num_read, NULL)) {
2820 fdinfo->wxflag |= WX_ATEOF;
2821 return 0;
2822 }else {
2825 *_errno() = EBADF;
2826 return -1;
2827 }
2828 }else if(!num_read) {
2829 fdinfo->wxflag |= WX_ATEOF;
2830 return 0;
2831 }else {
2832 pos++;
2833 }
2834
2835 char_len = get_utf8_char_len(readbuf[0]);
2836 if(char_len>pos) {
2837 if(ReadFile(hand, readbuf+pos, char_len-pos, &num_read, NULL))
2838 pos += num_read;
2839 }
2840
2841 if(readbuf[0] == '\n')
2842 fdinfo->wxflag |= WX_READNL;
2843 else
2844 fdinfo->wxflag &= ~WX_READNL;
2845
2846 if(readbuf[0] == 0x1a) {
2847 fdinfo->wxflag |= WX_ATEOF;
2848 return 0;
2849 }
2850
2851 if(readbuf[0] == '\r') {
2852 if(!ReadFile(hand, &lookahead, 1, &num_read, NULL) || num_read!=1)
2853 buf[0] = '\r';
2854 else if(lookahead == '\n')
2855 buf[0] = '\n';
2856 else {
2857 buf[0] = '\r';
2858 if(fdinfo->wxflag & (WX_PIPE | WX_TTY))
2859 fdinfo->lookahead[0] = lookahead;
2860 else
2861 SetFilePointer(fdinfo->handle, -1, NULL, FILE_CURRENT);
2862 }
2863 return 2;
2864 }
2865
2866 if(!(num_read = MultiByteToWideChar(CP_UTF8, 0, readbuf, pos, buf, count))) {
2868 return -1;
2869 }
2870
2871 return num_read*2;
2872 }
2873
2874 if(!ReadFile(hand, readbuf+pos, readbuf_size-pos, &num_read, NULL)) {
2875 if(pos) {
2876 num_read = 0;
2877 }else if(GetLastError() == ERROR_BROKEN_PIPE) {
2878 fdinfo->wxflag |= WX_ATEOF;
2879 if (readbuf != min_buf) free(readbuf);
2880 return 0;
2881 }else {
2884 *_errno() = EBADF;
2885 if (readbuf != min_buf) free(readbuf);
2886 return -1;
2887 }
2888 }else if(!pos && !num_read) {
2889 fdinfo->wxflag |= WX_ATEOF;
2890 if (readbuf != min_buf) free(readbuf);
2891 return 0;
2892 }
2893
2894 pos += num_read;
2895 if(readbuf[0] == '\n')
2896 fdinfo->wxflag |= WX_READNL;
2897 else
2898 fdinfo->wxflag &= ~WX_READNL;
2899
2900 /* Find first byte of last character (may be incomplete) */
2901 for(i=pos-1; i>0 && i>pos-4; i--)
2902 if((readbuf[i]&0xc0) != 0x80)
2903 break;
2904 char_len = get_utf8_char_len(readbuf[i]);
2905 if(char_len+i <= pos)
2906 i += char_len;
2907
2908 if(fdinfo->wxflag & (WX_PIPE | WX_TTY)) {
2909 if(i < pos)
2910 fdinfo->lookahead[0] = readbuf[i];
2911 if(i+1 < pos)
2912 fdinfo->lookahead[1] = readbuf[i+1];
2913 if(i+2 < pos)
2914 fdinfo->lookahead[2] = readbuf[i+2];
2915 }else if(i < pos) {
2917 }
2918 pos = i;
2919
2920 for(i=0, j=0; i<pos; i++) {
2921 if(readbuf[i] == 0x1a) {
2922 fdinfo->wxflag |= WX_ATEOF;
2923 break;
2924 }
2925
2926 /* strip '\r' if followed by '\n' */
2927 if(readbuf[i] == '\r' && i+1==pos) {
2928 if(fdinfo->lookahead[0] != '\n' || !ReadFile(hand, &lookahead, 1, &num_read, NULL) || !num_read) {
2929 readbuf[j++] = '\r';
2930 }else if(lookahead == '\n' && j==0) {
2931 readbuf[j++] = '\n';
2932 }else {
2933 if(lookahead != '\n')
2934 readbuf[j++] = '\r';
2935
2936 if(fdinfo->wxflag & (WX_PIPE | WX_TTY))
2937 fdinfo->lookahead[0] = lookahead;
2938 else
2939 SetFilePointer(fdinfo->handle, -1, NULL, FILE_CURRENT);
2940 }
2941 }else if(readbuf[i]!='\r' || readbuf[i+1]!='\n') {
2942 readbuf[j++] = readbuf[i];
2943 }
2944 }
2945 pos = j;
2946
2947 if(!(num_read = MultiByteToWideChar(CP_UTF8, 0, readbuf, pos, buf, count))) {
2949 if (readbuf != min_buf) free(readbuf);
2950 return -1;
2951 }
2952
2953 if (readbuf != min_buf) free(readbuf);
2954 return num_read*2;
2955}
#define MultiByteToWideChar
Definition: compat.h:110
static int get_utf8_char_len(char ch)
Definition: file.c:2770

Referenced by read_i().

◆ release_ioinfo()

static void release_ioinfo ( ioinfo info)
inlinestatic

◆ remove()

int CDECL remove ( const char path)

Definition at line 4957 of file file.c.

4958{
4959 return _unlink(path);
4960}
int CDECL _unlink(const char *path)
Definition: file.c:1085

◆ remove_std_buffer()

static void remove_std_buffer ( FILE file)
static

Definition at line 910 of file file.c.

911{
913 file->_ptr = file->_base = NULL;
914 file->_bufsiz = file->_cnt = 0;
915 file->_flag &= ~MSVCRT__USERBUF;
916}

Referenced by fputws(), vfprintf_helper(), and vfwprintf_helper().

◆ rename()

int CDECL rename ( const char oldpath,
const char newpath 
)

Definition at line 4973 of file file.c.

4974{
4975 wchar_t *oldpathW = NULL, *newpathW = NULL;
4976 int ret;
4977
4978 if (oldpath && !(oldpathW = wstrdupa_utf8(oldpath))) return -1;
4979 if (newpath && !(newpathW = wstrdupa_utf8(newpath)))
4980 {
4981 free(oldpathW);
4982 return -1;
4983 }
4984 ret = _wrename(oldpathW, newpathW);
4985 free(oldpathW);
4986 free(newpathW);
4987 return ret;
4988}
int CDECL _wrename(const wchar_t *oldpath, const wchar_t *newpath)
Definition: file.c:4993

Referenced by CloseTrace(), disk_set_information(), EndLog(), handle_nfs41_rename(), LocalRenameCmd(), OpenBookmarkFile(), printercache_rename_blob(), save_licence(), SavePrefs(), SpoolX(), and SwapBookmarkFiles().

◆ rewind()

void CDECL rewind ( FILE file)

Definition at line 1712 of file file.c.

1713{
1714 TRACE(":file (%p) fd (%d)\n",file,file->_file);
1715
1718 clearerr(file);
1720}
void CDECL clearerr(FILE *file)
Definition: file.c:1672
int CDECL _fseek_nolock(FILE *file, __msvcrt_long offset, int whence)
Definition: file.c:1618

Referenced by compare_export_(), FileSize(), main(), rewrite_client_leases(), setrpcent(), test_asciimode(), test_fgetc(), test_filemodeT(), test_fileops(), test_readmode(), and test_write_flush_size().

◆ setbuf()

void CDECL setbuf ( FILE file,
char buf 
)

Definition at line 5046 of file file.c.

5047{
5049}
int CDECL setvbuf(FILE *file, char *buf, int mode, size_t size)
Definition: file.c:5006
#define _IONBF
Definition: stdio.h:30
#define _IOFBF
Definition: stdio.h:29

Referenced by _fcons(), _Filebuf_base::_M_open(), DllMain(), main(), set_LogFile(), test_fgetc(), and test_flsbuf().

◆ setvbuf()

int CDECL setvbuf ( FILE file,
char buf,
int  mode,
size_t  size 
)

Definition at line 5006 of file file.c.

5007{
5008 if(!MSVCRT_CHECK_PMT(file != NULL)) return -1;
5009 if(!MSVCRT_CHECK_PMT(mode==_IONBF || mode==_IOFBF || mode==_IOLBF)) return -1;
5010 if(!MSVCRT_CHECK_PMT(mode==_IONBF || (size>=2 && size<=INT_MAX))) return -1;
5011
5013
5015 if(file->_flag & _IOMYBUF)
5016 free(file->_base);
5017 file->_flag &= ~(MSVCRT__NOBUF | _IOMYBUF | MSVCRT__USERBUF);
5018 file->_cnt = 0;
5019
5020 if(mode == _IONBF) {
5021 file->_flag |= MSVCRT__NOBUF;
5022 file->_base = file->_ptr = (char*)&file->_charbuf;
5023 file->_bufsiz = 2;
5024 }else if(buf) {
5025 file->_base = file->_ptr = buf;
5026 file->_flag |= MSVCRT__USERBUF;
5027 file->_bufsiz = size;
5028 }else {
5029 file->_base = file->_ptr = malloc(size);
5030 if(!file->_base) {
5031 file->_bufsiz = 0;
5033 return -1;
5034 }
5035
5036 file->_flag |= _IOMYBUF;
5037 file->_bufsiz = size;
5038 }
5040 return 0;
5041}
#define _IOLBF
Definition: stdio.h:31

Referenced by _tWinMain(), fileClient(), main(), OpenTrace(), pipeClient(), processRequest(), setbuf(), test_fileops(), test_flsbuf(), test_iobuf_layout(), test_std_stream_buffering(), test_write_flush(), and throw().

◆ split_oflags()

static unsigned split_oflags ( unsigned  oflags)
static

Definition at line 2293 of file file.c.

2294{
2295 int wxflags = 0;
2296 unsigned unsupp; /* until we support everything */
2297
2298 if (oflags & _O_APPEND) wxflags |= WX_APPEND;
2299 if (oflags & _O_BINARY) {/* Nothing to do */}
2300 else if (oflags & _O_TEXT) wxflags |= WX_TEXT;
2301 else if (oflags & _O_WTEXT) wxflags |= WX_TEXT;
2302 else if (oflags & _O_U16TEXT) wxflags |= WX_TEXT;
2303 else if (oflags & _O_U8TEXT) wxflags |= WX_TEXT;
2304 else
2305 {
2306 int fmode;
2307 _get_fmode(&fmode);
2308 if (!(fmode & _O_BINARY)) wxflags |= WX_TEXT; /* default to TEXT*/
2309 }
2310 if (oflags & _O_NOINHERIT) wxflags |= WX_DONTINHERIT;
2311
2312 if ((unsupp = oflags & ~(_O_BINARY | _O_TEXT | _O_APPEND | _O_TRUNC | _O_EXCL | _O_CREAT |
2315 ERR(":unsupported oflags %#x\n",unsupp);
2316
2317 return wxflags;
2318}
int CDECL _get_fmode(int *mode)
Definition: data.c:287

Referenced by _open_osfhandle(), _pipe(), _wsopen_dispatch(), and _wsopen_s().

◆ time_to_filetime()

static void time_to_filetime ( __time64_t  time,
FILETIME ft 
)
static

Definition at line 384 of file file.c.

385{
386 /* 1601 to 1970 is 369 years plus 89 leap days */
387 static const __int64 secs_1601_to_1970 = ((369 * 365 + 89) * (__int64)86400);
388
389 __int64 ticks = (time + secs_1601_to_1970) * 10000000;
390 ft->dwHighDateTime = ticks >> 32;
391 ft->dwLowDateTime = ticks;
392}
__u16 time
Definition: mkdosfs.c:8
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65

Referenced by _futime64().

◆ tmpfile()

FILE *CDECL tmpfile ( void  )

Definition at line 5199 of file file.c.

5200{
5201 char *filename = _tempnam(",", "t");
5202 int fd;
5203 FILE* file = NULL;
5204
5205 LOCK_FILES();
5208 if (fd != -1 && (file = msvcrt_alloc_fp()))
5209 {
5210 if (msvcrt_init_fp(file, fd, _IORW) == -1)
5211 {
5212 file->_flag = 0;
5213 file = NULL;
5214 }
5215 else file->_tmpfname = _strdup(filename);
5216 }
5217
5218 if(fd != -1 && !file)
5219 _close(fd);
5220 free(filename);
5221 UNLOCK_FILES();
5222 return file;
5223}
#define _strdup
Definition: debug_ros.c:7
char *CDECL _tempnam(const char *dir, const char *prefix)
Definition: file.c:3441

Referenced by CCFDATAStorage::Create(), create_temp_binary(), HANDLE_CustomType7(), jpeg_open_backing_store(), JSPROXY_InternetInitializeAutoProxyDll(), open_file_test(), patch_file(), test_color_contexts(), test_CreateDirectoryA(), test_CryptCATAdminAddRemoveCatalog(), test_GetNamedSecurityInfoA(), test_install_class(), test_retrieveObjectByUrl(), test_SetupCopyOEMInf(), tmpfile_s(), transfer_file_http(), CCFDATAStorage::Truncate(), VerInstallFileA(), and VerInstallFileW().

◆ tmpfile_s()

int CDECL tmpfile_s ( FILE **  file)

Definition at line 5228 of file file.c.

5229{
5230 if (!MSVCRT_CHECK_PMT(file != NULL)) return EINVAL;
5231
5232 *file = tmpfile();
5233 return 0;
5234}
FILE *CDECL tmpfile(void)
Definition: file.c:5199

◆ tmpnam()

char *CDECL tmpnam ( char s)

Definition at line 5108 of file file.c.

5109{
5110 if (!s) {
5112
5113 if(!data->tmpnam_buffer)
5114 data->tmpnam_buffer = malloc(MAX_PATH);
5115
5116 s = data->tmpnam_buffer;
5117 }
5118
5119 return tmpnam_helper(s, -1, &tmpnam_unique, TMP_MAX) ? NULL : s;
5120}
static int tmpnam_helper(char *s, size_t size, LONG *tmpnam_unique, int tmp_max)
Definition: file.c:5051

Referenced by CCFDATAStorage::Create(), test_tmpnam(), and tmpfile().

◆ tmpnam_helper()

static int tmpnam_helper ( char s,
size_t  size,
LONG tmpnam_unique,
int  tmp_max 
)
static

Definition at line 5051 of file file.c.

5052{
5053 char tmpstr[8];
5054 char *p = s;
5055 int digits;
5056
5057 if (!MSVCRT_CHECK_PMT(s != NULL)) return EINVAL;
5058
5059 if (size < 3) {
5060 if (size) *s = 0;
5061 *_errno() = ERANGE;
5062 return ERANGE;
5063 }
5064 *p++ = '\\';
5065 *p++ = 's';
5066 size -= 2;
5068 if (digits+1 > size) {
5069 *s = 0;
5070 *_errno() = ERANGE;
5071 return ERANGE;
5072 }
5073 memcpy(p, tmpstr, digits*sizeof(tmpstr[0]));
5074 p += digits;
5075 *p++ = '.';
5076 size -= digits+1;
5077
5078 while(1) {
5079 while ((digits = *tmpnam_unique)+1 < tmp_max) {
5081 break;
5082 }
5083
5085 if (digits+1 > size) {
5086 *s = 0;
5087 *_errno() = ERANGE;
5088 return ERANGE;
5089 }
5090 memcpy(p, tmpstr, digits*sizeof(tmpstr[0]));
5091 p[digits] = 0;
5092
5095 break;
5096 }
5097 return 0;
5098}
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:636
static int msvcrt_int_to_base32(int num, char *str)
Definition: file.c:919
#define ERANGE
Definition: errno.h:55
#define InterlockedCompareExchange
Definition: interlocked.h:119
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79

Referenced by tmpnam(), and tmpnam_s().

◆ tmpnam_s()

int CDECL tmpnam_s ( char s,
size_t  size 
)

Definition at line 5100 of file file.c.

5101{
5103}

◆ ungetc()

int CDECL ungetc ( int  c,
FILE file 
)

Definition at line 5732 of file file.c.

5733{
5734 int ret;
5735
5736 if(!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
5737
5741
5742 return ret;
5743}

Referenced by _fgetwc_nolock(), select_file_type(), test_fileops(), and ungetwc().

◆ ungetwc()

wint_t CDECL ungetwc ( wint_t  wc,
FILE file 
)

Definition at line 5783 of file file.c.

5784{
5785 wint_t ret;
5786
5787 if(!MSVCRT_CHECK_PMT(file != NULL)) return WEOF;
5788
5790 ret = _ungetwc_nolock(wc, file);
5792
5793 return ret;
5794}
wint_t CDECL _ungetwc_nolock(wint_t wc, FILE *file)
Definition: file.c:5799

◆ vfprintf()

◆ vfprintf_helper()

static int vfprintf_helper ( DWORD  options,
FILE file,
const char format,
_locale_t  locale,
va_list  valist 
)
static

Definition at line 5264 of file file.c.

5266{
5267 printf_arg args_ctx[_ARGMAX+1];
5268 BOOL tmp_buf;
5269 int ret;
5270
5271 if(!MSVCRT_CHECK_PMT( file != NULL )) return -1;
5272 if(!MSVCRT_CHECK_PMT( format != NULL )) return -1;
5273
5275 memset(args_ctx, 0, sizeof(args_ctx));
5277 if(ret < 0) {
5279 *_errno() = EINVAL;
5280 return ret;
5281 } else if(!ret)
5282 options &= ~MSVCRT_PRINTF_POSITIONAL_PARAMS;
5283 }
5284
5286 tmp_buf = add_std_buffer(file);
5290 if(tmp_buf) remove_std_buffer(file);
5292
5293 return ret;
5294}
static int puts_clbk_file_a(void *file, int len, const char *str)
Definition: file.c:5236
#define _ARGMAX
Definition: corecrt.h:157
int pf_printf_a(puts_clbk_a, void *, const char *, _locale_t, DWORD, args_clbk, void *, va_list *)
int create_positional_ctx_a(void *, const char *, va_list)
printf_arg arg_clbk_valist(void *, int, int, va_list *)
Definition: wcs.c:847
printf_arg arg_clbk_positional(void *, int, int, va_list *)
Definition: wcs.c:870

Referenced by _vfprintf_l(), _vfprintf_p_l(), _vfprintf_s_l(), and vfprintf().

◆ vfprintf_s()

int CDECL vfprintf_s ( FILE file,
const char format,
va_list  valist 
)

Definition at line 5357 of file file.c.

5358{
5359 return _vfprintf_s_l(file, format, NULL, valist);
5360}

Referenced by fprintf_s(), printf_s(), and vprintf_s().

◆ vfwprintf()

int CDECL vfwprintf ( FILE file,
const wchar_t format,
va_list  valist 
)

Definition at line 5365 of file file.c.

5366{
5367 return vfwprintf_helper(0, file, format, NULL, valist);
5368}

Referenced by _vcwprintf(), ConPrintf(), ConResPrintf(), fwprintf(), and vwprintf().

◆ vfwprintf_helper()

static int vfwprintf_helper ( DWORD  options,
FILE file,
const wchar_t format,
_locale_t  locale,
va_list  valist 
)
static

Definition at line 5296 of file file.c.

5298{
5299 printf_arg args_ctx[_ARGMAX+1];
5300 BOOL tmp_buf;
5301 int ret;
5302
5303 if(!MSVCRT_CHECK_PMT( file != NULL )) return -1;
5304 if(!MSVCRT_CHECK_PMT( format != NULL )) return -1;
5305
5307 memset(args_ctx, 0, sizeof(args_ctx));
5309 if(ret < 0) {
5311 *_errno() = EINVAL;
5312 return ret;
5313 } else if(!ret)
5314 options &= ~MSVCRT_PRINTF_POSITIONAL_PARAMS;
5315 }
5316
5318 tmp_buf = add_std_buffer(file);
5322 if(tmp_buf) remove_std_buffer(file);
5324
5325 return ret;
5326}
static int puts_clbk_file_w(void *file, int len, const wchar_t *str)
Definition: file.c:5241
int create_positional_ctx_w(void *, const wchar_t *, va_list)
int pf_printf_w(puts_clbk_w, void *, const wchar_t *, _locale_t, DWORD, args_clbk, void *, va_list *)

Referenced by _vfwprintf_l(), _vfwprintf_p_l(), _vfwprintf_s_l(), and vfwprintf().

◆ vfwprintf_s()

int CDECL vfwprintf_s ( FILE file,
const wchar_t format,
va_list  valist 
)

Definition at line 5373 of file file.c.

5374{
5376}

Referenced by fwprintf_s(), and vwprintf_s().

◆ vprintf()

int CDECL vprintf ( const char format,
va_list  valist 
)

Definition at line 5517 of file file.c.

5518{
5519 return vfprintf(stdout,format,valist);
5520}

Referenced by atltest_ok(), atltest_skip(), DbgPrint(), indent_printf(), ShimDbgPrint(), and xprintf().

◆ vprintf_s()

int CDECL vprintf_s ( const char format,
va_list  valist 
)

Definition at line 5525 of file file.c.

5526{
5528}

Referenced by printf_s().

◆ vwprintf()

int CDECL vwprintf ( const wchar_t format,
va_list  valist 
)

Definition at line 5533 of file file.c.

5534{
5535 return vfwprintf(stdout,format,valist);
5536}

Referenced by LoadAndPrintString(), and wprintf().

◆ vwprintf_s()

int CDECL vwprintf_s ( const wchar_t format,
va_list  valist 
)

Definition at line 5541 of file file.c.

5542{
5544}

Referenced by wprintf_s().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msvcrt  )

◆ wprintf()

int WINAPIV wprintf ( const wchar_t format,
  ... 
)

Definition at line 5836 of file file.c.

5837{
5839 int res;
5842 va_end(valist);
5843 return res;
5844}
int CDECL vwprintf(const wchar_t *format, va_list valist)
Definition: file.c:5533

◆ wprintf_s()

int WINAPIV wprintf_s ( const wchar_t format,
  ... 
)

Definition at line 5849 of file file.c.

5850{
5852 int res;
5855 va_end(valist);
5856 return res;
5857}
int CDECL vwprintf_s(const wchar_t *format, va_list valist)
Definition: file.c:5541

◆ wtmpnam_helper()

static int wtmpnam_helper ( wchar_t s,
size_t  size,
LONG tmpnam_unique,
int  tmp_max 
)
static

Definition at line 5122 of file file.c.

5123{
5124 wchar_t tmpstr[8];
5125 wchar_t *p = s;
5126 int digits;
5127
5128 if (!MSVCRT_CHECK_PMT(s != NULL)) return EINVAL;
5129
5130 if (size < 3) {
5131 if (size) *s = 0;
5132 *_errno() = ERANGE;
5133 return ERANGE;
5134 }
5135 *p++ = '\\';
5136 *p++ = 's';
5137 size -= 2;
5139 if (digits+1 > size) {
5140 *s = 0;
5141 *_errno() = ERANGE;
5142 return ERANGE;
5143 }
5144 memcpy(p, tmpstr, digits*sizeof(tmpstr[0]));
5145 p += digits;
5146 *p++ = '.';
5147 size -= digits+1;
5148
5149 while(1) {
5150 while ((digits = *tmpnam_unique)+1 < tmp_max) {
5152 break;
5153 }
5154
5156 if (digits+1 > size) {
5157 *s = 0;
5158 *_errno() = ERANGE;
5159 return ERANGE;
5160 }
5161 memcpy(p, tmpstr, digits*sizeof(tmpstr[0]));
5162 p[digits] = 0;
5163
5166 break;
5167 }
5168 return 0;
5169}
static int msvcrt_int_to_base32_w(int num, wchar_t *str)
Definition: file.c:944

Referenced by _wtmpnam(), and _wtmpnam_s().

Variable Documentation

◆ MSVCRT___badioinfo

◆ MSVCRT___pioinfo

ioinfo* MSVCRT___pioinfo[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { 0 }

Definition at line 155 of file file.c.

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

◆ MSVCRT__iob

FILE MSVCRT__iob[_IOB_ENTRIES] = { { 0 } }

Definition at line 263 of file file.c.

Referenced by iob_get_file().

◆ MSVCRT_file_cs

static CRITICAL_SECTION MSVCRT_file_cs = { &MSVCRT_file_cs_debug, -1, 0, 0, 0, 0 }
static

Definition at line 298 of file file.c.

◆ MSVCRT_file_cs_debug

CRITICAL_SECTION_DEBUG MSVCRT_file_cs_debug
static
Initial value:
=
{
0, 0, { (DWORD_PTR)(__FILE__ ": MSVCRT_file_cs") }
}
static CRITICAL_SECTION MSVCRT_file_cs
Definition: file.c:298
static CRITICAL_SECTION_DEBUG MSVCRT_file_cs_debug
Definition: file.c:299

Definition at line 299 of file file.c.

◆ MSVCRT_fstream

Definition at line 278 of file file.c.

Referenced by msvcrt_free_io(), and msvcrt_get_file().

◆ MSVCRT_max_streams

int MSVCRT_max_streams = 512
static

Definition at line 279 of file file.c.

Referenced by _getmaxstdio(), _setmaxstdio(), msvcrt_alloc_fp(), and msvcrt_get_file().

◆ MSVCRT_stream_idx

int MSVCRT_stream_idx
static

◆ MSVCRT_umask

int MSVCRT_umask = 0
static

Definition at line 282 of file file.c.

Referenced by _umask(), and _wsopen_dispatch().

◆ tmpnam_s_unique

LONG tmpnam_s_unique
static

Definition at line 286 of file file.c.

Referenced by _wtmpnam_s(), and tmpnam_s().

◆ tmpnam_unique

LONG tmpnam_unique
static

Definition at line 285 of file file.c.

Referenced by _wtmpnam(), tmpnam(), tmpnam_helper(), and wtmpnam_helper().

◆ utf16_bom

char utf16_bom[2] = { 0xff, 0xfe }
static

Definition at line 90 of file file.c.

Referenced by _wsopen_dispatch(), _wsopen_s(), and check_bom().

◆ utf8_bom

char utf8_bom[3] = { 0xef, 0xbb, 0xbf }
static

Definition at line 89 of file file.c.

Referenced by _wsopen_dispatch(), _wsopen_s(), check_bom(), editor_handle_message(), and parse_file().

◆ WCBAT

const ULONGLONG WCBAT = TOUL('b') << 32 | TOUL('a') << 16 | TOUL('t')
static

Definition at line 290 of file file.c.

Referenced by _wstat64().

◆ WCCMD

const ULONGLONG WCCMD = TOUL('c') << 32 | TOUL('m') << 16 | TOUL('d')
static

Definition at line 291 of file file.c.

Referenced by _wstat64().

◆ WCCOM

const ULONGLONG WCCOM = TOUL('c') << 32 | TOUL('o') << 16 | TOUL('m')
static

Definition at line 292 of file file.c.

Referenced by _wstat64().

◆ WCEXE

const ULONGLONG WCEXE = TOUL('e') << 32 | TOUL('x') << 16 | TOUL('e')
static

Definition at line 289 of file file.c.

Referenced by _wstat64().