home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctcoll95.zip / BASTELST / PAPI020.ZIP / BUF.C < prev    next >
C/C++ Source or Header  |  1993-10-06  |  1KB  |  85 lines

  1. /* Common ISDN API C-Library Functions: buffer handling
  2.     Author: Dietmar Friede
  3. Copyright (c) 1992 D.Friede
  4.  #include "copy"
  5.  #include "copying.doc"
  6. */
  7. #include "stdio.h"
  8. #include "types.h"
  9.  
  10. typedef byte buf[2064];
  11. static buf sendbuf[4];
  12. static byte far *freelist[4];
  13. static int free, head, tail;
  14.  
  15. void
  16. init_buf(void)
  17. {
  18.     int i;
  19.     for(i= 0; i<4; i++) freelist[i]= sendbuf[i];
  20.     free= 4; head= tail= 0;
  21. }
  22.  
  23. byte far * getbuf(void)
  24. {
  25.     byte far * p;
  26.     if( free == 0) return null;
  27.     free --;
  28.     p= freelist[head];
  29.     freelist[head++]= null;
  30.     head&=0x3;
  31.     return(p);
  32. }
  33.  
  34. void
  35. freebuf(byte far *p)
  36. {
  37.     if(p == null)
  38.     {
  39.         printf("buffer problem\n");
  40.         return;
  41.     }
  42.     free++;
  43.     if(free>4)
  44.     {
  45.         free= 4;
  46.         printf("panic buffer\n");
  47.         return;
  48.     }
  49.     freelist[tail++]= p;
  50.     tail&= 0x3;
  51. }
  52.  
  53. typedef byte mbuf[190];
  54. static mbuf messages[4];
  55. static char took[4];
  56. extern byte is_api_int;
  57.  
  58. byte far * getmsg(void)
  59. {
  60.     if(is_api_int&0xfc)
  61.     {
  62.         printf("panic msg problem %d ..\n",is_api_int);
  63.         if(is_api_int<0) is_api_int= 0;
  64.         return null;
  65.     }
  66.     if(took[is_api_int]++)
  67.     {
  68.         printf("panic msg took %d\n",is_api_int);
  69.         return null;
  70.     }
  71.  
  72.     return(messages[is_api_int]);
  73. }
  74.  
  75. void
  76. freemsg(byte far *p)
  77. {
  78.     took[is_api_int]--;
  79.     if(p == null)
  80.     {
  81.         printf("buffer problem\n");
  82.         return;
  83.     }
  84. }
  85.