home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_08_12
/
8n12046a
< prev
next >
Wrap
Text File
|
1990-10-15
|
1KB
|
46 lines
/*
* RING.C
*
* ring buffer routines
*
*/
#include "char.h"
/*
* r_write()
*
* r_write() puts a byte in the buffer. when is the buffer full?
* when writing 1 more byte would set the read and write indices
* equal to each other (which means the buffer is empty!!). does
* nothing but return if it can't write the byte without
* overflowing the buffer... if this was a real multi-tasking
* system, we could sleep until somebody reads a byte, which
* would allow us to do our write, but it isn't, so...
*/
void r_write(c)
char c;
{
if (((w_index + 1) & RLIMIT) == r_index)
return;
r_buf[ w_index++ ] = c;
w_index &= RLIMIT; /* wrap the index around */
}
/*
* r_puti()
*
* r_puti() converts a small (0 - 99) decimal number into two
* ASCII digits and put them in the ring buffer
*/
void r_puti(c)
char c;
{
r_write((c / 10) + '0');
r_write((c % 10) + '0');
}