1 | /* |
---|
2 | |
---|
3 | buffer.h |
---|
4 | |
---|
5 | Author: Tatu Ylonen <ylo@cs.hut.fi> |
---|
6 | |
---|
7 | Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
---|
8 | All rights reserved |
---|
9 | |
---|
10 | Created: Sat Mar 18 04:12:25 1995 ylo |
---|
11 | |
---|
12 | Code for manipulating FIFO buffers. |
---|
13 | |
---|
14 | */ |
---|
15 | |
---|
16 | /* |
---|
17 | * $Id: buffer.h,v 1.1.1.2 1999-03-08 17:43:42 danw Exp $ |
---|
18 | * $Log: not supported by cvs2svn $ |
---|
19 | * Revision 1.1.1.1 1996/02/18 21:38:11 ylo |
---|
20 | * Imported ssh-1.2.13. |
---|
21 | * |
---|
22 | * Revision 1.2 1995/07/13 01:18:55 ylo |
---|
23 | * Removed "Last modified" header. |
---|
24 | * Added cvs log. |
---|
25 | * |
---|
26 | * $Endlog$ |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef BUFFER_H |
---|
30 | #define BUFFER_H |
---|
31 | |
---|
32 | typedef struct |
---|
33 | { |
---|
34 | char *buf; /* Buffer for data. */ |
---|
35 | unsigned int alloc; /* Number of bytes allocated for data. */ |
---|
36 | unsigned int offset; /* Offset of first byte containing data. */ |
---|
37 | unsigned int end; /* Offset of last byte containing data. */ |
---|
38 | } Buffer; |
---|
39 | |
---|
40 | /* Initializes the buffer structure. */ |
---|
41 | void buffer_init(Buffer *buffer); |
---|
42 | |
---|
43 | /* Frees any memory used for the buffer. */ |
---|
44 | void buffer_free(Buffer *buffer); |
---|
45 | |
---|
46 | /* Clears any data from the buffer, making it empty. This does not actually |
---|
47 | zero the memory. */ |
---|
48 | void buffer_clear(Buffer *buffer); |
---|
49 | |
---|
50 | /* Appends data to the buffer, expanding it if necessary. */ |
---|
51 | void buffer_append(Buffer *buffer, const char *data, unsigned int len); |
---|
52 | |
---|
53 | /* Appends space to the buffer, expanding the buffer if necessary. |
---|
54 | This does not actually copy the data into the buffer, but instead |
---|
55 | returns a pointer to the allocated region. */ |
---|
56 | void buffer_append_space(Buffer *buffer, char **datap, unsigned int len); |
---|
57 | |
---|
58 | /* Returns the number of bytes of data in the buffer. */ |
---|
59 | unsigned int buffer_len(Buffer *buffer); |
---|
60 | |
---|
61 | /* Gets data from the beginning of the buffer. */ |
---|
62 | void buffer_get(Buffer *buffer, char *buf, unsigned int len); |
---|
63 | |
---|
64 | /* Consumes the given number of bytes from the beginning of the buffer. */ |
---|
65 | void buffer_consume(Buffer *buffer, unsigned int bytes); |
---|
66 | |
---|
67 | /* Consumes the given number of bytes from the end of the buffer. */ |
---|
68 | void buffer_consume_end(Buffer *buffer, unsigned int bytes); |
---|
69 | |
---|
70 | /* Returns a pointer to the first used byte in the buffer. */ |
---|
71 | char *buffer_ptr(Buffer *buffer); |
---|
72 | |
---|
73 | /* Dumps the contents of the buffer to stderr in hex. This intended for |
---|
74 | debugging purposes only. */ |
---|
75 | void buffer_dump(Buffer *buffer); |
---|
76 | |
---|
77 | #endif /* BUFFER_H */ |
---|