1 /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
2 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
3 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
5 #include <msvcrt/stdio.h>
6 #include <msvcrt/sys/types.h>
7 #include <msvcrt/stdlib.h>
8 #include <msvcrt/string.h>
9 #include <msvcrt/internal/file.h>
10 #include <msvcrt/io.h>
11 #include <msvcrt/wchar.h>
12 #include <msvcrt/errno.h>
14 int _readcnv(int fn, void* buf, size_t siz);
21 if ( !OPEN4READING(f)) {
25 if (f->_flag&(_IOSTRG|_IOEOF))
27 f->_flag &= ~_IOUNGETC;
29 if (f->_base == NULL && (f->_flag & _IONBF) == 0) {
31 if ((f->_base = malloc(size+1)) == NULL) {
34 f->_flag &= ~(_IOFBF|_IOLBF);
43 // flush stdout before reading from stdin
45 if (stdout->_flag&_IOLBF)
47 if (stderr->_flag&_IOLBF)
51 // if we have a dirty stream we flush it
52 if ((f->_flag &_IODIRTY) == _IODIRTY)
57 f->_cnt = _read(fileno(f), f->_base, f->_flag & _IONBF ? 1 : f->_bufsiz );
60 if(__is_text_file(f) && f->_cnt>0)
62 /* truncate text file at Ctrl-Z */
63 char *cz=memchr(f->_base, 0x1A, f->_cnt);
66 int newcnt = cz - f->_base;
67 lseek(fileno(f), -(f->_cnt - newcnt), SEEK_CUR);
74 if (f->_flag & _IONBF)
75 f->_base = NULL; // statically allocated buffer for sprintf
93 return *f->_ptr++ & 0377;
96 wint_t _filwbuf(FILE *fp)
98 return (wint_t )_filbuf(fp);
101 // convert the carriage return line feed pairs
103 int _readcnv(int fn, void *buf, size_t siz )
105 char *bufp = (char *)buf;
110 n = _read(fn, buf, siz );
112 while (_bufsiz > 0) {
116 *bufp = *(bufp + cr);