1570af302Sopenharmony_ci#include "stdio_impl.h" 2570af302Sopenharmony_ci 3570af302Sopenharmony_ciint __towrite(FILE *f) 4570af302Sopenharmony_ci{ 5570af302Sopenharmony_ci f->mode |= f->mode-1; 6570af302Sopenharmony_ci if (f->flags & F_NOWR) { 7570af302Sopenharmony_ci f->flags |= F_ERR; 8570af302Sopenharmony_ci return EOF; 9570af302Sopenharmony_ci } 10570af302Sopenharmony_ci /* Clear read buffer (easier than summoning nasal demons) */ 11570af302Sopenharmony_ci f->rpos = f->rend = 0; 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 /* Activate write through the buffer. */ 20570af302Sopenharmony_ci f->wpos = f->wbase = f->buf; 21570af302Sopenharmony_ci f->wend = f->buf + f->buf_size; 22570af302Sopenharmony_ci return 0; 23570af302Sopenharmony_ci} 24570af302Sopenharmony_ci 25570af302Sopenharmony_cihidden void __towrite_needs_stdio_exit() 26570af302Sopenharmony_ci{ 27570af302Sopenharmony_ci __stdio_exit_needed(); 28570af302Sopenharmony_ci} 29