diff options
| author | Michael Brown | 2007-05-31 15:26:50 +0200 |
|---|---|---|
| committer | Michael Brown | 2007-05-31 15:26:50 +0200 |
| commit | 335b99a39d468c7671f584bee362856cf5c2ed99 (patch) | |
| tree | 38df31c684e1023b74a6e86a78199fe3eecead77 /src | |
| parent | Add xfer_[v]printf() functions. (diff) | |
| download | ipxe-335b99a39d468c7671f584bee362856cf5c2ed99.tar.gz ipxe-335b99a39d468c7671f584bee362856cf5c2ed99.tar.xz ipxe-335b99a39d468c7671f584bee362856cf5c2ed99.zip | |
Move [v]ssnprintf() from iscsi.c into vsprintf.c; we need them
elsewhere as well.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/vsprintf.c | 39 | ||||
| -rw-r--r-- | src/include/gpxe/vsprintf.h | 4 | ||||
| -rw-r--r-- | src/net/tcp/iscsi.c | 27 |
3 files changed, 44 insertions, 26 deletions
diff --git a/src/core/vsprintf.c b/src/core/vsprintf.c index e6f072e7b..4457fe4f4 100644 --- a/src/core/vsprintf.c +++ b/src/core/vsprintf.c @@ -339,6 +339,45 @@ int snprintf ( char *buf, size_t size, const char *fmt, ... ) { } /** + * Version of vsnprintf() that accepts a signed buffer size + * + * @v buf Buffer into which to write the string + * @v size Size of buffer + * @v fmt Format string + * @v args Arguments corresponding to the format string + * @ret len Length of formatted string + */ +int vssnprintf ( char *buf, ssize_t ssize, const char *fmt, va_list args ) { + + /* Treat negative buffer size as zero buffer size */ + if ( ssize < 0 ) + ssize = 0; + + /* Hand off to vsnprintf */ + return vsnprintf ( buf, ssize, fmt, args ); +} + +/** + * Version of vsnprintf() that accepts a signed buffer size + * + * @v buf Buffer into which to write the string + * @v size Size of buffer + * @v fmt Format string + * @v ... Arguments corresponding to the format string + * @ret len Length of formatted string + */ +int ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... ) { + va_list args; + int len; + + /* Hand off to vssnprintf */ + va_start ( args, fmt ); + len = vssnprintf ( buf, ssize, fmt, args ); + va_end ( args ); + return len; +} + +/** * Write character to console * * @v ctx Context diff --git a/src/include/gpxe/vsprintf.h b/src/include/gpxe/vsprintf.h index ac87c5a8b..9360f29b7 100644 --- a/src/include/gpxe/vsprintf.h +++ b/src/include/gpxe/vsprintf.h @@ -64,4 +64,8 @@ struct printf_context { extern size_t vcprintf ( struct printf_context *ctx, const char *fmt, va_list args ); +extern int vssnprintf ( char *buf, ssize_t ssize, const char *fmt, + va_list args ); +extern int ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... ); + #endif /* _GPXE_VSPRINTF_H */ diff --git a/src/net/tcp/iscsi.c b/src/net/tcp/iscsi.c index 56567976f..f95286d09 100644 --- a/src/net/tcp/iscsi.c +++ b/src/net/tcp/iscsi.c @@ -23,6 +23,7 @@ #include <errno.h> #include <assert.h> #include <byteswap.h> +#include <gpxe/vsprintf.h> #include <gpxe/scsi.h> #include <gpxe/process.h> #include <gpxe/uaccess.h> @@ -349,32 +350,6 @@ static void iscsi_tx_data_out ( struct iscsi_session *iscsi, */ /** - * Version of snprintf() that accepts a signed buffer size - * - * @v buf Buffer into which to write the string - * @v size Size of buffer - * @v fmt Format string - * @v args Arguments corresponding to the format string - * @ret len Length of formatted string - * - * This is a utility function for iscsi_build_login_request_strings(). - */ -static int ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... ) { - va_list args; - int len; - - /* Treat negative buffer size as zero buffer size */ - if ( ssize < 0 ) - ssize = 0; - - /* Hand off to vsnprintf */ - va_start ( args, fmt ); - len = vsnprintf ( buf, ssize, fmt, args ); - va_end ( args ); - return len; -} - -/** * Build iSCSI login request strings * * @v iscsi iSCSI session |
