5 Author: Tatu Ylonen <ylo@cs.hut.fi>
7 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
10 Created: Sat Mar 18 04:12:25 1995 ylo
12 Code for manipulating FIFO buffers.
23 char *buf; /* Buffer for data. */
24 unsigned int alloc; /* Number of bytes allocated for data. */
25 unsigned int offset; /* Offset of first byte containing data. */
26 unsigned int end; /* Offset of last byte containing data. */
29 /* Initializes the buffer structure. */
30 void buffer_init(Buffer *buffer);
32 /* Frees any memory used for the buffer. */
33 void buffer_free(Buffer *buffer);
35 /* Clears any data from the buffer, making it empty. This does not actually
37 void buffer_clear(Buffer *buffer);
39 /* Appends data to the buffer, expanding it if necessary. */
40 void buffer_append(Buffer *buffer, const char *data, unsigned int len);
42 /* Appends space to the buffer, expanding the buffer if necessary.
43 This does not actually copy the data into the buffer, but instead
44 returns a pointer to the allocated region. */
45 void buffer_append_space(Buffer *buffer, char **datap, unsigned int len);
47 /* Returns the number of bytes of data in the buffer. */
48 unsigned int buffer_len(Buffer *buffer);
50 /* Gets data from the beginning of the buffer. */
51 void buffer_get(Buffer *buffer, char *buf, unsigned int len);
53 /* Consumes the given number of bytes from the beginning of the buffer. */
54 void buffer_consume(Buffer *buffer, unsigned int bytes);
56 /* Consumes the given number of bytes from the end of the buffer. */
57 void buffer_consume_end(Buffer *buffer, unsigned int bytes);
59 /* Returns a pointer to the first used byte in the buffer. */
60 char *buffer_ptr(Buffer *buffer);
62 /* Dumps the contents of the buffer to stderr in hex. This intended for
63 debugging purposes only. */
64 void buffer_dump(Buffer *buffer);