chiark / gitweb /
New functions `dstr_putf' and `dstr_vputf' which do `printf'-style
[mLib] / dstr.h
diff --git a/dstr.h b/dstr.h
index b7240fe62bc9287de733d811a80583534b2c427a..73b1ceb507055d5d32656cc22fa40f3b0f88d855 100644 (file)
--- a/dstr.h
+++ b/dstr.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: dstr.h,v 1.1 1998/06/17 23:44:42 mdw Exp $
+ * $Id: dstr.h,v 1.2 1998/12/15 23:53:23 mdw Exp $
  *
  * Handle dynamically growing strings
  *
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: dstr.h,v $
- * Revision 1.1  1998/06/17 23:44:42  mdw
- * Initial revision
+ * Revision 1.2  1998/12/15 23:53:23  mdw
+ * New functions `dstr_putf' and `dstr_vputf' which do `printf'-style
+ * formatting in a safe way.
+ *
+ * Revision 1.1.1.1  1998/06/17 23:44:42  mdw
+ * Initial version of mLib
  *
  */
 
@@ -53,6 +57,7 @@
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <stdarg.h>
 #include <stdio.h>
 
 /*----- Data structures ---------------------------------------------------*/
@@ -170,6 +175,36 @@ extern void dstr_puts(dstr */*d*/, const char */*s*/);
   (d)->len += sz;                                                      \
 } while (0)
 
+/* --- @dstr_vputf@ --- *
+ *
+ * Arguments:  @dstr *d@ = pointer to a dynamic string block
+ *             @const char *p@ = pointer to @printf@-style format string
+ *             @va_list ap@ = argument handle
+ *
+ * Returns:    ---
+ *
+ * Use:                As for @dstr_putf@, but may be used as a back-end to user-
+ *             supplied functions with @printf@-style interfaces.
+ */
+
+extern int dstr_vputf(dstr */*d*/, const char */*p*/, va_list /*ap*/);
+
+/* --- @dstr_putf@ --- *
+ *
+ * Arguments:  @dstr *d@ = pointer to a dynamic string block
+ *             @const char *p@ = pointer to @printf@-style format string
+ *             @...@ = argument handle
+ *
+ * Returns:    ---
+ *
+ * Use:                Writes a piece of text to a dynamic string, doing @printf@-
+ *             style substitutions as it goes.  Intended to be robust if
+ *             faced with malicious arguments, but not if the format string
+ *             itself is malicious.
+ */
+
+extern int dstr_putf(dstr */*d*/, const char */*p*/, ...);
+
 /* --- @dstr_putd@ --- *
  *
  * Arguments:  @dstr *d@ = pointer to a dynamic string block