cbfstool: add bputs() to store a byte stream to a buffer
There was already a bgets() function which operates on a buffer to copy a byte stream. Provide bputs() to store a byte stream to a buffer, thus making the API symmetrical. Change-Id: I6166f6b68eacb822da38c9da61a3e44f4c67136d Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/5366 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
01650045f4
commit
1240d29209
|
@ -112,6 +112,7 @@ struct xdr {
|
|||
|
||||
/* xdr.c */
|
||||
extern struct xdr xdr_le, xdr_be;
|
||||
int bgets(struct buffer *input, void *output, size_t len);
|
||||
size_t bgets(struct buffer *input, void *output, size_t len);
|
||||
size_t bputs(struct buffer *b, const void *data, size_t len);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
int bgets(struct buffer *input, void *output, size_t len)
|
||||
size_t bgets(struct buffer *input, void *output, size_t len)
|
||||
{
|
||||
len = input->size < len ? input->size : len;
|
||||
memmove(output, input->data, len);
|
||||
|
@ -34,6 +34,13 @@ int bgets(struct buffer *input, void *output, size_t len)
|
|||
return len;
|
||||
}
|
||||
|
||||
size_t bputs(struct buffer *b, const void *data, size_t len)
|
||||
{
|
||||
memmove(&b->data[b->size], data, len);
|
||||
b->size += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
/* The assumption in all this code is that we're given a pointer to enough data.
|
||||
* Hence, we do not check for underflow.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue