]> andersk Git - openssh.git/blame - buffer.h
- (djm) Merge OpenBSD changes:
[openssh.git] / buffer.h
CommitLineData
8efc0c15 1/*
5260325f 2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
5260325f 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5260325f 5 * Code for manipulating FIFO buffers.
35484284 6 *
bcbf86ec 7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
5260325f 12 */
8efc0c15 13
bcbf86ec 14/* RCSID("$OpenBSD: buffer.h,v 1.6 2000/09/07 20:27:50 deraadt Exp $"); */
8efc0c15 15
16#ifndef BUFFER_H
17#define BUFFER_H
18
5260325f 19typedef struct {
20 char *buf; /* Buffer for data. */
21 unsigned int alloc; /* Number of bytes allocated for data. */
22 unsigned int offset; /* Offset of first byte containing data. */
23 unsigned int end; /* Offset of last byte containing data. */
24} Buffer;
8efc0c15 25/* Initializes the buffer structure. */
5260325f 26void buffer_init(Buffer * buffer);
8efc0c15 27
28/* Frees any memory used for the buffer. */
5260325f 29void buffer_free(Buffer * buffer);
8efc0c15 30
31/* Clears any data from the buffer, making it empty. This does not actually
32 zero the memory. */
5260325f 33void buffer_clear(Buffer * buffer);
8efc0c15 34
35/* Appends data to the buffer, expanding it if necessary. */
5260325f 36void buffer_append(Buffer * buffer, const char *data, unsigned int len);
8efc0c15 37
aa3378df 38/*
39 * Appends space to the buffer, expanding the buffer if necessary. This does
40 * not actually copy the data into the buffer, but instead returns a pointer
41 * to the allocated region.
42 */
5260325f 43void buffer_append_space(Buffer * buffer, char **datap, unsigned int len);
8efc0c15 44
45/* Returns the number of bytes of data in the buffer. */
5260325f 46unsigned int buffer_len(Buffer * buffer);
8efc0c15 47
48/* Gets data from the beginning of the buffer. */
5260325f 49void buffer_get(Buffer * buffer, char *buf, unsigned int len);
8efc0c15 50
51/* Consumes the given number of bytes from the beginning of the buffer. */
5260325f 52void buffer_consume(Buffer * buffer, unsigned int bytes);
8efc0c15 53
54/* Consumes the given number of bytes from the end of the buffer. */
5260325f 55void buffer_consume_end(Buffer * buffer, unsigned int bytes);
8efc0c15 56
57/* Returns a pointer to the first used byte in the buffer. */
5260325f 58char *buffer_ptr(Buffer * buffer);
8efc0c15 59
aa3378df 60/*
61 * Dumps the contents of the buffer to stderr in hex. This intended for
62 * debugging purposes only.
63 */
5260325f 64void buffer_dump(Buffer * buffer);
8efc0c15 65
5260325f 66#endif /* BUFFER_H */
This page took 0.418817 seconds and 5 git commands to generate.