7848bb3086d65f9ce28241f5fd01d383a41127ca
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>
35 _fwalk((void (*)(FILE *))fflush
);
43 // nothing to do if stream can not be written to
45 if ( !OPEN4WRITING(f
) ) {
50 // discard any unget characters
52 f
->_flag
&= ~_IOUNGETC
;
55 // check for buffered dirty block
57 if ( (f
->_flag
&(_IODIRTY
|_IONBF
)) ==_IODIRTY
&& f
->_base
!= NULL
)
63 // if the buffer is read ahead and dirty we will flush it entirely
64 // else the buffer is appended to the file to the extend it has valid bytes
66 if ( (f
->_flag
& _IOAHEAD
) == _IOAHEAD
)
67 rn
= n
= f
->_ptr
- base
+ f
->_cnt
;
69 rn
= n
= f
->_ptr
- base
;
73 if ((f
->_flag
& _IOFBF
) == _IOFBF
) {
74 if ( (f
->_flag
& _IOAHEAD
) == _IOAHEAD
)
75 _lseek(fileno(f
),-rn
, SEEK_CUR
);
78 f
->_flag
&= ~_IOAHEAD
;
81 f
->_cnt
= (f
->_flag
&(_IOLBF
|_IONBF
)) ? 0 : f
->_bufsiz
;
83 // how can write return less than rn without being on error ???
85 // possibly commit the flushed data
86 // better open the file in write through mode
89 n
= _write(fileno(f
), base
, rn
);
97 f
->_flag
&= ~_IODIRTY
;
100 if (OPEN4READING(f
) && OPEN4WRITING(f
) )
108 int _flushall( void )