Commit 45f1b06b authored by Paul Rupe's avatar Paul Rupe Committed by Alexandre Julliard

Make ungetc(EOF) a no-op.

parent f6be23e7
......@@ -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));
......@@ -78,6 +80,26 @@ static void test_fileops( void )
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);
pos = (ULONGLONG)sizeof (outbuffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment