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 );
26 if ( !OPEN4READING(f)) {
32 if (f->_flag&(_IOSTRG|_IOEOF))
34 f->_flag &= ~_IOUNGETC;
36 if (f->_base==NULL && (f->_flag&_IONBF)==0) {
38 if ((f->_base = malloc(size+1)) == NULL)
42 f->_flag &= ~(_IOFBF|_IOLBF);
56 // fush stdout before reading from stdin
58 if (stdout->_flag&_IOLBF)
60 if (stderr->_flag&_IOLBF)
64 // if we have a dirty stream we flush it
65 if ( (f->_flag &_IODIRTY) == _IODIRTY )
70 f->_cnt = _read(fileno(f), f->_base, f->_flag & _IONBF ? 1 : f->_bufsiz );
73 if(__is_text_file(f) && f->_cnt>0)
75 /* truncate text file at Ctrl-Z */
76 char *cz=memchr(f->_base, 0x1A, f->_cnt);
79 int newcnt = cz - f->_base;
80 lseek(fileno(f), -(f->_cnt - newcnt), SEEK_CUR);
87 if (f->_flag & _IONBF)
88 f->_base = NULL; // statically allocated buffer for sprintf
105 return *f->_ptr++ & 0377;
108 wint_t _filwbuf(FILE *fp)
110 return (wint_t )_filbuf(fp);
113 // convert the carriage return line feed pairs
115 int _readcnv(int fn, void *buf, size_t siz )
117 char *bufp = (char *)buf;
122 n = _read(fn, buf, siz );
124 while (_bufsiz > 0) {
128 *bufp = *(bufp + cr);