+
+
+/*
+ * Allocate a tty structure and its associated buffers.
+ */
+struct tty *
+ttymalloc(itp)
+ struct tty *itp;
+{
+ struct tty *tp;
+
+#ifndef broken
+ /*
+ * Note that the itp input is not necessary when we can dealloc
+ * the struct tty.
+ */
+ if(itp == NULL) {
+ MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK);
+ bzero(tp, sizeof *tp);
+ } else {
+ tp = itp;
+ }
+#endif
+ if(tp->t_raw == NULL) {
+ MALLOC(tp->t_raw, struct ringb *, sizeof(struct ringb), M_TTYS, M_WAITOK);
+ bzero(tp->t_raw, sizeof *tp->t_raw);
+ }
+ if(tp->t_can == NULL) {
+ MALLOC(tp->t_can, struct ringb *, sizeof(struct ringb), M_TTYS, M_WAITOK);
+ bzero(tp->t_can, sizeof *tp->t_can);
+ }
+ if(tp->t_out == NULL) {
+ MALLOC(tp->t_out, struct ringb *, sizeof(struct ringb), M_TTYS, M_WAITOK);
+ bzero(tp->t_out, sizeof *tp->t_out);
+ }
+ return(tp);
+}
+
+/*
+ * Free a tty structure and its buffers.
+ */
+void
+ttyfree(tp)
+struct tty *tp;
+{
+ FREE(tp->t_raw, M_TTYS);
+ FREE(tp->t_can, M_TTYS);
+ FREE(tp->t_out, M_TTYS);
+ tp->t_raw = tp->t_can = tp->t_out = NULL;
+#ifdef broken /* session holds a ref to the tty; can't deallocate */
+ /* also set tp to NULL when this isn't broken anymore */
+ FREE(tp, M_TTYS);
+#endif
+}