1570af302Sopenharmony_ci#include <stdio_impl.h> 2570af302Sopenharmony_ci 3570af302Sopenharmony_ciint __toread(FILE *f) 4570af302Sopenharmony_ci{ 5570af302Sopenharmony_ci f->mode |= f->mode-1; 6570af302Sopenharmony_ci if (f->wpos != f->wbase) f->write(f, 0, 0); 7570af302Sopenharmony_ci f->wpos = f->wbase = f->wend = 0; 8570af302Sopenharmony_ci if (f->flags & F_NORD) { 9570af302Sopenharmony_ci f->flags |= F_ERR; 10570af302Sopenharmony_ci return EOF; 11570af302Sopenharmony_ci } 12570af302Sopenharmony_ci 13570af302Sopenharmony_ci /* Alloc file buffer if needed */ 14570af302Sopenharmony_ci if (__falloc_buf(f) < 0) { 15570af302Sopenharmony_ci f->flags |= F_ERR; 16570af302Sopenharmony_ci return EOF; 17570af302Sopenharmony_ci } 18570af302Sopenharmony_ci 19570af302Sopenharmony_ci f->rpos = f->rend = f->buf + f->buf_size; 20570af302Sopenharmony_ci 21570af302Sopenharmony_ci return (f->flags & F_EOF) ? EOF : 0; 22570af302Sopenharmony_ci} 23570af302Sopenharmony_ci 24570af302Sopenharmony_cihidden void __toread_needs_stdio_exit() 25570af302Sopenharmony_ci{ 26570af302Sopenharmony_ci __stdio_exit_needed(); 27570af302Sopenharmony_ci} 28