Browse Source

Move [v]ssnprintf() from iscsi.c into vsprintf.c; we need them

elsewhere as well.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
335b99a39d
3 changed files with 44 additions and 26 deletions
  1. 39
    0
      src/core/vsprintf.c
  2. 4
    0
      src/include/gpxe/vsprintf.h
  3. 1
    26
      src/net/tcp/iscsi.c

+ 39
- 0
src/core/vsprintf.c View File

@@ -338,6 +338,45 @@ int snprintf ( char *buf, size_t size, const char *fmt, ... ) {
338 338
 	return i;
339 339
 }
340 340
 
341
+/**
342
+ * Version of vsnprintf() that accepts a signed buffer size
343
+ *
344
+ * @v buf		Buffer into which to write the string
345
+ * @v size		Size of buffer
346
+ * @v fmt		Format string
347
+ * @v args		Arguments corresponding to the format string
348
+ * @ret len		Length of formatted string
349
+ */
350
+int vssnprintf ( char *buf, ssize_t ssize, const char *fmt, va_list args ) {
351
+
352
+	/* Treat negative buffer size as zero buffer size */
353
+	if ( ssize < 0 )
354
+		ssize = 0;
355
+
356
+	/* Hand off to vsnprintf */
357
+	return vsnprintf ( buf, ssize, fmt, args );
358
+}
359
+
360
+/**
361
+ * Version of vsnprintf() that accepts a signed buffer size
362
+ *
363
+ * @v buf		Buffer into which to write the string
364
+ * @v size		Size of buffer
365
+ * @v fmt		Format string
366
+ * @v ...		Arguments corresponding to the format string
367
+ * @ret len		Length of formatted string
368
+ */
369
+int ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... ) {
370
+	va_list args;
371
+	int len;
372
+
373
+	/* Hand off to vssnprintf */
374
+	va_start ( args, fmt );
375
+	len = vssnprintf ( buf, ssize, fmt, args );
376
+	va_end ( args );
377
+	return len;
378
+}
379
+
341 380
 /**
342 381
  * Write character to console
343 382
  *

+ 4
- 0
src/include/gpxe/vsprintf.h View File

@@ -64,4 +64,8 @@ struct printf_context {
64 64
 
65 65
 extern size_t vcprintf ( struct printf_context *ctx, const char *fmt,
66 66
 			 va_list args );
67
+extern int vssnprintf ( char *buf, ssize_t ssize, const char *fmt,
68
+			va_list args );
69
+extern int ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... );
70
+
67 71
 #endif /* _GPXE_VSPRINTF_H */

+ 1
- 26
src/net/tcp/iscsi.c View File

@@ -23,6 +23,7 @@
23 23
 #include <errno.h>
24 24
 #include <assert.h>
25 25
 #include <byteswap.h>
26
+#include <gpxe/vsprintf.h>
26 27
 #include <gpxe/scsi.h>
27 28
 #include <gpxe/process.h>
28 29
 #include <gpxe/uaccess.h>
@@ -348,32 +349,6 @@ static void iscsi_tx_data_out ( struct iscsi_session *iscsi,
348 349
  *
349 350
  */
350 351
 
351
-/**
352
- * Version of snprintf() that accepts a signed buffer size
353
- *
354
- * @v buf		Buffer into which to write the string
355
- * @v size		Size of buffer
356
- * @v fmt		Format string
357
- * @v args		Arguments corresponding to the format string
358
- * @ret len		Length of formatted string
359
- *
360
- * This is a utility function for iscsi_build_login_request_strings().
361
- */
362
-static int ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... ) {
363
-	va_list args;
364
-	int len;
365
-
366
-	/* Treat negative buffer size as zero buffer size */
367
-	if ( ssize < 0 )
368
-		ssize = 0;
369
-
370
-	/* Hand off to vsnprintf */
371
-	va_start ( args, fmt );
372
-	len = vsnprintf ( buf, ssize, fmt, args );
373
-	va_end ( args );
374
-	return len;
375
-}
376
-
377 352
 /**
378 353
  * Build iSCSI login request strings
379 354
  *

Loading…
Cancel
Save