mirror of https://github.com/ipxe/ipxe.git
Allow buffers to be pre-expanded on demand.
parent
6c72bf13a1
commit
c8b3e969a0
|
@ -167,11 +167,7 @@ int fill_buffer ( struct buffer *buffer, const void *data,
|
||||||
|
|
||||||
/* Check that block fits within buffer, expand if necessary */
|
/* Check that block fits within buffer, expand if necessary */
|
||||||
if ( data_end > buffer->len ) {
|
if ( data_end > buffer->len ) {
|
||||||
if ( ! buffer->expand ) {
|
if ( ( rc = expand_buffer ( buffer, data_end ) ) != 0 ) {
|
||||||
DBGC ( buffer, "BUFFER %p not expandable\n", buffer );
|
|
||||||
return -ENOBUFS;
|
|
||||||
}
|
|
||||||
if ( ( rc = buffer->expand ( buffer, data_end ) ) != 0 ) {
|
|
||||||
DBGC ( buffer, "BUFFER %p could not expand :%s\n",
|
DBGC ( buffer, "BUFFER %p could not expand :%s\n",
|
||||||
buffer, strerror ( rc ) );
|
buffer, strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _GPXE_BUFFER_H
|
#define _GPXE_BUFFER_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <gpxe/uaccess.h>
|
#include <gpxe/uaccess.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
|
@ -101,4 +102,24 @@ struct buffer {
|
||||||
extern int fill_buffer ( struct buffer *buffer, const void *data,
|
extern int fill_buffer ( struct buffer *buffer, const void *data,
|
||||||
size_t offset, size_t len );
|
size_t offset, size_t len );
|
||||||
|
|
||||||
|
/** Expand data buffer
|
||||||
|
*
|
||||||
|
* @v buffer Data buffer
|
||||||
|
* @v new_len New length
|
||||||
|
* @ret rc Return status code
|
||||||
|
*
|
||||||
|
* Expand the data buffer to accommodate more data. Some buffers may
|
||||||
|
* not support being expanded.
|
||||||
|
*/
|
||||||
|
static inline int expand_buffer ( struct buffer *buffer, size_t new_len ) {
|
||||||
|
|
||||||
|
if ( new_len <= buffer->len )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ( ! buffer->expand )
|
||||||
|
return -ENOBUFS;
|
||||||
|
|
||||||
|
return buffer->expand ( buffer, new_len );
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _GPXE_BUFFER_H */
|
#endif /* _GPXE_BUFFER_H */
|
||||||
|
|
Loading…
Reference in New Issue