From 4662e5286aa259e158f314157d0d8f2ad213a321 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 18 Mar 2025 16:20:42 +0100 Subject: membuff: Rename functions to have membuf_ prefix The double 'f' is not necessary and is a bit annoying as elsewhere in U-Boot we use 'buf'. Rename all the functions before it is used more widely. Signed-off-by: Simon Glass --- include/membuff.h | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'include') diff --git a/include/membuff.h b/include/membuff.h index 4eba626ce1c..c7370e1c072 100644 --- a/include/membuff.h +++ b/include/membuff.h @@ -6,8 +6,8 @@ * Copyright (c) 1992 Simon Glass */ -#ifndef _MEMBUFF_H -#define _MEMBUFF_H +#ifndef _membuf_H +#define _membuf_H /** * @struct membuff: holds the state of a membuff - it is used for input and @@ -37,16 +37,16 @@ struct membuff { }; /** - * membuff_purge() - reset a membuff to the empty state + * membuf_purge() - reset a membuff to the empty state * * Initialise head and tail pointers so that the membuff becomes empty. * * @mb: membuff to purge */ -void membuff_purge(struct membuff *mb); +void membuf_purge(struct membuff *mb); /** - * membuff_putraw() - find out where bytes can be written + * membuf_putraw() - find out where bytes can be written * * Work out where in the membuff some data could be written. Return a pointer * to the address and the number of bytes which can be written there. If @@ -64,10 +64,10 @@ void membuff_purge(struct membuff *mb); * @data: the address data can be written to * Return: number of bytes which can be written */ -int membuff_putraw(struct membuff *mb, int maxlen, bool update, char **data); +int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data); /** - * membuff_getraw() - find and return a pointer to available bytes + * membuf_getraw() - find and return a pointer to available bytes * * Returns a pointer to any valid input data in the given membuff and * optionally marks it as read. Note that not all input data may not be @@ -82,37 +82,37 @@ int membuff_putraw(struct membuff *mb, int maxlen, bool update, char **data); * @data: returns address of data in input membuff * Return: the number of bytes available at *@data */ -int membuff_getraw(struct membuff *mb, int maxlen, bool update, char **data); +int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data); /** - * membuff_putbyte() - Writes a byte to a membuff + * membuf_putbyte() - Writes a byte to a membuff * * @mb: membuff to adjust * @ch: byte to write * Return: true on success, false if membuff is full */ -bool membuff_putbyte(struct membuff *mb, int ch); +bool membuf_putbyte(struct membuff *mb, int ch); /** * @mb: membuff to adjust - * membuff_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 */ -int membuff_getbyte(struct membuff *mb); +int membuf_getbyte(struct membuff *mb); /** - * membuff_peekbyte() - check the next available byte + * membuf_peekbyte() - check the next available byte * - * Return the next byte which membuff_getbyte() would return, without + * Return the next byte which membuf_getbyte() would return, without * removing it from the membuff. * * @mb: membuff to adjust * Return: the byte peeked, or -1 if the membuff is empty */ -int membuff_peekbyte(struct membuff *mb); +int membuf_peekbyte(struct membuff *mb); /** - * membuff_get() - get data from a membuff + * membuf_get() - get data from a membuff * * Copies any available data (up to @maxlen bytes) to @buff and removes it * from the membuff. @@ -122,10 +122,10 @@ int membuff_peekbyte(struct membuff *mb); * @maxlen: maximum number of bytes to read * Return: the number of bytes read */ -int membuff_get(struct membuff *mb, char *buff, int maxlen); +int membuf_get(struct membuff *mb, char *buff, int maxlen); /** - * membuff_put() - write data to a membuff + * membuf_put() - write data to a membuff * * Writes some data to a membuff. Returns the number of bytes added. If this * is less than @lnehgt, then the membuff got full @@ -135,36 +135,36 @@ int membuff_get(struct membuff *mb, char *buff, int maxlen); * @length: number of bytes to write from 'data' * Return: the number of bytes added */ -int membuff_put(struct membuff *mb, const char *buff, int length); +int membuf_put(struct membuff *mb, const char *buff, int length); /** - * membuff_isempty() - check if a membuff is empty + * membuf_isempty() - check if a membuff is empty * * @mb: membuff to check * Return: true if empty, else false */ -bool membuff_isempty(struct membuff *mb); +bool membuf_isempty(struct membuff *mb); /** - * membuff_avail() - check available data in a membuff + * membuf_avail() - check available data in a membuff * * @mb: membuff to check * Return: number of bytes of data available */ -int membuff_avail(struct membuff *mb); +int membuf_avail(struct membuff *mb); /** - * membuff_size() - get the size of a membuff + * membuf_size() - get the size of a membuff * * Note that a membuff can only old data up to one byte less than its size. * * @mb: membuff to check * Return: total size */ -int membuff_size(struct membuff *mb); +int membuf_size(struct membuff *mb); /** - * membuff_makecontig() - adjust all membuff data to be contiguous + * membuf_makecontig() - adjust all membuff data to be contiguous * * This places all data in a membuff into a single contiguous lump, if * possible @@ -172,18 +172,18 @@ int membuff_size(struct membuff *mb); * @mb: membuff to adjust * Return: true on success */ -bool membuff_makecontig(struct membuff *mb); +bool membuf_makecontig(struct membuff *mb); /** - * membuff_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 * * @mb: membuff to check * Return: returns the number of bytes free in a membuff */ -int membuff_free(struct membuff *mb); +int membuf_free(struct membuff *mb); /** - * membuff_readline() - read a line of text from a membuff + * membuf_readline() - read a line of text from a membuff * * Reads a line of text of up to 'maxlen' characters from a membuff and puts * it in @str. Any character less than @minch is assumed to be the end of @@ -196,10 +196,10 @@ int membuff_free(struct membuff *mb); * 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 */ -int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit); +int membuf_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit); /** - * membuff_extend_by() - expand a membuff + * membuf_extend_by() - expand a membuff * * Extends a membuff by the given number of bytes * @@ -209,38 +209,38 @@ int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch, bool * Return: 0 if the expand succeeded, -ENOMEM if not enough memory, -E2BIG * if the the size would exceed @max */ -int membuff_extend_by(struct membuff *mb, int by, int max); +int membuf_extend_by(struct membuff *mb, int by, int max); /** - * membuff_init() - set up a new membuff using an existing membuff + * membuf_init() - set up a new membuff using an existing membuff * * @mb: membuff to set up * @buff: Address of buffer * @size: Size of buffer */ -void membuff_init(struct membuff *mb, char *buff, int size); +void membuf_init(struct membuff *mb, char *buff, int size); /** - * membuff_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 */ -void membuff_uninit(struct membuff *mb); +void membuf_uninit(struct membuff *mb); /** - * membuff_new() - create a new membuff + * membuf_new() - create a new membuff * * @mb: membuff to init * @size: size of membuff to create * Return: 0 if OK, -ENOMEM if out of memory */ -int membuff_new(struct membuff *mb, int size); +int membuf_new(struct membuff *mb, int size); /** - * membuff_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 */ -void membuff_dispose(struct membuff *mb); +void membuf_dispose(struct membuff *mb); #endif -- cgit v1.2.3 From 9ca1789ff099a364c6e16dcb6f6ad2e8677f32f1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 18 Mar 2025 16:20:43 +0100 Subject: membuff: Rename the files to membuf Rename the C and header files to use the membuf basename, to match the functions. Add a MAINTAINERS entry while we are here. Signed-off-by: Simon Glass --- include/asm-generic/global_data.h | 2 +- include/membuf.h | 246 ++++++++++++++++++++++++++++++++++++++ include/membuff.h | 246 -------------------------------------- 3 files changed, 247 insertions(+), 247 deletions(-) create mode 100644 include/membuf.h delete mode 100644 include/membuff.h (limited to 'include') diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 789adf2c3f9..18d94592b03 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/membuf.h b/include/membuf.h new file mode 100644 index 00000000000..c7370e1c072 --- /dev/null +++ b/include/membuf.h @@ -0,0 +1,246 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2015 Google, Inc + * Written by Simon Glass + * + * Copyright (c) 1992 Simon Glass + */ + +#ifndef _membuf_H +#define _membuf_H + +/** + * @struct membuff: holds the state of a membuff - it is used for input and + * 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 + * @head and read out from @tail. The membuff is empty when @head == @tail + * and full when adding another character would make @head == @tail. We + * therefore waste one character in the membuff to avoid having an extra flag + * to determine whether (when @head == @tail) the membuff is empty or full. + * + * xxxxxx data + * ...... empty + * + * .............xxxxxxxxxxxxxxxx......................... + * ^ ^ + * tail head + * + * xxxxxxxxxxxxx................xxxxxxxxxxxxxxxxxxxxxxxxx + * ^ ^ + * head tail + */ +struct membuff { + char *start; /** the start of the buffer */ + char *end; /** the end of the buffer (start + length) */ + char *head; /** current buffer head */ + char *tail; /** current buffer tail */ +}; + +/** + * membuf_purge() - reset a membuff to the empty state + * + * Initialise head and tail pointers so that the membuff becomes empty. + * + * @mb: membuff to purge + */ +void membuf_purge(struct membuff *mb); + +/** + * membuf_putraw() - find out where bytes can be written + * + * Work out where in the membuff some data could be written. Return a pointer + * to the address and the number of bytes which can be written there. If + * @update is true, the caller must then write the data immediately, since + * the membuff is updated as if the write has been done, + * + * Note that because the spare space in a membuff may not be contiguous, this + * function may not return @maxlen even if there is enough space in the + * membuff. However, by calling this function twice (with @update == true), + * you will get access to all the spare space. + * + * @mb: membuff to adjust + * @maxlen: the number of bytes we want to write + * @update: true to update the membuff as if the write happened, false to not + * @data: the address data can be written to + * Return: number of bytes which can be written + */ +int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data); + +/** + * membuf_getraw() - find and return a pointer to available bytes + * + * Returns a pointer to any valid input data in the given membuff and + * optionally marks it as read. Note that not all input data may not be + * returned, since data is not necessarily contiguous in the membuff. However, + * if you call this function twice (with @update == true) you are guaranteed + * to get all available data, in at most two installments. + * + * @mb: membuff to adjust + * @maxlen: maximum number of bytes to get + * @update: true to update the membuff as if the bytes have been read (use + * false to check bytes without reading them) + * @data: returns address of data in input membuff + * Return: the number of bytes available at *@data + */ +int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data); + +/** + * membuf_putbyte() - Writes a byte to a membuff + * + * @mb: membuff to adjust + * @ch: byte to write + * Return: true on success, false if membuff is full + */ +bool membuf_putbyte(struct membuff *mb, int ch); + +/** + * @mb: membuff to adjust + * membuf_getbyte() - Read a byte from the membuff + * Return: the byte read, or -1 if the membuff is empty + */ +int membuf_getbyte(struct membuff *mb); + +/** + * membuf_peekbyte() - check the next available byte + * + * Return the next byte which membuf_getbyte() would return, without + * removing it from the membuff. + * + * @mb: membuff to adjust + * Return: the byte peeked, or -1 if the membuff is empty + */ +int membuf_peekbyte(struct membuff *mb); + +/** + * membuf_get() - get data from a membuff + * + * Copies any available data (up to @maxlen bytes) to @buff and removes it + * from the membuff. + * + * @mb: membuff to adjust + * @Buff: address of membuff to transfer bytes to + * @maxlen: maximum number of bytes to read + * Return: the number of bytes read + */ +int membuf_get(struct membuff *mb, char *buff, int maxlen); + +/** + * membuf_put() - write data to a membuff + * + * Writes some data to a membuff. Returns the number of bytes added. If this + * is less than @lnehgt, then the membuff got full + * + * @mb: membuff to adjust + * @data: the data to write + * @length: number of bytes to write from 'data' + * Return: the number of bytes added + */ +int membuf_put(struct membuff *mb, const char *buff, int length); + +/** + * membuf_isempty() - check if a membuff is empty + * + * @mb: membuff to check + * Return: true if empty, else false + */ +bool membuf_isempty(struct membuff *mb); + +/** + * membuf_avail() - check available data in a membuff + * + * @mb: membuff to check + * Return: number of bytes of data available + */ +int membuf_avail(struct membuff *mb); + +/** + * membuf_size() - get the size of a membuff + * + * Note that a membuff can only old data up to one byte less than its size. + * + * @mb: membuff to check + * Return: total size + */ +int membuf_size(struct membuff *mb); + +/** + * membuf_makecontig() - adjust all membuff data to be contiguous + * + * This places all data in a membuff into a single contiguous lump, if + * possible + * + * @mb: membuff to adjust + * Return: true on success + */ +bool membuf_makecontig(struct membuff *mb); + +/** + * membuf_free() - find the number of bytes that can be written to a membuff + * + * @mb: membuff to check + * Return: returns the number of bytes free in a membuff + */ +int membuf_free(struct membuff *mb); + +/** + * membuf_readline() - read a line of text from a membuff + * + * Reads a line of text of up to 'maxlen' characters from a membuff and puts + * it in @str. Any character less than @minch is assumed to be the end of + * line character + * + * @mb: membuff to adjust + * @str: Place to put the line + * @maxlen: Maximum line length (excluding terminator) + * @must_fit: If true then str is empty if line doesn't fit + * 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 + */ +int membuf_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit); + +/** + * membuf_extend_by() - expand a membuff + * + * Extends a membuff by the given number of bytes + * + * @mb: membuff to adjust + * @by: Number of bytes to increase the size by + * @max: Maximum size to allow + * Return: 0 if the expand succeeded, -ENOMEM if not enough memory, -E2BIG + * if the the size would exceed @max + */ +int membuf_extend_by(struct membuff *mb, int by, int max); + +/** + * membuf_init() - set up a new membuff using an existing membuff + * + * @mb: membuff to set up + * @buff: Address of buffer + * @size: Size of buffer + */ +void membuf_init(struct membuff *mb, char *buff, int size); + +/** + * membuf_uninit() - clear a membuff so it can no longer be used + * + * @mb: membuff to uninit + */ +void membuf_uninit(struct membuff *mb); + +/** + * membuf_new() - create a new membuff + * + * @mb: membuff to init + * @size: size of membuff to create + * Return: 0 if OK, -ENOMEM if out of memory + */ +int membuf_new(struct membuff *mb, int size); + +/** + * membuf_dispose() - free memory allocated to a membuff and uninit it + * + * @mb: membuff to dispose + */ +void membuf_dispose(struct membuff *mb); + +#endif diff --git a/include/membuff.h b/include/membuff.h deleted file mode 100644 index c7370e1c072..00000000000 --- a/include/membuff.h +++ /dev/null @@ -1,246 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2015 Google, Inc - * Written by Simon Glass - * - * Copyright (c) 1992 Simon Glass - */ - -#ifndef _membuf_H -#define _membuf_H - -/** - * @struct membuff: holds the state of a membuff - it is used for input and - * 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 - * @head and read out from @tail. The membuff is empty when @head == @tail - * and full when adding another character would make @head == @tail. We - * therefore waste one character in the membuff to avoid having an extra flag - * to determine whether (when @head == @tail) the membuff is empty or full. - * - * xxxxxx data - * ...... empty - * - * .............xxxxxxxxxxxxxxxx......................... - * ^ ^ - * tail head - * - * xxxxxxxxxxxxx................xxxxxxxxxxxxxxxxxxxxxxxxx - * ^ ^ - * head tail - */ -struct membuff { - char *start; /** the start of the buffer */ - char *end; /** the end of the buffer (start + length) */ - char *head; /** current buffer head */ - char *tail; /** current buffer tail */ -}; - -/** - * membuf_purge() - reset a membuff to the empty state - * - * Initialise head and tail pointers so that the membuff becomes empty. - * - * @mb: membuff to purge - */ -void membuf_purge(struct membuff *mb); - -/** - * membuf_putraw() - find out where bytes can be written - * - * Work out where in the membuff some data could be written. Return a pointer - * to the address and the number of bytes which can be written there. If - * @update is true, the caller must then write the data immediately, since - * the membuff is updated as if the write has been done, - * - * Note that because the spare space in a membuff may not be contiguous, this - * function may not return @maxlen even if there is enough space in the - * membuff. However, by calling this function twice (with @update == true), - * you will get access to all the spare space. - * - * @mb: membuff to adjust - * @maxlen: the number of bytes we want to write - * @update: true to update the membuff as if the write happened, false to not - * @data: the address data can be written to - * Return: number of bytes which can be written - */ -int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data); - -/** - * membuf_getraw() - find and return a pointer to available bytes - * - * Returns a pointer to any valid input data in the given membuff and - * optionally marks it as read. Note that not all input data may not be - * returned, since data is not necessarily contiguous in the membuff. However, - * if you call this function twice (with @update == true) you are guaranteed - * to get all available data, in at most two installments. - * - * @mb: membuff to adjust - * @maxlen: maximum number of bytes to get - * @update: true to update the membuff as if the bytes have been read (use - * false to check bytes without reading them) - * @data: returns address of data in input membuff - * Return: the number of bytes available at *@data - */ -int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data); - -/** - * membuf_putbyte() - Writes a byte to a membuff - * - * @mb: membuff to adjust - * @ch: byte to write - * Return: true on success, false if membuff is full - */ -bool membuf_putbyte(struct membuff *mb, int ch); - -/** - * @mb: membuff to adjust - * membuf_getbyte() - Read a byte from the membuff - * Return: the byte read, or -1 if the membuff is empty - */ -int membuf_getbyte(struct membuff *mb); - -/** - * membuf_peekbyte() - check the next available byte - * - * Return the next byte which membuf_getbyte() would return, without - * removing it from the membuff. - * - * @mb: membuff to adjust - * Return: the byte peeked, or -1 if the membuff is empty - */ -int membuf_peekbyte(struct membuff *mb); - -/** - * membuf_get() - get data from a membuff - * - * Copies any available data (up to @maxlen bytes) to @buff and removes it - * from the membuff. - * - * @mb: membuff to adjust - * @Buff: address of membuff to transfer bytes to - * @maxlen: maximum number of bytes to read - * Return: the number of bytes read - */ -int membuf_get(struct membuff *mb, char *buff, int maxlen); - -/** - * membuf_put() - write data to a membuff - * - * Writes some data to a membuff. Returns the number of bytes added. If this - * is less than @lnehgt, then the membuff got full - * - * @mb: membuff to adjust - * @data: the data to write - * @length: number of bytes to write from 'data' - * Return: the number of bytes added - */ -int membuf_put(struct membuff *mb, const char *buff, int length); - -/** - * membuf_isempty() - check if a membuff is empty - * - * @mb: membuff to check - * Return: true if empty, else false - */ -bool membuf_isempty(struct membuff *mb); - -/** - * membuf_avail() - check available data in a membuff - * - * @mb: membuff to check - * Return: number of bytes of data available - */ -int membuf_avail(struct membuff *mb); - -/** - * membuf_size() - get the size of a membuff - * - * Note that a membuff can only old data up to one byte less than its size. - * - * @mb: membuff to check - * Return: total size - */ -int membuf_size(struct membuff *mb); - -/** - * membuf_makecontig() - adjust all membuff data to be contiguous - * - * This places all data in a membuff into a single contiguous lump, if - * possible - * - * @mb: membuff to adjust - * Return: true on success - */ -bool membuf_makecontig(struct membuff *mb); - -/** - * membuf_free() - find the number of bytes that can be written to a membuff - * - * @mb: membuff to check - * Return: returns the number of bytes free in a membuff - */ -int membuf_free(struct membuff *mb); - -/** - * membuf_readline() - read a line of text from a membuff - * - * Reads a line of text of up to 'maxlen' characters from a membuff and puts - * it in @str. Any character less than @minch is assumed to be the end of - * line character - * - * @mb: membuff to adjust - * @str: Place to put the line - * @maxlen: Maximum line length (excluding terminator) - * @must_fit: If true then str is empty if line doesn't fit - * 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 - */ -int membuf_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit); - -/** - * membuf_extend_by() - expand a membuff - * - * Extends a membuff by the given number of bytes - * - * @mb: membuff to adjust - * @by: Number of bytes to increase the size by - * @max: Maximum size to allow - * Return: 0 if the expand succeeded, -ENOMEM if not enough memory, -E2BIG - * if the the size would exceed @max - */ -int membuf_extend_by(struct membuff *mb, int by, int max); - -/** - * membuf_init() - set up a new membuff using an existing membuff - * - * @mb: membuff to set up - * @buff: Address of buffer - * @size: Size of buffer - */ -void membuf_init(struct membuff *mb, char *buff, int size); - -/** - * membuf_uninit() - clear a membuff so it can no longer be used - * - * @mb: membuff to uninit - */ -void membuf_uninit(struct membuff *mb); - -/** - * membuf_new() - create a new membuff - * - * @mb: membuff to init - * @size: size of membuff to create - * Return: 0 if OK, -ENOMEM if out of memory - */ -int membuf_new(struct membuff *mb, int size); - -/** - * membuf_dispose() - free memory allocated to a membuff and uninit it - * - * @mb: membuff to dispose - */ -void membuf_dispose(struct membuff *mb); - -#endif -- cgit v1.2.3 From 68b0af2127dbd7b304f897f4796c6eb86fd74402 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 18 Mar 2025 16:20:44 +0100 Subject: membuf: Rename struct Rename the struct to match the function prefix and filenames. Signed-off-by: Simon Glass --- include/asm-generic/global_data.h | 4 ++-- include/membuf.h | 42 +++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 23 deletions(-) (limited to 'include') diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 18d94592b03..506ee51cdb0 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -316,14 +316,14 @@ struct global_data { * * 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 * * If console recording is activated, this buffer can be used to * emulate input. */ - struct membuff console_in; + struct membuf console_in; #endif #if CONFIG_IS_ENABLED(VIDEO) /** diff --git a/include/membuf.h b/include/membuf.h index c7370e1c072..17616d5577e 100644 --- a/include/membuf.h +++ b/include/membuf.h @@ -10,7 +10,7 @@ #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). * 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 @@ -29,7 +29,7 @@ * ^ ^ * head tail */ -struct membuff { +struct membuf { char *start; /** the start of the buffer */ char *end; /** the end of the buffer (start + length) */ char *head; /** current buffer head */ @@ -43,7 +43,7 @@ struct membuff { * * @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 @@ -64,7 +64,7 @@ void membuf_purge(struct membuff *mb); * @data: the address data can be written to * 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 @@ -82,7 +82,7 @@ int membuf_putraw(struct membuff *mb, int maxlen, bool update, char **data); * @data: returns address of data in input membuff * 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 @@ -91,14 +91,14 @@ int membuf_getraw(struct membuff *mb, int maxlen, bool update, char **data); * @ch: byte to write * 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 * membuf_getbyte() - Read a byte from the membuff * 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 @@ -109,7 +109,7 @@ int membuf_getbyte(struct membuff *mb); * @mb: membuff to adjust * 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 @@ -122,7 +122,7 @@ int membuf_peekbyte(struct membuff *mb); * @maxlen: maximum number of bytes to 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 @@ -135,7 +135,7 @@ int membuf_get(struct membuff *mb, char *buff, int maxlen); * @length: number of bytes to write from 'data' * 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 @@ -143,7 +143,7 @@ int membuf_put(struct membuff *mb, const char *buff, int length); * @mb: membuff to check * 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 @@ -151,7 +151,7 @@ bool membuf_isempty(struct membuff *mb); * @mb: membuff to check * 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 @@ -161,7 +161,7 @@ int membuf_avail(struct membuff *mb); * @mb: membuff to check * Return: total size */ -int membuf_size(struct membuff *mb); +int membuf_size(struct membuf *mb); /** * membuf_makecontig() - adjust all membuff data to be contiguous @@ -172,7 +172,7 @@ int membuf_size(struct membuff *mb); * @mb: membuff to adjust * 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 @@ -180,7 +180,7 @@ bool membuf_makecontig(struct membuff *mb); * @mb: membuff to check * 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 @@ -196,7 +196,7 @@ int membuf_free(struct membuff *mb); * 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 */ -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 @@ -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 * 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 @@ -218,14 +218,14 @@ int membuf_extend_by(struct membuff *mb, int by, int max); * @buff: Address 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 * * @mb: membuff to uninit */ -void membuf_uninit(struct membuff *mb); +void membuf_uninit(struct membuf *mb); /** * membuf_new() - create a new membuff @@ -234,13 +234,13 @@ void membuf_uninit(struct membuff *mb); * @size: size of membuff to create * 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 * * @mb: membuff to dispose */ -void membuf_dispose(struct membuff *mb); +void membuf_dispose(struct membuf *mb); #endif -- cgit v1.2.3 From f48f1705c357605f05f5a47b84c1c89dc33bec35 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 18 Mar 2025 16:20:45 +0100 Subject: membuf: Include stdbool This uses a bool type so include the required header. Signed-off-by: Simon Glass --- include/membuf.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/membuf.h b/include/membuf.h index 17616d5577e..636ed703ee7 100644 --- a/include/membuf.h +++ b/include/membuf.h @@ -9,6 +9,8 @@ #ifndef _membuf_H #define _membuf_H +#include + /** * @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). -- cgit v1.2.3 From da8694a7d2cc9fdfd67e8a039ba1e70bdd543d0b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 18 Mar 2025 16:20:48 +0100 Subject: membuf: Minor code-style improvements Show the start in end in the comment. Comment a missing variable in membuf_readline() and fix its line length. Signed-off-by: Simon Glass --- include/membuf.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/membuf.h b/include/membuf.h index 636ed703ee7..46764690f53 100644 --- a/include/membuf.h +++ b/include/membuf.h @@ -25,7 +25,7 @@ * * .............xxxxxxxxxxxxxxxx......................... * ^ ^ - * tail head + * ^start tail head ^end * * xxxxxxxxxxxxx................xxxxxxxxxxxxxxxxxxxxxxxxx * ^ ^ @@ -194,11 +194,13 @@ int membuf_free(struct membuf *mb); * @mb: membuff to adjust * @str: Place to put the line * @maxlen: Maximum line length (excluding terminator) + * @minch: Minimum ASCII character to permit as part of the line (e.g. ' ') * @must_fit: If true then str is empty if line doesn't fit * 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 */ -int membuf_readline(struct membuf *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 -- cgit v1.2.3