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 );
23 if ( !OPEN4READING(f)) {
29 if (f->_flag&(_IOSTRG|_IOEOF))
31 f->_flag &= ~_IOUNGETC;
33 if (f->_base==NULL && (f->_flag&_IONBF)==0) {
35 if ((f->_base = malloc(size+1)) == NULL)
39 f->_flag &= ~(_IOFBF|_IOLBF);
53 // fush stdout before reading from stdin
55 if (stdout->_flag&_IOLBF)
57 if (stderr->_flag&_IOLBF)
61 // if we have a dirty stream we flush it
62 if ( (f->_flag &_IODIRTY) == _IODIRTY )
67 f->_cnt = _read(fileno(f), f->_base, f->_flag & _IONBF ? 1 : f->_bufsiz );
70 if(__is_text_file(f) && f->_cnt>0)
72 /* truncate text file at Ctrl-Z */
73 char *cz=memchr(f->_base, 0x1A, f->_cnt);
76 int newcnt = cz - f->_base;
77 lseek(fileno(f), -(f->_cnt - newcnt), SEEK_CUR);
84 if (f->_flag & _IONBF)
85 f->_base = NULL; // statically allocated buffer for sprintf
102 return *f->_ptr++ & 0377;
105 wint_t _filwbuf(FILE *fp)
107 return (wint_t )_filbuf(fp);
110 // convert the carriage return line feed pairs
112 int _readcnv(int fn, void *buf, size_t siz )
114 char *bufp = (char *)buf;
119 n = _read(fn, buf, siz );
121 while (_bufsiz > 0) {
125 *bufp = *(bufp + cr);