[libc] add fprintf/vfprintf

Change-Id: Ibc0fe656295cb97f8839d6fbae7682a57bc395e1
Signed-off-by: Dima Zavin <dima@android.com>
diff --git a/include/stdio.h b/include/stdio.h
index ce9c548..c44a567 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -67,6 +67,9 @@
 int getc(FILE *fp);
 int getchar(void);
 
+int fprintf(FILE *fp, const char *fmt, ...);
+int vfprintf(FILE *fp, const char *fmt, va_list ap);
+
 __END_CDECLS
 
 #endif
diff --git a/lib/libc/stdio.c b/lib/libc/stdio.c
index 698700b..51b4ec7 100644
--- a/lib/libc/stdio.c
+++ b/lib/libc/stdio.c
@@ -59,14 +59,29 @@
 	return getc(stdin);
 }
 
+int vfprintf(FILE *fp, const char *fmt, va_list ap)
+{
+	return fp->vfprintf(fp->ctx, fmt, ap);
+}
+
+int fprintf(FILE *fp, const char *fmt, ...)
+{
+	va_list ap;
+	int err;
+
+	va_start(ap, fmt);
+	err = vfprintf(fp, fmt, ap);
+	va_end(ap);
+	return err;
+}
+
 int _printf(const char *fmt, ...)
 {
-	int err;
-	FILE *fp = stdout;
-
 	va_list ap;
+	int err;
+
 	va_start(ap, fmt);
-	err = fp->vfprintf(fp->ctx, fmt, ap);
+	err = vfprintf(stdout, fmt, ap);
 	va_end(ap);
 
 	return err;