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 >
Wrap
C/C++ Source or Header
|
1993-10-06
|
1KB
|
85 lines
/* Common ISDN API C-Library Functions: buffer handling
Author: Dietmar Friede
Copyright (c) 1992 D.Friede
#include "copy"
#include "copying.doc"
*/
#include "stdio.h"
#include "types.h"
typedef byte buf[2064];
static buf sendbuf[4];
static byte far *freelist[4];
static int free, head, tail;
void
init_buf(void)
{
int i;
for(i= 0; i<4; i++) freelist[i]= sendbuf[i];
free= 4; head= tail= 0;
}
byte far * getbuf(void)
{
byte far * p;
if( free == 0) return null;
free --;
p= freelist[head];
freelist[head++]= null;
head&=0x3;
return(p);
}
void
freebuf(byte far *p)
{
if(p == null)
{
printf("buffer problem\n");
return;
}
free++;
if(free>4)
{
free= 4;
printf("panic buffer\n");
return;
}
freelist[tail++]= p;
tail&= 0x3;
}
typedef byte mbuf[190];
static mbuf messages[4];
static char took[4];
extern byte is_api_int;
byte far * getmsg(void)
{
if(is_api_int&0xfc)
{
printf("panic msg problem %d ..\n",is_api_int);
if(is_api_int<0) is_api_int= 0;
return null;
}
if(took[is_api_int]++)
{
printf("panic msg took %d\n",is_api_int);
return null;
}
return(messages[is_api_int]);
}
void
freemsg(byte far *p)
{
took[is_api_int]--;
if(p == null)
{
printf("buffer problem\n");
return;
}
}