diff options
Diffstat (limited to 'other/ssharp/buffer.h')
| -rw-r--r-- | other/ssharp/buffer.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/other/ssharp/buffer.h b/other/ssharp/buffer.h new file mode 100644 index 0000000..f3c509d --- /dev/null +++ b/other/ssharp/buffer.h | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | ||
| 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | ||
| 4 | * All rights reserved | ||
| 5 | * Code for manipulating FIFO buffers. | ||
| 6 | * | ||
| 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". | ||
| 12 | */ | ||
| 13 | |||
| 14 | /* RCSID("$OpenBSD: buffer.h,v 1.7 2000/12/19 23:17:55 markus Exp $"); */ | ||
| 15 | |||
| 16 | #ifndef BUFFER_H | ||
| 17 | #define BUFFER_H | ||
| 18 | |||
| 19 | typedef struct { | ||
| 20 | char *buf; /* Buffer for data. */ | ||
| 21 | u_int alloc; /* Number of bytes allocated for data. */ | ||
| 22 | u_int offset; /* Offset of first byte containing data. */ | ||
| 23 | u_int end; /* Offset of last byte containing data. */ | ||
| 24 | } Buffer; | ||
| 25 | /* Initializes the buffer structure. */ | ||
| 26 | void buffer_init(Buffer * buffer); | ||
| 27 | |||
| 28 | /* Frees any memory used for the buffer. */ | ||
| 29 | void buffer_free(Buffer * buffer); | ||
| 30 | |||
| 31 | /* Clears any data from the buffer, making it empty. This does not actually | ||
| 32 | zero the memory. */ | ||
| 33 | void buffer_clear(Buffer * buffer); | ||
| 34 | |||
| 35 | /* Appends data to the buffer, expanding it if necessary. */ | ||
| 36 | void buffer_append(Buffer * buffer, const char *data, u_int len); | ||
| 37 | |||
| 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 | */ | ||
| 43 | void buffer_append_space(Buffer * buffer, char **datap, u_int len); | ||
| 44 | |||
| 45 | /* Returns the number of bytes of data in the buffer. */ | ||
| 46 | u_int buffer_len(Buffer * buffer); | ||
| 47 | |||
| 48 | /* Gets data from the beginning of the buffer. */ | ||
| 49 | void buffer_get(Buffer * buffer, char *buf, u_int len); | ||
| 50 | |||
| 51 | /* Consumes the given number of bytes from the beginning of the buffer. */ | ||
| 52 | void buffer_consume(Buffer * buffer, u_int bytes); | ||
| 53 | |||
| 54 | /* Consumes the given number of bytes from the end of the buffer. */ | ||
| 55 | void buffer_consume_end(Buffer * buffer, u_int bytes); | ||
| 56 | |||
| 57 | /* Returns a pointer to the first used byte in the buffer. */ | ||
| 58 | char *buffer_ptr(Buffer * buffer); | ||
| 59 | |||
| 60 | /* | ||
| 61 | * Dumps the contents of the buffer to stderr in hex. This intended for | ||
| 62 | * debugging purposes only. | ||
| 63 | */ | ||
| 64 | void buffer_dump(Buffer * buffer); | ||
| 65 | |||
| 66 | #endif /* BUFFER_H */ | ||
