Browse Source

Add xfer_[v]printf() functions.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
a6a18ae9af
2 changed files with 45 additions and 0 deletions
  1. 41
    0
      src/core/xfer.c
  2. 4
    0
      src/include/gpxe/xfer.h

+ 41
- 0
src/core/xfer.c View File

@@ -17,6 +17,7 @@
17 17
  */
18 18
 
19 19
 #include <string.h>
20
+#include <stdio.h>
20 21
 #include <errno.h>
21 22
 #include <gpxe/xfer.h>
22 23
 
@@ -221,6 +222,46 @@ int xfer_deliver_raw ( struct xfer_interface *xfer,
221 222
 	return rc;
222 223
 }
223 224
 
225
+/**
226
+ * Deliver formatted string
227
+ *
228
+ * @v xfer		Data transfer interface
229
+ * @v format		Format string
230
+ * @v args		Arguments corresponding to the format string
231
+ * @ret rc		Return status code
232
+ */
233
+int xfer_vprintf ( struct xfer_interface *xfer, const char *format,
234
+		   va_list args ) {
235
+	size_t len;
236
+	va_list args_tmp;
237
+
238
+	va_copy ( args_tmp, args );
239
+	len = vsnprintf ( NULL, 0, format, args );
240
+	{
241
+		char buf[len + 1];
242
+		vsnprintf ( buf, sizeof ( buf ), format, args_tmp );
243
+		return xfer_deliver_raw ( xfer, buf, len );
244
+	}
245
+}
246
+
247
+/**
248
+ * Deliver formatted string
249
+ *
250
+ * @v xfer		Data transfer interface
251
+ * @v format		Format string
252
+ * @v ...		Arguments corresponding to the format string
253
+ * @ret rc		Return status code
254
+ */
255
+int xfer_printf ( struct xfer_interface *xfer, const char *format, ... ) {
256
+	va_list args;
257
+	int rc;
258
+
259
+	va_start ( args, format );
260
+	rc = xfer_vprintf ( xfer, format, args );
261
+	va_end ( args );
262
+	return rc;
263
+}
264
+
224 265
 /****************************************************************************
225 266
  *
226 267
  * Helper methods

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

@@ -143,6 +143,10 @@ extern int xfer_deliver_iob ( struct xfer_interface *xfer,
143 143
 			      struct io_buffer *iobuf );
144 144
 extern int xfer_deliver_raw ( struct xfer_interface *xfer,
145 145
 			      const void *data, size_t len );
146
+extern int xfer_vprintf ( struct xfer_interface *xfer,
147
+			  const char *format, va_list args );
148
+extern int xfer_printf ( struct xfer_interface *xfer,
149
+			 const char *format, ... );
146 150
 
147 151
 extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
148 152
 extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,

Loading…
Cancel
Save