buffer.h revision 60573
157429Smarkm/*
260573Skris *
357429Smarkm * buffer.h
460573Skris *
557429Smarkm * Author: Tatu Ylonen <ylo@cs.hut.fi>
660573Skris *
757429Smarkm * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
857429Smarkm *                    All rights reserved
960573Skris *
1057429Smarkm * Created: Sat Mar 18 04:12:25 1995 ylo
1160573Skris *
1257429Smarkm * Code for manipulating FIFO buffers.
1360573Skris *
1457429Smarkm */
1557429Smarkm
1660573Skris/* RCSID("$Id: buffer.h,v 1.4 2000/04/14 10:30:30 markus Exp $"); */
1757429Smarkm
1857429Smarkm#ifndef BUFFER_H
1957429Smarkm#define BUFFER_H
2057429Smarkm
2157429Smarkmtypedef struct {
2257429Smarkm	char   *buf;		/* Buffer for data. */
2357429Smarkm	unsigned int alloc;	/* Number of bytes allocated for data. */
2457429Smarkm	unsigned int offset;	/* Offset of first byte containing data. */
2557429Smarkm	unsigned int end;	/* Offset of last byte containing data. */
2657429Smarkm}       Buffer;
2757429Smarkm/* Initializes the buffer structure. */
2857429Smarkmvoid    buffer_init(Buffer * buffer);
2957429Smarkm
3057429Smarkm/* Frees any memory used for the buffer. */
3157429Smarkmvoid    buffer_free(Buffer * buffer);
3257429Smarkm
3357429Smarkm/* Clears any data from the buffer, making it empty.  This does not actually
3457429Smarkm   zero the memory. */
3557429Smarkmvoid    buffer_clear(Buffer * buffer);
3657429Smarkm
3757429Smarkm/* Appends data to the buffer, expanding it if necessary. */
3857429Smarkmvoid    buffer_append(Buffer * buffer, const char *data, unsigned int len);
3957429Smarkm
4057429Smarkm/*
4157429Smarkm * Appends space to the buffer, expanding the buffer if necessary. This does
4257429Smarkm * not actually copy the data into the buffer, but instead returns a pointer
4357429Smarkm * to the allocated region.
4457429Smarkm */
4557429Smarkmvoid    buffer_append_space(Buffer * buffer, char **datap, unsigned int len);
4657429Smarkm
4757429Smarkm/* Returns the number of bytes of data in the buffer. */
4857429Smarkmunsigned int buffer_len(Buffer * buffer);
4957429Smarkm
5057429Smarkm/* Gets data from the beginning of the buffer. */
5157429Smarkmvoid    buffer_get(Buffer * buffer, char *buf, unsigned int len);
5257429Smarkm
5357429Smarkm/* Consumes the given number of bytes from the beginning of the buffer. */
5457429Smarkmvoid    buffer_consume(Buffer * buffer, unsigned int bytes);
5557429Smarkm
5657429Smarkm/* Consumes the given number of bytes from the end of the buffer. */
5757429Smarkmvoid    buffer_consume_end(Buffer * buffer, unsigned int bytes);
5857429Smarkm
5957429Smarkm/* Returns a pointer to the first used byte in the buffer. */
6057429Smarkmchar   *buffer_ptr(Buffer * buffer);
6157429Smarkm
6257429Smarkm/*
6357429Smarkm * Dumps the contents of the buffer to stderr in hex.  This intended for
6457429Smarkm * debugging purposes only.
6557429Smarkm */
6657429Smarkmvoid    buffer_dump(Buffer * buffer);
6757429Smarkm
6857429Smarkm#endif				/* BUFFER_H */
69