/* File : ibuff.c buffer management functions */ /* Copyright (C) 1992 Indian Institute of Technology, Bombay Written by V. Srinivas and Nitin Kaulavkar, Dept of Computer Science and Engineering. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "yapcbr.h" #include "ipxwatch.h" #include "sap.h" #include "ipxrip.h" extern struct sap_tbl *sap_q_h, *sap_q_t; extern struct rip_table *rip_q_h,*rip_q_t; void *ibuf_alloc(int type); void ibuf_free(void *buff, int type); /* allocate buffers for the sap table and rip table */ void *ibuf_alloc(int type) { void *tmp; switch(type){ case NOVLSAP: if(sap_q_h == 0) return(malloc(sizeof(struct sap_tbl))); else{ tmp = sap_q_h; sap_q_h = sap_q_h->next; return(tmp); } break; case NOVLRIP: if(rip_q_h == 0) return(malloc(sizeof(struct rip_table))); else{ tmp = rip_q_h; rip_q_h = rip_q_h->next; return(tmp); } break; default: break; } return(NULL); } /* return buffer to the buffer pool */ void ibuf_free(void *buff,int type) { switch(type){ case NOVLSAP: if(sap_q_h == 0){ sap_q_h = sap_q_t = (struct sap_tbl *)buff; ((struct sap_tbl *)buff)->next = 0; } else{ /* append to the tail of the queue */ ((struct sap_tbl *)buff)->next = 0; sap_q_t->next = (struct sap_tbl *)buff; sap_q_t = (struct sap_tbl *)buff; } break; case NOVLRIP: if(rip_q_h == 0){ rip_q_h = rip_q_t = (struct rip_table *)buff; ((struct rip_table *)buff)->next = 0; } else{ /* append to the tail of the queue */ ((struct rip_table *)buff)->next = 0; rip_q_t->next = (struct rip_table *)buff; rip_q_t = (struct rip_table *)buff; } break; default: break; } }