From 67a696766c62f9c6f18878f2b8823755b8034220 Mon Sep 17 00:00:00 2001
From: Tobias Scheuer <tobias.scheuer@sap.com>
Date: Sat, 20 Dec 2014 14:31:34 +0100
Subject: [PATCH] add DanielH's implementation of al_fprintf and al_vfprintf

---
 include/allegro5/file.h |  2 ++
 src/file.c              | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/include/allegro5/file.h b/include/allegro5/file.h
index aef8c12..718e7a4 100644
--- a/include/allegro5/file.h
+++ b/include/allegro5/file.h
@@ -76,6 +76,8 @@ AL_FUNC(size_t, al_fwrite32be, (ALLEGRO_FILE *f, int32_t l));
 AL_FUNC(char*, al_fgets, (ALLEGRO_FILE *f, char * const p, size_t max));
 AL_FUNC(ALLEGRO_USTR *, al_fget_ustr, (ALLEGRO_FILE *f));
 AL_FUNC(int, al_fputs, (ALLEGRO_FILE *f, const char *p));
+AL_FUNC(size_t, al_fprintf, (ALLEGRO_FILE *f, const char *format, ...));
+AL_FUNC(size_t, al_vfprintf, (ALLEGRO_FILE *f, const char* format, va_list args));
 
 /* Specific to stdio backend. */
 AL_FUNC(ALLEGRO_FILE*, al_fopen_fd, (int fd, const char *mode));
diff --git a/src/file.c b/src/file.c
index 6f54bcd..9cecf2d 100644
--- a/src/file.c
+++ b/src/file.c
@@ -538,4 +538,50 @@ void *al_get_file_userdata(ALLEGRO_FILE *f)
 }
 
 
+/* Function: al_vfprintf
+ */
+size_t al_vfprintf(ALLEGRO_FILE *pfile, const char *format, va_list args)
+{
+   size_t rv = 0;
+   ALLEGRO_USTR *ustr = 0;
+   size_t size = 0;
+
+   if (pfile != 0 && format != 0)
+   {
+      ustr = al_ustr_new("");
+      if (ustr)
+      {
+         rv = al_ustr_vappendf(ustr, format, args);
+         if (rv)
+         {
+            size = al_ustr_size(ustr);
+            if (size > 0)
+            {
+               rv = al_fwrite(pfile, (const void*)(al_cstr(ustr)), size);
+            }
+         }
+         al_ustr_free(ustr);
+      }
+   }
+   return rv;
+}
+
+
+/* Function: al_fprintf
+ */
+size_t al_fprintf(ALLEGRO_FILE *pfile, const char *format, ...)
+{
+   size_t rv = 0;
+   va_list args = 0;
+
+   if (pfile != 0 && format != 0)
+   {
+      va_start(args, format);
+      rv = al_vfprintf(pfile, format, args);
+      va_end(args);
+   }
+   return rv;
+} 
+
+
 /* vim: set sts=3 sw=3 et: */
-- 
1.9.4.msysgit.0

