]> granicus.if.org Git - icu/commitdiff
ICU-10038 Add u_fopen variant that accepts UTF16 filename
authorMichael Ow <mow@svn.icu-project.org>
Thu, 1 May 2014 17:45:12 +0000 (17:45 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Thu, 1 May 2014 17:45:12 +0000 (17:45 +0000)
X-SVN-Rev: 35681

icu4c/source/common/unicode/urename.h
icu4c/source/io/ufile.c
icu4c/source/io/unicode/ustdio.h

index 4a79d83647d9d3a80b1d470c5a584530723a4a7c..6dd3b9e7d5c53fac89db5141300c4fc847a66ccd 100644 (file)
 #define u_flushDefaultConverter U_ICU_ENTRY_POINT_RENAME(u_flushDefaultConverter)
 #define u_foldCase U_ICU_ENTRY_POINT_RENAME(u_foldCase)
 #define u_fopen U_ICU_ENTRY_POINT_RENAME(u_fopen)
+#define u_fopen_u U_ICU_ENTRY_POINT_RENAME(u_fopen_u)
 #define u_forDigit U_ICU_ENTRY_POINT_RENAME(u_forDigit)
 #define u_formatMessage U_ICU_ENTRY_POINT_RENAME(u_formatMessage)
 #define u_formatMessageWithError U_ICU_ENTRY_POINT_RENAME(u_formatMessageWithError)
 #define u_vsprintf_u U_ICU_ENTRY_POINT_RENAME(u_vsprintf_u)
 #define u_vsscanf U_ICU_ENTRY_POINT_RENAME(u_vsscanf)
 #define u_vsscanf_u U_ICU_ENTRY_POINT_RENAME(u_vsscanf_u)
+#define u_wfopen U_ICU_ENTRY_POINT_RENAME(u_wfopen)
 #define u_writeIdenticalLevelRun U_ICU_ENTRY_POINT_RENAME(u_writeIdenticalLevelRun)
 #define ubidi_addPropertyStarts U_ICU_ENTRY_POINT_RENAME(ubidi_addPropertyStarts)
 #define ubidi_close U_ICU_ENTRY_POINT_RENAME(ubidi_close)
index 820071f1bcfc7a60d0286b0aa550d7f2ecf934a4..11a235e27fae3e207d3b8e3a00c91f965db1ba34 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
-*   Copyright (C) 1998-2013, International Business Machines
+*   Copyright (C) 1998-2014, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
@@ -31,6 +31,7 @@
 #include "unicode/uloc.h"
 #include "unicode/ures.h"
 #include "unicode/ucnv.h"
+#include "unicode/ustring.h"
 #include "cstring.h"
 #include "cmemory.h"
 
@@ -147,6 +148,35 @@ u_fopen(const char    *filename,
     return result; /* not a file leak */
 }
 
+U_CAPI UFILE* U_EXPORT2
+u_fopen_u(const UChar   *filename,
+        const char    *perm,
+        const char    *locale,
+        const char    *codepage)
+{
+    UFILE     *result;
+    char buffer[256];
+
+    u_austrcpy(buffer, filename);
+
+    result = u_fopen(buffer, perm, locale, codepage);
+#if U_PLATFORM_USES_ONLY_WIN32_API
+    /* Try Windows API _wfopen if the above fails. */
+    if (!result) {
+        FILE *systemFile = _wfopen(filename, (UChar*)perm);
+        if (systemFile) {
+            result = finit_owner(systemFile, locale, codepage, TRUE);
+        }
+        if (!result) {
+            /* Something bad happened.
+               Maybe the converter couldn't be opened. */
+            fclose(systemFile);
+        }
+    }
+#endif
+    return result; /* not a file leak */
+}
+
 U_CAPI UFILE* U_EXPORT2
 u_fstropen(UChar *stringBuf,
            int32_t      capacity,
index 8fed38df7850c6fa04d8579bb4b6182ea1d33280..b98ae6a74cedc5385f0f7d3ce3caaa8805f1281a 100644 (file)
@@ -241,6 +241,29 @@ u_fopen(const char    *filename,
     const char    *locale,
     const char    *codepage);
 
+/**
+ * Open a UFILE with a UChar* filename
+ * A UFILE is a wrapper around a FILE* that is locale and codepage aware.
+ * That is, data written to a UFILE will be formatted using the conventions
+ * specified by that UFILE's Locale; this data will be in the character set
+ * specified by that UFILE's codepage.
+ * @param filename The name of the file to open.
+ * @param perm The read/write permission for the UFILE; one of "r", "w", "rw"
+ * @param locale The locale whose conventions will be used to format
+ * and parse output. If this parameter is NULL, the default locale will
+ * be used.
+ * @param codepage The codepage in which data will be written to and
+ * read from the file. If this paramter is NULL the system default codepage
+ * will be used.
+ * @return A new UFILE, or NULL if an error occurred.
+ * @draft ICU 54
+ */
+U_DRAFT UFILE* U_EXPORT2
+u_fopen_u(const UChar    *filename,
+    const char    *perm,
+    const char    *locale,
+    const char    *codepage);
+
 /**
  * Open a UFILE on top of an existing FILE* stream. The FILE* stream
  * ownership remains with the caller. To have the UFILE take over