Make ungetc(EOF) a no-op.
This commit is contained in:
parent
f6be23e75b
commit
45f1b06b94
|
@ -2190,7 +2190,7 @@ char *MSVCRT_fgets(char *s, int size, MSVCRT_FILE* file)
|
|||
if ((cc != MSVCRT_EOF) && (size > 1))
|
||||
*s++ = cc;
|
||||
*s = '\0';
|
||||
TRACE(":got '%s'\n", debugstr_a(buf_start));
|
||||
TRACE(":got %s\n", debugstr_a(buf_start));
|
||||
return buf_start;
|
||||
}
|
||||
|
||||
|
@ -2983,6 +2983,8 @@ int MSVCRT_printf(const char *format, ...)
|
|||
*/
|
||||
int MSVCRT_ungetc(int c, MSVCRT_FILE * file)
|
||||
{
|
||||
if (c == MSVCRT_EOF)
|
||||
return MSVCRT_EOF;
|
||||
if(file->_bufsiz == 0 && !(file->_flag & MSVCRT__IONBF)) {
|
||||
msvcrt_alloc_buffer(file);
|
||||
file->_ptr++;
|
||||
|
@ -2991,6 +2993,7 @@ int MSVCRT_ungetc(int c, MSVCRT_FILE * file)
|
|||
file->_ptr--;
|
||||
*file->_ptr=c;
|
||||
file->_cnt++;
|
||||
MSVCRT_clearerr(file);
|
||||
return c;
|
||||
}
|
||||
return MSVCRT_EOF;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Unit test suite for file functions
|
||||
*
|
||||
* Copyright 2002 Bill Currie
|
||||
* Copyright 2005 Paul Rupe
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -59,6 +60,7 @@ static void test_fileops( void )
|
|||
int fd;
|
||||
FILE *file;
|
||||
fpos_t pos;
|
||||
int i, c;
|
||||
|
||||
fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE);
|
||||
write (fd, outbuffer, sizeof (outbuffer));
|
||||
|
@ -77,6 +79,26 @@ static void test_fileops( void )
|
|||
ok(strlen(buffer) == 1,"fgets dropped chars\n");
|
||||
ok(buffer[0] == outbuffer[strlen(outbuffer)-1],"fgets exchanged chars\n");
|
||||
|
||||
rewind(file);
|
||||
for (i = 0, c = EOF; i < sizeof(outbuffer); i++)
|
||||
{
|
||||
ok((c = fgetc(file)) == outbuffer[i], "fgetc returned wrong data\n");
|
||||
}
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF\n");
|
||||
ok(feof(file), "feof did not return EOF\n");
|
||||
ok(ungetc(c, file) == EOF, "ungetc(EOF) did not return EOF\n");
|
||||
ok(feof(file), "feof after ungetc(EOF) did not return EOF\n");
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF\n");
|
||||
c = outbuffer[sizeof(outbuffer) - 1];
|
||||
ok(ungetc(c, file) == c, "ungetc did not return its input\n");
|
||||
ok(!feof(file), "feof after ungetc returned EOF\n");
|
||||
ok((c = fgetc(file)) != EOF, "getc after ungetc returned EOF\n");
|
||||
ok(c == outbuffer[sizeof(outbuffer) - 1],
|
||||
"getc did not return ungetc'd data\n");
|
||||
ok(!feof(file), "feof after getc returned EOF prematurely\n");
|
||||
ok((c = fgetc(file)) == EOF, "getc did not return EOF\n");
|
||||
ok(feof(file), "feof after getc did not return EOF\n");
|
||||
|
||||
rewind(file);
|
||||
ok(fgetpos(file,&pos) == 0, "fgetpos failed unexpected\n");
|
||||
ok(pos == 0, "Unexpected result of fgetpos 0x%Lx\n", pos);
|
||||
|
|
Loading…
Reference in New Issue