]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/io/uprintf.c
ICU-511.25.tar.gz
[apple/icu.git] / icuSources / io / uprintf.c
index d95c02c671c3cf3aa778b4fc1b238af717faea4f..4f9ec18148d643204f73fa9643551d3c2417c72f 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
 /*
 ******************************************************************************
 *
-*   Copyright (C) 1998-2004, International Business Machines
+*   Copyright (C) 1998-2012, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
 
 #include "uprintf.h"
 #include "ufile.h"
 
 #include "uprintf.h"
 #include "ufile.h"
+#include "ucln_io.h"
 #include "locbund.h"
 
 #include "cmemory.h"
 
 #include "locbund.h"
 
 #include "cmemory.h"
 
+static UFILE *gStdOut = NULL;
+
+static UBool U_CALLCONV uprintf_cleanup(void)
+{
+    if (gStdOut != NULL) {
+        u_fclose(gStdOut);
+        gStdOut = NULL;
+    }
+    return TRUE;
+}
+
+U_CAPI UFILE * U_EXPORT2
+u_get_stdout()
+{
+    if (gStdOut == NULL) {
+        gStdOut = u_finit(stdout, NULL, NULL);
+        ucln_io_registerCleanup(UCLN_IO_PRINTF, &uprintf_cleanup);
+    }
+    return gStdOut;
+}
+
 static int32_t U_EXPORT2
 u_printf_write(void          *context,
                const UChar   *str,
 static int32_t U_EXPORT2
 u_printf_write(void          *context,
                const UChar   *str,
@@ -92,6 +114,18 @@ u_fprintf(    UFILE        *f,
     return count;
 }
 
     return count;
 }
 
+U_CAPI int32_t U_EXPORT2
+u_printf(const char *patternSpecification,
+         ...)
+{
+    va_list ap;
+    int32_t count;
+    va_start(ap, patternSpecification);
+    count = u_vfprintf(u_get_stdout(), patternSpecification, ap);
+    va_end(ap);
+    return count;
+}
+
 U_CAPI int32_t U_EXPORT2 
 u_fprintf_u(    UFILE        *f,
             const UChar    *patternSpecification,
 U_CAPI int32_t U_EXPORT2 
 u_fprintf_u(    UFILE        *f,
             const UChar    *patternSpecification,
@@ -107,6 +141,18 @@ u_fprintf_u(    UFILE        *f,
     return count;
 }
 
     return count;
 }
 
+U_CAPI int32_t U_EXPORT2
+u_printf_u(const UChar *patternSpecification,
+           ...)
+{
+    va_list ap;
+    int32_t count;
+    va_start(ap, patternSpecification);
+    count = u_vfprintf_u(u_get_stdout(), patternSpecification, ap);
+    va_end(ap);
+    return count;
+}
+
 U_CAPI int32_t  U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
 u_vfprintf(    UFILE        *f,
            const char    *patternSpecification,
 U_CAPI int32_t  U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
 u_vfprintf(    UFILE        *f,
            const char    *patternSpecification,