membuf: Rename struct
Rename the struct to match the function prefix and filenames. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -44,7 +44,7 @@ void sandbox_serial_endisable(bool enabled);
|
|||||||
* @buf: holds input characters available to be read by this driver
|
* @buf: holds input characters available to be read by this driver
|
||||||
*/
|
*/
|
||||||
struct sandbox_serial_priv {
|
struct sandbox_serial_priv {
|
||||||
struct membuff buf;
|
struct membuf buf;
|
||||||
char serial_buf[16];
|
char serial_buf[16];
|
||||||
bool start_of_line;
|
bool start_of_line;
|
||||||
};
|
};
|
||||||
|
@@ -108,7 +108,7 @@ static int extlinux_check(struct udevice *dev, struct bootflow_iter *iter)
|
|||||||
*/
|
*/
|
||||||
static int extlinux_fill_info(struct bootflow *bflow)
|
static int extlinux_fill_info(struct bootflow *bflow)
|
||||||
{
|
{
|
||||||
struct membuff mb;
|
struct membuf mb;
|
||||||
char line[200];
|
char line[200];
|
||||||
char *data;
|
char *data;
|
||||||
int len;
|
int len;
|
||||||
|
@@ -101,7 +101,7 @@ static void console_record_putc(const char c)
|
|||||||
if (!(gd->flags & GD_FLG_RECORD))
|
if (!(gd->flags & GD_FLG_RECORD))
|
||||||
return;
|
return;
|
||||||
if (gd->console_out.start &&
|
if (gd->console_out.start &&
|
||||||
!membuf_putbyte((struct membuff *)&gd->console_out, c))
|
!membuf_putbyte((struct membuf *)&gd->console_out, c))
|
||||||
gd->flags |= GD_FLG_RECORD_OVF;
|
gd->flags |= GD_FLG_RECORD_OVF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ static void console_record_puts(const char *s)
|
|||||||
if (gd->console_out.start) {
|
if (gd->console_out.start) {
|
||||||
int len = strlen(s);
|
int len = strlen(s);
|
||||||
|
|
||||||
if (membuf_put((struct membuff *)&gd->console_out, s, len) !=
|
if (membuf_put((struct membuf *)&gd->console_out, s, len) !=
|
||||||
len)
|
len)
|
||||||
gd->flags |= GD_FLG_RECORD_OVF;
|
gd->flags |= GD_FLG_RECORD_OVF;
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ static int console_record_getc(void)
|
|||||||
if (!gd->console_in.start)
|
if (!gd->console_in.start)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return membuf_getbyte((struct membuff *)&gd->console_in);
|
return membuf_getbyte((struct membuf *)&gd->console_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int console_record_tstc(void)
|
static int console_record_tstc(void)
|
||||||
@@ -133,7 +133,7 @@ static int console_record_tstc(void)
|
|||||||
if (!(gd->flags & GD_FLG_RECORD))
|
if (!(gd->flags & GD_FLG_RECORD))
|
||||||
return 0;
|
return 0;
|
||||||
if (gd->console_in.start) {
|
if (gd->console_in.start) {
|
||||||
if (membuf_peekbyte((struct membuff *)&gd->console_in) != -1)
|
if (membuf_peekbyte((struct membuf *)&gd->console_in) != -1)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -810,13 +810,13 @@ int console_record_init(void)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = membuf_new((struct membuff *)&gd->console_out,
|
ret = membuf_new((struct membuf *)&gd->console_out,
|
||||||
gd->flags & GD_FLG_RELOC ?
|
gd->flags & GD_FLG_RELOC ?
|
||||||
CONFIG_CONSOLE_RECORD_OUT_SIZE :
|
CONFIG_CONSOLE_RECORD_OUT_SIZE :
|
||||||
CONFIG_CONSOLE_RECORD_OUT_SIZE_F);
|
CONFIG_CONSOLE_RECORD_OUT_SIZE_F);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
ret = membuf_new((struct membuff *)&gd->console_in,
|
ret = membuf_new((struct membuf *)&gd->console_in,
|
||||||
CONFIG_CONSOLE_RECORD_IN_SIZE);
|
CONFIG_CONSOLE_RECORD_IN_SIZE);
|
||||||
|
|
||||||
/* Start recording from the beginning */
|
/* Start recording from the beginning */
|
||||||
@@ -827,8 +827,8 @@ int console_record_init(void)
|
|||||||
|
|
||||||
void console_record_reset(void)
|
void console_record_reset(void)
|
||||||
{
|
{
|
||||||
membuf_purge((struct membuff *)&gd->console_out);
|
membuf_purge((struct membuf *)&gd->console_out);
|
||||||
membuf_purge((struct membuff *)&gd->console_in);
|
membuf_purge((struct membuf *)&gd->console_in);
|
||||||
gd->flags &= ~GD_FLG_RECORD_OVF;
|
gd->flags &= ~GD_FLG_RECORD_OVF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -847,23 +847,23 @@ int console_record_readline(char *str, int maxlen)
|
|||||||
if (console_record_isempty())
|
if (console_record_isempty())
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
return membuf_readline((struct membuff *)&gd->console_out, str,
|
return membuf_readline((struct membuf *)&gd->console_out, str,
|
||||||
maxlen, '\0', false);
|
maxlen, '\0', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int console_record_avail(void)
|
int console_record_avail(void)
|
||||||
{
|
{
|
||||||
return membuf_avail((struct membuff *)&gd->console_out);
|
return membuf_avail((struct membuf *)&gd->console_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool console_record_isempty(void)
|
bool console_record_isempty(void)
|
||||||
{
|
{
|
||||||
return membuf_isempty((struct membuff *)&gd->console_out);
|
return membuf_isempty((struct membuf *)&gd->console_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
int console_in_puts(const char *str)
|
int console_in_puts(const char *str)
|
||||||
{
|
{
|
||||||
return membuf_put((struct membuff *)&gd->console_in, str, strlen(str));
|
return membuf_put((struct membuf *)&gd->console_in, str, strlen(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -38,7 +38,7 @@ enum {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct sandbox_keyb_priv {
|
struct sandbox_keyb_priv {
|
||||||
struct membuff in;
|
struct membuf in;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sandbox_keyb_plat {
|
struct sandbox_keyb_plat {
|
||||||
|
@@ -316,14 +316,14 @@ struct global_data {
|
|||||||
*
|
*
|
||||||
* This buffer is used to collect output during console recording.
|
* This buffer is used to collect output during console recording.
|
||||||
*/
|
*/
|
||||||
struct membuff console_out;
|
struct membuf console_out;
|
||||||
/**
|
/**
|
||||||
* @console_in: input buffer for console recording
|
* @console_in: input buffer for console recording
|
||||||
*
|
*
|
||||||
* If console recording is activated, this buffer can be used to
|
* If console recording is activated, this buffer can be used to
|
||||||
* emulate input.
|
* emulate input.
|
||||||
*/
|
*/
|
||||||
struct membuff console_in;
|
struct membuf console_in;
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_IS_ENABLED(VIDEO)
|
#if CONFIG_IS_ENABLED(VIDEO)
|
||||||
/**
|
/**
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
#define _membuf_H
|
#define _membuf_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct membuff: holds the state of a membuff - it is used for input and
|
* @struct membuf: holds the state of a membuff - it is used for input and
|
||||||
* output buffers. The buffer extends from @start to (@start + @size - 1).
|
* output buffers. The buffer extends from @start to (@start + @size - 1).
|
||||||
* Data in the buffer extends from @tail to @head: it is written in at
|
* Data in the buffer extends from @tail to @head: it is written in at
|
||||||
* @head and read out from @tail. The membuff is empty when @head == @tail
|
* @head and read out from @tail. The membuff is empty when @head == @tail
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
* ^ ^
|
* ^ ^
|
||||||
* head tail
|
* head tail
|
||||||
*/
|
*/
|
||||||
struct membuff {
|
struct membuf {
|
||||||
char *start; /** the start of the buffer */
|
char *start; /** the start of the buffer */
|
||||||
char *end; /** the end of the buffer (start + length) */
|
char *end; /** the end of the buffer (start + length) */
|
||||||
char *head; /** current buffer head */
|
char *head; /** current buffer head */
|
||||||
@@ -43,7 +43,7 @@ struct membuff {
|
|||||||
*
|
*
|
||||||
* @mb: membuff to purge
|
* @mb: membuff to purge
|
||||||
*/
|
*/
|
||||||
void membuf_purge(struct membuff *mb);
|
void membuf_purge(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_putraw() - find out where bytes can be written
|
* membuf_putraw() - find out where bytes can be written
|
||||||
@@ -64,7 +64,7 @@ void membuf_purge(struct membuff *mb);
|
|||||||
* @data: the address data can be written to
|
* @data: the address data can be written to
|
||||||
* Return: number of bytes which can be written
|
* Return: number of bytes which can be written
|
||||||
*/
|
*/
|
||||||
int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data);
|
int membuf_putraw(struct membuf *mb, int maxlen, bool update, char **data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_getraw() - find and return a pointer to available bytes
|
* membuf_getraw() - find and return a pointer to available bytes
|
||||||
@@ -82,7 +82,7 @@ int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data);
|
|||||||
* @data: returns address of data in input membuff
|
* @data: returns address of data in input membuff
|
||||||
* Return: the number of bytes available at *@data
|
* Return: the number of bytes available at *@data
|
||||||
*/
|
*/
|
||||||
int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data);
|
int membuf_getraw(struct membuf *mb, int maxlen, bool update, char **data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_putbyte() - Writes a byte to a membuff
|
* membuf_putbyte() - Writes a byte to a membuff
|
||||||
@@ -91,14 +91,14 @@ int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data);
|
|||||||
* @ch: byte to write
|
* @ch: byte to write
|
||||||
* Return: true on success, false if membuff is full
|
* Return: true on success, false if membuff is full
|
||||||
*/
|
*/
|
||||||
bool membuf_putbyte(struct membuff *mb, int ch);
|
bool membuf_putbyte(struct membuf *mb, int ch);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mb: membuff to adjust
|
* @mb: membuff to adjust
|
||||||
* membuf_getbyte() - Read a byte from the membuff
|
* membuf_getbyte() - Read a byte from the membuff
|
||||||
* Return: the byte read, or -1 if the membuff is empty
|
* Return: the byte read, or -1 if the membuff is empty
|
||||||
*/
|
*/
|
||||||
int membuf_getbyte(struct membuff *mb);
|
int membuf_getbyte(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_peekbyte() - check the next available byte
|
* membuf_peekbyte() - check the next available byte
|
||||||
@@ -109,7 +109,7 @@ int membuf_getbyte(struct membuff *mb);
|
|||||||
* @mb: membuff to adjust
|
* @mb: membuff to adjust
|
||||||
* Return: the byte peeked, or -1 if the membuff is empty
|
* Return: the byte peeked, or -1 if the membuff is empty
|
||||||
*/
|
*/
|
||||||
int membuf_peekbyte(struct membuff *mb);
|
int membuf_peekbyte(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_get() - get data from a membuff
|
* membuf_get() - get data from a membuff
|
||||||
@@ -122,7 +122,7 @@ int membuf_peekbyte(struct membuff *mb);
|
|||||||
* @maxlen: maximum number of bytes to read
|
* @maxlen: maximum number of bytes to read
|
||||||
* Return: the number of bytes read
|
* Return: the number of bytes read
|
||||||
*/
|
*/
|
||||||
int membuf_get(struct membuff *mb, char *buff, int maxlen);
|
int membuf_get(struct membuf *mb, char *buff, int maxlen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_put() - write data to a membuff
|
* membuf_put() - write data to a membuff
|
||||||
@@ -135,7 +135,7 @@ int membuf_get(struct membuff *mb, char *buff, int maxlen);
|
|||||||
* @length: number of bytes to write from 'data'
|
* @length: number of bytes to write from 'data'
|
||||||
* Return: the number of bytes added
|
* Return: the number of bytes added
|
||||||
*/
|
*/
|
||||||
int membuf_put(struct membuff *mb, const char *buff, int length);
|
int membuf_put(struct membuf *mb, const char *buff, int length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_isempty() - check if a membuff is empty
|
* membuf_isempty() - check if a membuff is empty
|
||||||
@@ -143,7 +143,7 @@ int membuf_put(struct membuff *mb, const char *buff, int length);
|
|||||||
* @mb: membuff to check
|
* @mb: membuff to check
|
||||||
* Return: true if empty, else false
|
* Return: true if empty, else false
|
||||||
*/
|
*/
|
||||||
bool membuf_isempty(struct membuff *mb);
|
bool membuf_isempty(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_avail() - check available data in a membuff
|
* membuf_avail() - check available data in a membuff
|
||||||
@@ -151,7 +151,7 @@ bool membuf_isempty(struct membuff *mb);
|
|||||||
* @mb: membuff to check
|
* @mb: membuff to check
|
||||||
* Return: number of bytes of data available
|
* Return: number of bytes of data available
|
||||||
*/
|
*/
|
||||||
int membuf_avail(struct membuff *mb);
|
int membuf_avail(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_size() - get the size of a membuff
|
* membuf_size() - get the size of a membuff
|
||||||
@@ -161,7 +161,7 @@ int membuf_avail(struct membuff *mb);
|
|||||||
* @mb: membuff to check
|
* @mb: membuff to check
|
||||||
* Return: total size
|
* Return: total size
|
||||||
*/
|
*/
|
||||||
int membuf_size(struct membuff *mb);
|
int membuf_size(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_makecontig() - adjust all membuff data to be contiguous
|
* membuf_makecontig() - adjust all membuff data to be contiguous
|
||||||
@@ -172,7 +172,7 @@ int membuf_size(struct membuff *mb);
|
|||||||
* @mb: membuff to adjust
|
* @mb: membuff to adjust
|
||||||
* Return: true on success
|
* Return: true on success
|
||||||
*/
|
*/
|
||||||
bool membuf_makecontig(struct membuff *mb);
|
bool membuf_makecontig(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_free() - find the number of bytes that can be written to a membuff
|
* membuf_free() - find the number of bytes that can be written to a membuff
|
||||||
@@ -180,7 +180,7 @@ bool membuf_makecontig(struct membuff *mb);
|
|||||||
* @mb: membuff to check
|
* @mb: membuff to check
|
||||||
* Return: returns the number of bytes free in a membuff
|
* Return: returns the number of bytes free in a membuff
|
||||||
*/
|
*/
|
||||||
int membuf_free(struct membuff *mb);
|
int membuf_free(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_readline() - read a line of text from a membuff
|
* membuf_readline() - read a line of text from a membuff
|
||||||
@@ -196,7 +196,7 @@ int membuf_free(struct membuff *mb);
|
|||||||
* Return: number of bytes read (including terminator) if a line has been
|
* Return: number of bytes read (including terminator) if a line has been
|
||||||
* read, 0 if nothing was there or line didn't fit when must_fit is set
|
* read, 0 if nothing was there or line didn't fit when must_fit is set
|
||||||
*/
|
*/
|
||||||
int membuf_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit);
|
int membuf_readline(struct membuf *mb, char *str, int maxlen, int minch, bool must_fit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_extend_by() - expand a membuff
|
* membuf_extend_by() - expand a membuff
|
||||||
@@ -209,7 +209,7 @@ int membuf_readline(struct membuff *mb, char *str, int maxlen, int minch, bool m
|
|||||||
* Return: 0 if the expand succeeded, -ENOMEM if not enough memory, -E2BIG
|
* Return: 0 if the expand succeeded, -ENOMEM if not enough memory, -E2BIG
|
||||||
* if the the size would exceed @max
|
* if the the size would exceed @max
|
||||||
*/
|
*/
|
||||||
int membuf_extend_by(struct membuff *mb, int by, int max);
|
int membuf_extend_by(struct membuf *mb, int by, int max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_init() - set up a new membuff using an existing membuff
|
* membuf_init() - set up a new membuff using an existing membuff
|
||||||
@@ -218,14 +218,14 @@ int membuf_extend_by(struct membuff *mb, int by, int max);
|
|||||||
* @buff: Address of buffer
|
* @buff: Address of buffer
|
||||||
* @size: Size of buffer
|
* @size: Size of buffer
|
||||||
*/
|
*/
|
||||||
void membuf_init(struct membuff *mb, char *buff, int size);
|
void membuf_init(struct membuf *mb, char *buff, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_uninit() - clear a membuff so it can no longer be used
|
* membuf_uninit() - clear a membuff so it can no longer be used
|
||||||
*
|
*
|
||||||
* @mb: membuff to uninit
|
* @mb: membuff to uninit
|
||||||
*/
|
*/
|
||||||
void membuf_uninit(struct membuff *mb);
|
void membuf_uninit(struct membuf *mb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_new() - create a new membuff
|
* membuf_new() - create a new membuff
|
||||||
@@ -234,13 +234,13 @@ void membuf_uninit(struct membuff *mb);
|
|||||||
* @size: size of membuff to create
|
* @size: size of membuff to create
|
||||||
* Return: 0 if OK, -ENOMEM if out of memory
|
* Return: 0 if OK, -ENOMEM if out of memory
|
||||||
*/
|
*/
|
||||||
int membuf_new(struct membuff *mb, int size);
|
int membuf_new(struct membuf *mb, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* membuf_dispose() - free memory allocated to a membuff and uninit it
|
* membuf_dispose() - free memory allocated to a membuff and uninit it
|
||||||
*
|
*
|
||||||
* @mb: membuff to dispose
|
* @mb: membuff to dispose
|
||||||
*/
|
*/
|
||||||
void membuf_dispose(struct membuff *mb);
|
void membuf_dispose(struct membuf *mb);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
42
lib/membuf.c
42
lib/membuf.c
@@ -11,14 +11,14 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include "membuf.h"
|
#include "membuf.h"
|
||||||
|
|
||||||
void membuf_purge(struct membuff *mb)
|
void membuf_purge(struct membuf *mb)
|
||||||
{
|
{
|
||||||
/* set mb->head and mb->tail so the buffers look empty */
|
/* set mb->head and mb->tail so the buffers look empty */
|
||||||
mb->head = mb->start;
|
mb->head = mb->start;
|
||||||
mb->tail = mb->start;
|
mb->tail = mb->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int membuf_putrawflex(struct membuff *mb, int maxlen, bool update,
|
static int membuf_putrawflex(struct membuf *mb, int maxlen, bool update,
|
||||||
char ***data, int *offsetp)
|
char ***data, int *offsetp)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
@@ -72,7 +72,7 @@ static int membuf_putrawflex(struct membuff *mb, int maxlen, bool update,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data)
|
int membuf_putraw(struct membuf *mb, int maxlen, bool update, char **data)
|
||||||
{
|
{
|
||||||
char **datap;
|
char **datap;
|
||||||
int offset;
|
int offset;
|
||||||
@@ -84,7 +84,7 @@ int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool membuf_putbyte(struct membuff *mb, int ch)
|
bool membuf_putbyte(struct membuf *mb, int ch)
|
||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ bool membuf_putbyte(struct membuff *mb, int ch)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data)
|
int membuf_getraw(struct membuf *mb, int maxlen, bool update, char **data)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
@@ -146,21 +146,21 @@ int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_getbyte(struct membuff *mb)
|
int membuf_getbyte(struct membuf *mb)
|
||||||
{
|
{
|
||||||
char *data = 0;
|
char *data = 0;
|
||||||
|
|
||||||
return membuf_getraw(mb, 1, true, &data) != 1 ? -1 : *(uint8_t *)data;
|
return membuf_getraw(mb, 1, true, &data) != 1 ? -1 : *(uint8_t *)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_peekbyte(struct membuff *mb)
|
int membuf_peekbyte(struct membuf *mb)
|
||||||
{
|
{
|
||||||
char *data = 0;
|
char *data = 0;
|
||||||
|
|
||||||
return membuf_getraw(mb, 1, false, &data) != 1 ? -1 : *(uint8_t *)data;
|
return membuf_getraw(mb, 1, false, &data) != 1 ? -1 : *(uint8_t *)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_get(struct membuff *mb, char *buff, int maxlen)
|
int membuf_get(struct membuf *mb, char *buff, int maxlen)
|
||||||
{
|
{
|
||||||
char *data = 0, *buffptr = buff;
|
char *data = 0, *buffptr = buff;
|
||||||
int len = 1, i;
|
int len = 1, i;
|
||||||
@@ -183,7 +183,7 @@ int membuf_get(struct membuff *mb, char *buff, int maxlen)
|
|||||||
return buffptr - buff;
|
return buffptr - buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_put(struct membuff *mb, const char *buff, int length)
|
int membuf_put(struct membuf *mb, const char *buff, int length)
|
||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
int towrite, i, written;
|
int towrite, i, written;
|
||||||
@@ -203,14 +203,14 @@ int membuf_put(struct membuff *mb, const char *buff, int length)
|
|||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool membuf_isempty(struct membuff *mb)
|
bool membuf_isempty(struct membuf *mb)
|
||||||
{
|
{
|
||||||
return mb->head == mb->tail;
|
return mb->head == mb->tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_avail(struct membuff *mb)
|
int membuf_avail(struct membuf *mb)
|
||||||
{
|
{
|
||||||
struct membuff copy;
|
struct membuf copy;
|
||||||
int i, avail;
|
int i, avail;
|
||||||
char *data = 0;
|
char *data = 0;
|
||||||
|
|
||||||
@@ -225,12 +225,12 @@ int membuf_avail(struct membuff *mb)
|
|||||||
return avail;
|
return avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_size(struct membuff *mb)
|
int membuf_size(struct membuf *mb)
|
||||||
{
|
{
|
||||||
return mb->end - mb->start;
|
return mb->end - mb->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool membuf_makecontig(struct membuff *mb)
|
bool membuf_makecontig(struct membuf *mb)
|
||||||
{
|
{
|
||||||
int topsize, botsize;
|
int topsize, botsize;
|
||||||
|
|
||||||
@@ -281,13 +281,13 @@ bool membuf_makecontig(struct membuff *mb)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_free(struct membuff *mb)
|
int membuf_free(struct membuf *mb)
|
||||||
{
|
{
|
||||||
return mb->end == mb->start ? 0 :
|
return mb->end == mb->start ? 0 :
|
||||||
(mb->end - mb->start) - 1 - membuf_avail(mb);
|
(mb->end - mb->start) - 1 - membuf_avail(mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit)
|
int membuf_readline(struct membuf *mb, char *str, int maxlen, int minch, bool must_fit)
|
||||||
{
|
{
|
||||||
int len; /* number of bytes read (!= string length) */
|
int len; /* number of bytes read (!= string length) */
|
||||||
char *s, *end;
|
char *s, *end;
|
||||||
@@ -322,7 +322,7 @@ int membuf_readline(struct membuff *mb, char *str, int maxlen, int minch, bool m
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_extend_by(struct membuff *mb, int by, int max)
|
int membuf_extend_by(struct membuf *mb, int by, int max)
|
||||||
{
|
{
|
||||||
int oldhead, oldtail;
|
int oldhead, oldtail;
|
||||||
int size, orig;
|
int size, orig;
|
||||||
@@ -358,14 +358,14 @@ int membuf_extend_by(struct membuff *mb, int by, int max)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void membuf_init(struct membuff *mb, char *buff, int size)
|
void membuf_init(struct membuf *mb, char *buff, int size)
|
||||||
{
|
{
|
||||||
mb->start = buff;
|
mb->start = buff;
|
||||||
mb->end = mb->start + size;
|
mb->end = mb->start + size;
|
||||||
membuf_purge(mb);
|
membuf_purge(mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int membuf_new(struct membuff *mb, int size)
|
int membuf_new(struct membuf *mb, int size)
|
||||||
{
|
{
|
||||||
mb->start = malloc(size);
|
mb->start = malloc(size);
|
||||||
if (!mb->start)
|
if (!mb->start)
|
||||||
@@ -375,14 +375,14 @@ int membuf_new(struct membuff *mb, int size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void membuf_uninit(struct membuff *mb)
|
void membuf_uninit(struct membuf *mb)
|
||||||
{
|
{
|
||||||
mb->end = NULL;
|
mb->end = NULL;
|
||||||
mb->start = NULL;
|
mb->start = NULL;
|
||||||
membuf_purge(mb);
|
membuf_purge(mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void membuf_dispose(struct membuff *mb)
|
void membuf_dispose(struct membuf *mb)
|
||||||
{
|
{
|
||||||
free(&mb->start);
|
free(&mb->start);
|
||||||
membuf_uninit(mb);
|
membuf_uninit(mb);
|
||||||
|
Reference in New Issue
Block a user