mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-26 03:09:12 +00:00
Add xfer_[v]printf() functions.
This commit is contained in:
parent
656485c1f1
commit
a6a18ae9af
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <gpxe/xfer.h>
|
||||
|
||||
@ -221,6 +222,46 @@ int xfer_deliver_raw ( struct xfer_interface *xfer,
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver formatted string
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v format Format string
|
||||
* @v args Arguments corresponding to the format string
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int xfer_vprintf ( struct xfer_interface *xfer, const char *format,
|
||||
va_list args ) {
|
||||
size_t len;
|
||||
va_list args_tmp;
|
||||
|
||||
va_copy ( args_tmp, args );
|
||||
len = vsnprintf ( NULL, 0, format, args );
|
||||
{
|
||||
char buf[len + 1];
|
||||
vsnprintf ( buf, sizeof ( buf ), format, args_tmp );
|
||||
return xfer_deliver_raw ( xfer, buf, len );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver formatted string
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v format Format string
|
||||
* @v ... Arguments corresponding to the format string
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int xfer_printf ( struct xfer_interface *xfer, const char *format, ... ) {
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start ( args, format );
|
||||
rc = xfer_vprintf ( xfer, format, args );
|
||||
va_end ( args );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Helper methods
|
||||
|
@ -143,6 +143,10 @@ extern int xfer_deliver_iob ( struct xfer_interface *xfer,
|
||||
struct io_buffer *iobuf );
|
||||
extern int xfer_deliver_raw ( struct xfer_interface *xfer,
|
||||
const void *data, size_t len );
|
||||
extern int xfer_vprintf ( struct xfer_interface *xfer,
|
||||
const char *format, va_list args );
|
||||
extern int xfer_printf ( struct xfer_interface *xfer,
|
||||
const char *format, ... );
|
||||
|
||||
extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
|
||||
extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,
|
||||
|
Loading…
Reference in New Issue
Block a user