2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/crtdll/conio/kbhit.c
5 * PURPOSE: Checks for keyboard hits
6 * PROGRAMER: Boudewijn Dekker
10 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
11 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
12 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
14 #include <msvcrt/stdio.h>
15 #include <msvcrt/errno.h>
16 #include <msvcrt/sys/types.h>
17 #include <msvcrt/sys/stat.h>
18 #include <msvcrt/stdlib.h>
19 #include <msvcrt/internal/file.h>
20 #include <msvcrt/io.h>
38 _fwalk((void (*)(FILE *))fflush);
46 // nothing to do if stream can not be written to
48 if ( !OPEN4WRITING(f) ) {
53 // discard any unget characters
55 f->_flag &= ~_IOUNGETC;
58 // check for buffered dirty block
60 if ( (f->_flag&(_IODIRTY|_IONBF)) ==_IODIRTY && f->_base != NULL)
66 // if the buffer is read ahead and dirty we will flush it entirely
67 // else the buffer is appended to the file to the extend it has valid bytes
69 if ( (f->_flag & _IOAHEAD) == _IOAHEAD )
70 rn = n = f->_ptr - base + f->_cnt;
72 rn = n = f->_ptr - base;
76 if ((f->_flag & _IOFBF) == _IOFBF) {
77 if ( (f->_flag & _IOAHEAD) == _IOAHEAD )
78 _lseek(fileno(f),-rn, SEEK_CUR);
81 f->_flag &= ~_IOAHEAD;
84 f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
86 // how can write return less than rn without being on error ???
88 // possibly commit the flushed data
89 // better open the file in write through mode
92 n = _write(fileno(f), base, rn);
100 f->_flag &= ~_IODIRTY;
103 if (OPEN4READING(f) && OPEN4WRITING(f) )
114 int _flushall( void )