Author: akhaldi Date: Tue Sep 6 10:04:29 2016 New Revision: 72589
URL: http://svn.reactos.org/svn/reactos?rev=72589&view=rev Log: [CRT] Reduce difference of file.c with Wine Staging 1.9.16. CORE-11866
Modified: trunk/reactos/sdk/lib/crt/stdio/_flsbuf.c trunk/reactos/sdk/lib/crt/stdio/file.c
Modified: trunk/reactos/sdk/lib/crt/stdio/_flsbuf.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/crt/stdio/_flsbuf.c... ============================================================================== --- trunk/reactos/sdk/lib/crt/stdio/_flsbuf.c [iso-8859-1] (original) +++ trunk/reactos/sdk/lib/crt/stdio/_flsbuf.c [iso-8859-1] Tue Sep 6 10:04:29 2016 @@ -8,7 +8,7 @@
#include <precomp.h>
-void __cdecl alloc_buffer(FILE *stream); +BOOL __cdecl msvcrt_alloc_buffer(FILE *stream);
int __cdecl _flsbuf(int ch, FILE *stream) @@ -47,7 +47,7 @@ if (!(stream->_flag & _IONBF) && stream != stdout && stream != stderr) { /* If we have no buffer, try to allocate one */ - if (!stream->_base) alloc_buffer(stream); + if (!stream->_base) msvcrt_alloc_buffer(stream); }
/* Check if we can use a buffer now */
Modified: trunk/reactos/sdk/lib/crt/stdio/file.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/crt/stdio/file.c?re... ============================================================================== --- trunk/reactos/sdk/lib/crt/stdio/file.c [iso-8859-1] (original) +++ trunk/reactos/sdk/lib/crt/stdio/file.c [iso-8859-1] Tue Sep 6 10:04:29 2016 @@ -107,8 +107,8 @@ static char utf16_bom[2] = { 0xff, 0xfe };
/* FIXME: this should be allocated dynamically */ -#define MAX_FILES 2048 -#define FD_BLOCK_SIZE 64 +#define MSVCRT_MAX_FILES 2048 +#define MSVCRT_FD_BLOCK_SIZE 64
#define MSVCRT_INTERNAL_BUFSIZ 4096
@@ -125,7 +125,7 @@ * __pioinfo (MSVCRT.@) * array of pointers to ioinfo arrays [64] */ -ioinfo * __pioinfo[MAX_FILES/FD_BLOCK_SIZE] = { 0 }; +ioinfo * __pioinfo[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { 0 };
/********************************************************************* * __badioinfo (MSVCRT.@) @@ -141,7 +141,7 @@ } file_crit;
FILE _iob[_IOB_ENTRIES] = { { 0 } }; -static file_crit* MSVCRT_fstream[MAX_FILES/FD_BLOCK_SIZE] = { NULL }; +static file_crit* MSVCRT_fstream[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { NULL }; static int MSVCRT_max_streams = 512, MSVCRT_stream_idx;
/* INTERNAL: process umask */ @@ -171,23 +171,23 @@ static inline ioinfo* get_ioinfo_nolock(int fd) { ioinfo *ret = NULL; - if(fd>=0 && fd<MAX_FILES) - ret = __pioinfo[fd/FD_BLOCK_SIZE]; + if(fd>=0 && fd<MSVCRT_MAX_FILES) + ret = __pioinfo[fd/MSVCRT_FD_BLOCK_SIZE]; if(!ret) return &__badioinfo;
- return ret + (fd%FD_BLOCK_SIZE); + return ret + (fd%MSVCRT_FD_BLOCK_SIZE); }
static inline ioinfo* get_ioinfo(int fd) { ioinfo *ret = NULL; - if(fd < MAX_FILES) - ret = __pioinfo[fd/FD_BLOCK_SIZE]; + if(fd < MSVCRT_MAX_FILES) + ret = __pioinfo[fd/MSVCRT_FD_BLOCK_SIZE]; if(!ret) return &__badioinfo;
- return ret + (fd%FD_BLOCK_SIZE); + return ret + (fd%MSVCRT_FD_BLOCK_SIZE); }
static inline FILE* msvcrt_get_file(int i) @@ -200,18 +200,18 @@ if(i < _IOB_ENTRIES) return &_iob[i];
- ret = MSVCRT_fstream[i/FD_BLOCK_SIZE]; + ret = MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE]; if(!ret) { - MSVCRT_fstream[i/FD_BLOCK_SIZE] = calloc(FD_BLOCK_SIZE, sizeof(file_crit)); - if(!MSVCRT_fstream[i/FD_BLOCK_SIZE]) { + MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE] = calloc(MSVCRT_FD_BLOCK_SIZE, sizeof(file_crit)); + if(!MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE]) { ERR("out of memory\n"); *_errno() = ENOMEM; return NULL; }
- ret = MSVCRT_fstream[i/FD_BLOCK_SIZE] + (i%FD_BLOCK_SIZE); + ret = MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE] + (i%MSVCRT_FD_BLOCK_SIZE); } else - ret += i%FD_BLOCK_SIZE; + ret += i%MSVCRT_FD_BLOCK_SIZE;
return &ret->file; } @@ -284,7 +284,7 @@ { ioinfo *fdinfo;
- if (fd >= MAX_FILES) + if (fd >= MSVCRT_MAX_FILES) { WARN(":files exhausted!\n"); *_errno() = ENFILE; @@ -295,15 +295,15 @@ if(fdinfo == &__badioinfo) { int i;
- __pioinfo[fd/FD_BLOCK_SIZE] = calloc(FD_BLOCK_SIZE, sizeof(ioinfo)); - if(!__pioinfo[fd/FD_BLOCK_SIZE]) { + __pioinfo[fd/MSVCRT_FD_BLOCK_SIZE] = calloc(MSVCRT_FD_BLOCK_SIZE, sizeof(ioinfo)); + if(!__pioinfo[fd/MSVCRT_FD_BLOCK_SIZE]) { WARN(":out of memory!\n"); *_errno() = ENOMEM; return -1; }
- for(i=0; i<FD_BLOCK_SIZE; i++) - __pioinfo[fd/FD_BLOCK_SIZE][i].handle = INVALID_HANDLE_VALUE; + for(i=0; i<MSVCRT_FD_BLOCK_SIZE; i++) + __pioinfo[fd/MSVCRT_FD_BLOCK_SIZE][i].handle = INVALID_HANDLE_VALUE;
fdinfo = get_ioinfo(fd); } @@ -460,7 +460,7 @@ handle_ptr = (HANDLE*)(wxflag_ptr + count);
count = min(count, (si.cbReserved2 - sizeof(unsigned)) / (sizeof(HANDLE) + 1)); - count = min(count, MAX_FILES); + count = min(count, MSVCRT_MAX_FILES); for (i = 0; i < count; i++) { if ((*wxflag_ptr & WX_OPEN) && *handle_ptr != INVALID_HANDLE_VALUE) @@ -553,7 +553,7 @@ }
/* INTERNAL: Allocate stdio file buffer */ -/*static*/ BOOL alloc_buffer(FILE* file) +/*static*/ BOOL msvcrt_alloc_buffer(FILE* file) { if((file->_file==STDOUT_FILENO || file->_file==STDERR_FILENO) && _isatty(file->_file)) @@ -941,7 +941,7 @@
TRACE("(od=%d, nd=%d)\n", od, nd); LOCK_FILES(); - if (nd < MAX_FILES && nd >= 0 && is_valid_fd(od)) + if (nd < MSVCRT_MAX_FILES && nd >= 0 && is_valid_fd(od)) { HANDLE handle;
@@ -1313,7 +1313,7 @@ _unlock_file(file); }
-static int get_flags(const wchar_t* mode, int *open_flags, int* stream_flags) +static int msvcrt_get_flags(const wchar_t* mode, int *open_flags, int* stream_flags) { int plus = strchrW(mode, '+') != NULL;
@@ -1453,7 +1453,7 @@ int open_flags, stream_flags; FILE* file;
- if (get_flags(mode, &open_flags, &stream_flags) == -1) return NULL; + if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) return NULL;
LOCK_FILES(); if (!(file = msvcrt_alloc_fp())) @@ -1842,6 +1842,7 @@ else if (access & GENERIC_READ) oflags = check_bom(hand, oflags, TRUE); } + type = GetFileType(hand); if (type == FILE_TYPE_CHAR) wxflag |= WX_TTY; @@ -2757,7 +2758,7 @@
/* Allocate buffer if needed */ if(!(file->_flag & (_IONBF | _IOMYBUF | _USERBUF))) - alloc_buffer(file); + msvcrt_alloc_buffer(file);
if(!(file->_flag & _IOREAD)) { if(file->_flag & _IORW) @@ -3105,7 +3106,7 @@ TRACE("(%s,%s)\n", debugstr_w(path), debugstr_w(mode));
/* map mode string to open() flags. "man fopen" for possibilities. */ - if (get_flags(mode, &open_flags, &stream_flags) == -1) + if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) return NULL;
LOCK_FILES(); @@ -3280,7 +3281,7 @@ }
if(rcnt>0 && !(file->_flag & (_IONBF | _IOMYBUF | _USERBUF))) - alloc_buffer(file); + msvcrt_alloc_buffer(file);
while(rcnt>0) { @@ -3344,7 +3345,7 @@ { fclose(file); /* map mode string to open() flags. "man fopen" for possibilities. */ - if (get_flags(mode, &open_flags, &stream_flags) == -1) + if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) file = NULL; else { @@ -3862,7 +3863,7 @@
_lock_file(file); if((!(file->_flag & (_IONBF | _IOMYBUF | _USERBUF)) - && alloc_buffer(file)) + && msvcrt_alloc_buffer(file)) || (!file->_cnt && file->_ptr==file->_base)) file->_ptr++;
@@ -3950,7 +3951,7 @@ { TRACE("%d\n", newmax);
- if(newmax<_IOB_ENTRIES || newmax>MAX_FILES || newmax<MSVCRT_stream_idx) + if(newmax<_IOB_ENTRIES || newmax>MSVCRT_MAX_FILES || newmax<MSVCRT_stream_idx) return -1;
MSVCRT_max_streams = newmax;