/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*/
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
#endif /* not lint */
/*
* This defines a structure for a ring buffer.
*
* The circular buffer has two parts:
* (((
* full: [consume, supply)
* empty: [supply, consume)
* ]]]
*
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/sysmacros.h>
#include "ring.h"
#include "general.h"
#define ring_subtract(d, a, b) (((a)-(b) >= 0)? \
(a)-(b): (((a)-(b))+(d)->size))
(a)+(c) : (((a)+(c))-(d)->size))
(a)-(c) : (((a)-(c))-(d)->size))
/*
* The following is a clock, used to determine full, empty, etc.
*
* There is some trickiness here. Since the ring buffers are initialized
* to ZERO on allocation, we need to make sure, when interpreting the
* clock, that when the times are EQUAL, then the buffer is FULL.
*/
((d)->consumetime >= (d)->supplytime))
((d)->supplytime > (d)->consumetime))
/* Buffer state transition routines */
int
unsigned char *buffer;
int count;
{
return (1);
}
/* Mark routines */
/*
* Mark the most recently supplied byte.
*/
void
{
}
/*
* Is the ring pointing to the mark?
*/
int
{
return (1);
} else {
return (0);
}
}
/*
* Clear any mark set on the ring.
*/
void
{
}
/*
* Add characters from current segment to ring buffer.
*/
void
int count;
{
}
/*
* We have just consumed "c" bytes.
*/
void
int count;
{
if (count == 0) /* don't update anything */
return;
}
/*
* Try to encourage "ring_empty_consecutive()" to be large.
*/
if (ring_empty(ring)) {
}
}
/* Buffer state query routines */
/* Number of bytes that may be supplied */
int
{
} else {
}
}
/* number of CONSECUTIVE bytes that may be supplied */
int
{
/*
* if consume is "below" supply, or empty, then
* return distance to the top
*/
} else {
/*
* else, return what we may.
*/
}
}
/*
* Return the number of bytes that are available for consuming
* (but don't give more than enough to get to cross over set mark)
*/
int
{
} else {
}
} else {
}
}
/*
* Return the number of CONSECUTIVE bytes available for consuming.
* However, don't return more than enough to cross over set mark.
*/
int
{
} else {
}
} else {
} else { /* Else, distance to mark */
}
}
}
/*
* Move data into the "supply" portion of of the ring buffer.
*/
void
unsigned char *buffer;
int count;
{
int i;
while (count) {
ring_supplied(ring, i);
count -= i;
buffer += i;
}
}
#ifdef notdef
/*
* Move data from the "consume" portion of the ring buffer
*/
void
unsigned char *buffer;
int count;
{
int i;
while (count) {
ring_consumed(ring, i);
count -= i;
buffer += i;
}
}
#endif
void
void (*encryptor)();
{
unsigned char *s, *c;
return;
if (s <= c) {
} else
(*encryptor)(c, s - c);
}
void
{
if (!ring_empty(ring))
else
}