/* methods common to all streamoids */ #include "io-defs.h" /* util function for cloning method vectors */ method_fun * __clone_method_vector(m, n) method_fun * m; int n; { int i; method_fun * new_vector; new_vector = (method_fun * )malloc(n * sizeof(method_fun *)); for (i = 0 ; i < n ; i++) new_vector[i] = m[i]; return(new_vector); } /* push a byte back in, works on an streamoid */ DEFMETHOD m_untyi_byte(self, ch) struct streamoid * self; int ch; { if (self->flags & STR_UNTYIED_P) /* already got one? */ return(EOF_VALUE); /* give up */ --self->file_position; self->flags |= STR_UNTYIED_P; self->untyied_char = ch; return(ch); } /* Close */ DEFMETHOD m_close(self) struct streamoid * self; { if (!(self->flags & STR_OPEN_P)) /* already closed? */ return; __force_output(self); /* flush any pending buf */ if (!(self->flags & STR_NOCLOSE_P)) method_call_0(self, METHOD_CLOSE_I); /* close up */ /* deallocate buffers and things */ if (self->buffer) free(self->buffer); /* dealloc the buf */ free(self->method); /* dealloc method vec */ __remove_open_streamoid(self); free(self); /* free the streamoid */ } /* default info method. */ DEFMETHOD m_no_info(self) struct streamoid * self; { return(INF_UNDEF); /* no info here */ }