msvcrt: Use EOF from public header.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2020-11-30 14:37:09 +01:00 committed by Alexandre Julliard
parent 7acfe8fb73
commit 8180f4001a
6 changed files with 51 additions and 52 deletions

View File

@ -35,7 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
static HANDLE MSVCRT_console_in = INVALID_HANDLE_VALUE; static HANDLE MSVCRT_console_in = INVALID_HANDLE_VALUE;
static HANDLE MSVCRT_console_out= INVALID_HANDLE_VALUE; static HANDLE MSVCRT_console_out= INVALID_HANDLE_VALUE;
static int __MSVCRT_console_buffer = MSVCRT_EOF; static int __MSVCRT_console_buffer = EOF;
static wchar_t __MSVCRT_console_buffer_w = WEOF; static wchar_t __MSVCRT_console_buffer_w = WEOF;
/* INTERNAL: Initialise console handles */ /* INTERNAL: Initialise console handles */
@ -153,12 +153,12 @@ static BOOL handle_enhanced_keys(INPUT_RECORD *ir, unsigned char *ch1, unsigned
*/ */
int CDECL _getch_nolock(void) int CDECL _getch_nolock(void)
{ {
int retval = MSVCRT_EOF; int retval = EOF;
if (__MSVCRT_console_buffer != MSVCRT_EOF) if (__MSVCRT_console_buffer != EOF)
{ {
retval = __MSVCRT_console_buffer; retval = __MSVCRT_console_buffer;
__MSVCRT_console_buffer = MSVCRT_EOF; __MSVCRT_console_buffer = EOF;
} }
else else
{ {
@ -290,7 +290,7 @@ int CDECL _putch_nolock(int c)
DWORD count; DWORD count;
if (WriteConsoleA(MSVCRT_console_out, &c, 1, &count, NULL) && count == 1) if (WriteConsoleA(MSVCRT_console_out, &c, 1, &count, NULL) && count == 1)
return c; return c;
return MSVCRT_EOF; return EOF;
} }
/********************************************************************* /*********************************************************************
@ -333,7 +333,7 @@ int CDECL _getche_nolock(void)
{ {
int retval; int retval;
retval = _getch_nolock(); retval = _getch_nolock();
if (retval != MSVCRT_EOF) if (retval != EOF)
retval = _putch_nolock(retval); retval = _putch_nolock(retval);
return retval; return retval;
} }
@ -419,8 +419,8 @@ char* CDECL _cgets(char* str)
*/ */
int CDECL _ungetch_nolock(int c) int CDECL _ungetch_nolock(int c)
{ {
int retval = MSVCRT_EOF; int retval = EOF;
if (c != MSVCRT_EOF && __MSVCRT_console_buffer == MSVCRT_EOF) if (c != EOF && __MSVCRT_console_buffer == EOF)
retval = __MSVCRT_console_buffer = c; retval = __MSVCRT_console_buffer = c;
return retval; return retval;
} }
@ -466,7 +466,7 @@ int CDECL _kbhit(void)
int retval = 0; int retval = 0;
LOCK_CONSOLE; LOCK_CONSOLE;
if (__MSVCRT_console_buffer != MSVCRT_EOF) if (__MSVCRT_console_buffer != EOF)
retval = 1; retval = 1;
else else
{ {

View File

@ -658,7 +658,7 @@ static int msvcrt_flush_buffer(MSVCRT_FILE* file)
int cnt=file->_ptr-file->_base; int cnt=file->_ptr-file->_base;
if(cnt>0 && MSVCRT__write(file->_file, file->_base, cnt) != cnt) { if(cnt>0 && MSVCRT__write(file->_file, file->_base, cnt) != cnt) {
file->_flag |= MSVCRT__IOERR; file->_flag |= MSVCRT__IOERR;
ret = MSVCRT_EOF; ret = EOF;
} else if(file->_flag & MSVCRT__IORW) { } else if(file->_flag & MSVCRT__IORW) {
file->_flag &= ~MSVCRT__IOWRT; file->_flag &= ~MSVCRT__IOWRT;
} }
@ -1035,7 +1035,7 @@ int CDECL MSVCRT__fflush_nolock(MSVCRT_FILE* file)
res = msvcrt_flush_buffer(file); res = msvcrt_flush_buffer(file);
if(!res && (file->_flag & MSVCRT__IOCOMMIT)) if(!res && (file->_flag & MSVCRT__IOCOMMIT))
res = MSVCRT__commit(file->_file) ? MSVCRT_EOF : 0; res = MSVCRT__commit(file->_file) ? EOF : 0;
return res; return res;
} }
@ -2938,7 +2938,7 @@ int CDECL MSVCRT__setmode(int fd,int mode)
if(info == &MSVCRT___badioinfo) { if(info == &MSVCRT___badioinfo) {
*MSVCRT__errno() = MSVCRT_EBADF; *MSVCRT__errno() = MSVCRT_EBADF;
return MSVCRT_EOF; return EOF;
} }
if(mode == MSVCRT__O_BINARY) { if(mode == MSVCRT__O_BINARY) {
@ -3618,7 +3618,7 @@ int CDECL MSVCRT__putw(int val, MSVCRT_FILE* file)
file->_flag |= MSVCRT__IOERR; file->_flag |= MSVCRT__IOERR;
MSVCRT__unlock_file(file); MSVCRT__unlock_file(file);
return MSVCRT_EOF; return EOF;
} }
/********************************************************************* /*********************************************************************
@ -3645,7 +3645,7 @@ int CDECL MSVCRT__fclose_nolock(MSVCRT_FILE* file)
if(!(file->_flag & (MSVCRT__IOREAD | MSVCRT__IOWRT | MSVCRT__IORW))) if(!(file->_flag & (MSVCRT__IOREAD | MSVCRT__IOWRT | MSVCRT__IORW)))
{ {
file->_flag = 0; file->_flag = 0;
return MSVCRT_EOF; return EOF;
} }
flag = file->_flag; flag = file->_flag;
@ -3660,7 +3660,7 @@ int CDECL MSVCRT__fclose_nolock(MSVCRT_FILE* file)
r=MSVCRT__close(file->_file); r=MSVCRT__close(file->_file);
file->_flag = 0; file->_flag = 0;
return ((r == -1) || (flag & MSVCRT__IOERR) ? MSVCRT_EOF : 0); return ((r == -1) || (flag & MSVCRT__IOERR) ? EOF : 0);
} }
/********************************************************************* /*********************************************************************
@ -3687,7 +3687,7 @@ int CDECL MSVCRT__filbuf(MSVCRT_FILE* file)
unsigned char c; unsigned char c;
if(file->_flag & MSVCRT__IOSTRG) if(file->_flag & MSVCRT__IOSTRG)
return MSVCRT_EOF; return EOF;
/* Allocate buffer if needed */ /* Allocate buffer if needed */
if(!(file->_flag & (MSVCRT__IONBF | MSVCRT__IOMYBUF | MSVCRT__USERBUF))) if(!(file->_flag & (MSVCRT__IONBF | MSVCRT__IOMYBUF | MSVCRT__USERBUF)))
@ -3697,14 +3697,14 @@ int CDECL MSVCRT__filbuf(MSVCRT_FILE* file)
if(file->_flag & MSVCRT__IORW) if(file->_flag & MSVCRT__IORW)
file->_flag |= MSVCRT__IOREAD; file->_flag |= MSVCRT__IOREAD;
else else
return MSVCRT_EOF; return EOF;
} }
if(!(file->_flag & (MSVCRT__IOMYBUF | MSVCRT__USERBUF))) { if(!(file->_flag & (MSVCRT__IOMYBUF | MSVCRT__USERBUF))) {
int r; int r;
if ((r = MSVCRT__read(file->_file,&c,1)) != 1) { if ((r = MSVCRT__read(file->_file,&c,1)) != 1) {
file->_flag |= (r == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR; file->_flag |= (r == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR;
return MSVCRT_EOF; return EOF;
} }
return c; return c;
@ -3713,7 +3713,7 @@ int CDECL MSVCRT__filbuf(MSVCRT_FILE* file)
if(file->_cnt<=0) { if(file->_cnt<=0) {
file->_flag |= (file->_cnt == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR; file->_flag |= (file->_cnt == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR;
file->_cnt = 0; file->_cnt = 0;
return MSVCRT_EOF; return EOF;
} }
file->_cnt--; file->_cnt--;
@ -3768,7 +3768,7 @@ int CDECL MSVCRT__fgetchar(void)
*/ */
char * CDECL MSVCRT_fgets(char *s, int size, MSVCRT_FILE* file) char * CDECL MSVCRT_fgets(char *s, int size, MSVCRT_FILE* file)
{ {
int cc = MSVCRT_EOF; int cc = EOF;
char * buf_start = s; char * buf_start = s;
TRACE(":file(%p) fd (%d) str (%p) len (%d)\n", TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
@ -3776,18 +3776,18 @@ char * CDECL MSVCRT_fgets(char *s, int size, MSVCRT_FILE* file)
MSVCRT__lock_file(file); MSVCRT__lock_file(file);
while ((size >1) && (cc = MSVCRT__fgetc_nolock(file)) != MSVCRT_EOF && cc != '\n') while ((size >1) && (cc = MSVCRT__fgetc_nolock(file)) != EOF && cc != '\n')
{ {
*s++ = (char)cc; *s++ = (char)cc;
size --; size --;
} }
if ((cc == MSVCRT_EOF) && (s == buf_start)) /* If nothing read, return 0*/ if ((cc == EOF) && (s == buf_start)) /* If nothing read, return 0*/
{ {
TRACE(":nothing read\n"); TRACE(":nothing read\n");
MSVCRT__unlock_file(file); MSVCRT__unlock_file(file);
return NULL; return NULL;
} }
if ((cc != MSVCRT_EOF) && (size > 1)) if ((cc != EOF) && (size > 1))
*s++ = cc; *s++ = cc;
*s = '\0'; *s = '\0';
TRACE(":got %s\n", debugstr_a(buf_start)); TRACE(":got %s\n", debugstr_a(buf_start));
@ -3823,7 +3823,7 @@ wint_t CDECL MSVCRT__fgetwc_nolock(MSVCRT_FILE* file)
for(p=(char*)&ret; (wint_t*)p<&ret+1; p++) { for(p=(char*)&ret; (wint_t*)p<&ret+1; p++) {
ch = MSVCRT__fgetc_nolock(file); ch = MSVCRT__fgetc_nolock(file);
if(ch == MSVCRT_EOF) { if(ch == EOF) {
ret = WEOF; ret = WEOF;
break; break;
} }
@ -3834,11 +3834,11 @@ wint_t CDECL MSVCRT__fgetwc_nolock(MSVCRT_FILE* file)
int len = 0; int len = 0;
ch = MSVCRT__fgetc_nolock(file); ch = MSVCRT__fgetc_nolock(file);
if(ch != MSVCRT_EOF) { if(ch != EOF) {
mbs[0] = (char)ch; mbs[0] = (char)ch;
if(MSVCRT_isleadbyte((unsigned char)mbs[0])) { if(MSVCRT_isleadbyte((unsigned char)mbs[0])) {
ch = MSVCRT__fgetc_nolock(file); ch = MSVCRT__fgetc_nolock(file);
if(ch != MSVCRT_EOF) { if(ch != EOF) {
mbs[1] = (char)ch; mbs[1] = (char)ch;
len = 2; len = 2;
} }
@ -3867,10 +3867,10 @@ int CDECL MSVCRT__getw(MSVCRT_FILE* file)
MSVCRT__lock_file(file); MSVCRT__lock_file(file);
for (j=0; j<sizeof(int); j++) { for (j=0; j<sizeof(int); j++) {
k = MSVCRT__fgetc_nolock(file); k = MSVCRT__fgetc_nolock(file);
if (k == MSVCRT_EOF) { if (k == EOF) {
file->_flag |= MSVCRT__IOEOF; file->_flag |= MSVCRT__IOEOF;
MSVCRT__unlock_file(file); MSVCRT__unlock_file(file);
return MSVCRT_EOF; return EOF;
} }
ch[j] = k; ch[j] = k;
} }
@ -3949,14 +3949,14 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
if(!(file->_flag & MSVCRT__IORW)) { if(!(file->_flag & MSVCRT__IORW)) {
file->_flag |= MSVCRT__IOERR; file->_flag |= MSVCRT__IOERR;
*MSVCRT__errno() = MSVCRT_EBADF; *MSVCRT__errno() = MSVCRT_EBADF;
return MSVCRT_EOF; return EOF;
} }
file->_flag |= MSVCRT__IOWRT; file->_flag |= MSVCRT__IOWRT;
} }
if(file->_flag & MSVCRT__IOREAD) { if(file->_flag & MSVCRT__IOREAD) {
if(!(file->_flag & MSVCRT__IOEOF)) { if(!(file->_flag & MSVCRT__IOEOF)) {
file->_flag |= MSVCRT__IOERR; file->_flag |= MSVCRT__IOERR;
return MSVCRT_EOF; return EOF;
} }
file->_cnt = 0; file->_cnt = 0;
file->_ptr = file->_base; file->_ptr = file->_base;
@ -3985,7 +3985,7 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
if (len == 1) if (len == 1)
return c & 0xff; return c & 0xff;
file->_flag |= MSVCRT__IOERR; file->_flag |= MSVCRT__IOERR;
return MSVCRT_EOF; return EOF;
} }
} }
@ -4041,7 +4041,7 @@ size_t CDECL MSVCRT__fwrite_nolock(const void *ptr, size_t size, size_t nmemb, M
pcnt = (wrcnt / bufsiz) * bufsiz; pcnt = (wrcnt / bufsiz) * bufsiz;
if(msvcrt_flush_buffer(file) == MSVCRT_EOF) if(msvcrt_flush_buffer(file) == EOF)
break; break;
if(MSVCRT__write(file->_file, ptr, pcnt) <= 0) { if(MSVCRT__write(file->_file, ptr, pcnt) <= 0) {
@ -4052,7 +4052,7 @@ size_t CDECL MSVCRT__fwrite_nolock(const void *ptr, size_t size, size_t nmemb, M
wrcnt -= pcnt; wrcnt -= pcnt;
ptr = (const char*)ptr + pcnt; ptr = (const char*)ptr + pcnt;
} else { } else {
if(MSVCRT__flsbuf(*(const char*)ptr, file) == MSVCRT_EOF) if(MSVCRT__flsbuf(*(const char*)ptr, file) == EOF)
break; break;
written++; written++;
wrcnt--; wrcnt--;
@ -4425,7 +4425,7 @@ size_t CDECL MSVCRT__fread_nolock_s(void *buf, size_t buf_size, size_t elem_size
}else { }else {
int c = MSVCRT__filbuf(stream); int c = MSVCRT__filbuf(stream);
if(c == MSVCRT_EOF) if(c == EOF)
break; break;
if(!MSVCRT_CHECK_PMT_ERR(buf_size != buf_pos, MSVCRT_ERANGE)) { if(!MSVCRT_CHECK_PMT_ERR(buf_size != buf_pos, MSVCRT_ERANGE)) {
@ -4658,7 +4658,7 @@ int CDECL MSVCRT_fputs(const char *s, MSVCRT_FILE* file)
int ret; int ret;
MSVCRT__lock_file(file); MSVCRT__lock_file(file);
ret = MSVCRT__fwrite_nolock(s, sizeof(*s), len, file) == len ? 0 : MSVCRT_EOF; ret = MSVCRT__fwrite_nolock(s, sizeof(*s), len, file) == len ? 0 : EOF;
MSVCRT__unlock_file(file); MSVCRT__unlock_file(file);
return ret; return ret;
} }
@ -4674,7 +4674,7 @@ int CDECL MSVCRT_fputws(const wchar_t *s, MSVCRT_FILE* file)
MSVCRT__lock_file(file); MSVCRT__lock_file(file);
if (!(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) { if (!(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) {
ret = MSVCRT__fwrite_nolock(s,sizeof(*s),len,file) == len ? 0 : MSVCRT_EOF; ret = MSVCRT__fwrite_nolock(s,sizeof(*s),len,file) == len ? 0 : EOF;
MSVCRT__unlock_file(file); MSVCRT__unlock_file(file);
return ret; return ret;
} }
@ -4722,7 +4722,7 @@ char * CDECL MSVCRT_gets_s(char *buf, size_t len)
MSVCRT__lock_file(MSVCRT_stdin); MSVCRT__lock_file(MSVCRT_stdin);
for(cc = MSVCRT__fgetc_nolock(MSVCRT_stdin); for(cc = MSVCRT__fgetc_nolock(MSVCRT_stdin);
len != 0 && cc != MSVCRT_EOF && cc != '\n'; len != 0 && cc != EOF && cc != '\n';
cc = MSVCRT__fgetc_nolock(MSVCRT_stdin)) cc = MSVCRT__fgetc_nolock(MSVCRT_stdin))
{ {
if (cc != '\r') if (cc != '\r')
@ -4740,7 +4740,7 @@ char * CDECL MSVCRT_gets_s(char *buf, size_t len)
return NULL; return NULL;
} }
if ((cc == MSVCRT_EOF) && (buf_start == buf)) if ((cc == EOF) && (buf_start == buf))
{ {
TRACE(":nothing read\n"); TRACE(":nothing read\n");
return NULL; return NULL;
@ -4814,10 +4814,10 @@ int CDECL MSVCRT_puts(const char *s)
MSVCRT__lock_file(MSVCRT_stdout); MSVCRT__lock_file(MSVCRT_stdout);
if(MSVCRT__fwrite_nolock(s, sizeof(*s), len, MSVCRT_stdout) != len) { if(MSVCRT__fwrite_nolock(s, sizeof(*s), len, MSVCRT_stdout) != len) {
MSVCRT__unlock_file(MSVCRT_stdout); MSVCRT__unlock_file(MSVCRT_stdout);
return MSVCRT_EOF; return EOF;
} }
ret = MSVCRT__fwrite_nolock("\n",1,1,MSVCRT_stdout) == 1 ? 0 : MSVCRT_EOF; ret = MSVCRT__fwrite_nolock("\n",1,1,MSVCRT_stdout) == 1 ? 0 : EOF;
MSVCRT__unlock_file(MSVCRT_stdout); MSVCRT__unlock_file(MSVCRT_stdout);
return ret; return ret;
} }
@ -5502,7 +5502,7 @@ int CDECL MSVCRT_ungetc(int c, MSVCRT_FILE * file)
{ {
int ret; int ret;
if(!MSVCRT_CHECK_PMT(file != NULL)) return MSVCRT_EOF; if(!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
MSVCRT__lock_file(file); MSVCRT__lock_file(file);
ret = MSVCRT__ungetc_nolock(c, file); ret = MSVCRT__ungetc_nolock(c, file);
@ -5516,11 +5516,11 @@ int CDECL MSVCRT_ungetc(int c, MSVCRT_FILE * file)
*/ */
int CDECL MSVCRT__ungetc_nolock(int c, MSVCRT_FILE * file) int CDECL MSVCRT__ungetc_nolock(int c, MSVCRT_FILE * file)
{ {
if(!MSVCRT_CHECK_PMT(file != NULL)) return MSVCRT_EOF; if(!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
if (c == MSVCRT_EOF || !(file->_flag&MSVCRT__IOREAD || if (c == EOF || !(file->_flag&MSVCRT__IOREAD ||
(file->_flag&MSVCRT__IORW && !(file->_flag&MSVCRT__IOWRT)))) (file->_flag&MSVCRT__IORW && !(file->_flag&MSVCRT__IOWRT))))
return MSVCRT_EOF; return EOF;
if((!(file->_flag & (MSVCRT__IONBF | MSVCRT__IOMYBUF | MSVCRT__USERBUF)) if((!(file->_flag & (MSVCRT__IONBF | MSVCRT__IOMYBUF | MSVCRT__USERBUF))
&& msvcrt_alloc_buffer(file)) && msvcrt_alloc_buffer(file))
@ -5532,7 +5532,7 @@ int CDECL MSVCRT__ungetc_nolock(int c, MSVCRT_FILE * file)
if(file->_flag & MSVCRT__IOSTRG) { if(file->_flag & MSVCRT__IOSTRG) {
if(*file->_ptr != c) { if(*file->_ptr != c) {
file->_ptr++; file->_ptr++;
return MSVCRT_EOF; return EOF;
} }
}else { }else {
*file->_ptr = c; *file->_ptr = c;
@ -5543,7 +5543,7 @@ int CDECL MSVCRT__ungetc_nolock(int c, MSVCRT_FILE * file)
return c; return c;
} }
return MSVCRT_EOF; return EOF;
} }
/********************************************************************* /*********************************************************************

View File

@ -2444,7 +2444,7 @@ wint_t CDECL btowc(int c)
unsigned char letter = c; unsigned char letter = c;
wchar_t ret; wchar_t ret;
if(c == MSVCRT_EOF) if(c == EOF)
return WEOF; return WEOF;
if(!get_locinfo()->lc_codepage) if(!get_locinfo()->lc_codepage)
return c & 255; return c & 255;

View File

@ -555,7 +555,6 @@ struct MSVCRT__stat64 {
#define MSVCRT__stati64 MSVCRT__stat32i64 #define MSVCRT__stati64 MSVCRT__stat32i64
#endif #endif
#define MSVCRT_EOF (-1)
#define MSVCRT_TMP_MAX 0x7fff #define MSVCRT_TMP_MAX 0x7fff
#define MSVCRT_TMP_MAX_S 0x7fffffff #define MSVCRT_TMP_MAX_S 0x7fffffff
#define MSVCRT_RAND_MAX 0x7fff #define MSVCRT_RAND_MAX 0x7fff

View File

@ -34,8 +34,8 @@
#define _BITMAPSIZE_ 256*256 #define _BITMAPSIZE_ 256*256
#else /* WIDE_SCANF */ #else /* WIDE_SCANF */
#define _CHAR_ char #define _CHAR_ char
#define _EOF_ MSVCRT_EOF #define _EOF_ EOF
#define _EOF_RET MSVCRT_EOF #define _EOF_RET EOF
#define _ISSPACE_(c) MSVCRT_isspace(c) #define _ISSPACE_(c) MSVCRT_isspace(c)
#define _WIDE2SUPPORTED_(c) c /* FIXME: convert wide char to char */ #define _WIDE2SUPPORTED_(c) c /* FIXME: convert wide char to char */
#define _CHAR2SUPPORTED_(c) c /* No conversion needed (char to char) */ #define _CHAR2SUPPORTED_(c) c /* No conversion needed (char to char) */

View File

@ -2039,10 +2039,10 @@ INT CDECL MSVCRT_wctob( wint_t wchar )
if (wchar < 0xff) if (wchar < 0xff)
return (signed char)wchar; return (signed char)wchar;
else else
return MSVCRT_EOF; return EOF;
} else if(WideCharToMultiByte( codepage, 0, &wchar, 1, &out, 1, NULL, perror ) && !error) } else if(WideCharToMultiByte( codepage, 0, &wchar, 1, &out, 1, NULL, perror ) && !error)
return (INT)out; return (INT)out;
return MSVCRT_EOF; return EOF;
} }
/********************************************************************* /*********************************************************************