[CRT]
authorAmine Khaldi <amine.khaldi@reactos.org>
Wed, 14 May 2014 14:55:37 +0000 (14:55 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Wed, 14 May 2014 14:55:37 +0000 (14:55 +0000)
* Update ungetc().
CORE-8080

svn path=/trunk/; revision=63293

reactos/lib/sdk/crt/stdio/file.c

index ec22bfe..ae6164e 100644 (file)
@@ -3880,13 +3880,19 @@ int CDECL ungetc(int c, FILE * file)
         return EOF;
 
     _lock_file(file);
-    if(file->_bufsiz == 0) {
-        alloc_buffer(file);
+    if(file->_bufsiz == 0 && alloc_buffer(file))
         file->_ptr++;
-    }
     if(file->_ptr>file->_base) {
         file->_ptr--;
-        *file->_ptr=c;
+        if(file->_flag & _IOSTRG) {
+            if(*file->_ptr != c) {
+                file->_ptr++;
+                _unlock_file(file);
+                return EOF;
+            }
+        }else {
+            *file->_ptr = c;
+        }
         file->_cnt++;
         clearerr(file);
         _unlock_file(file);