1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1997-2006, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: ures_cnv.c
12 * tab size: 8 (not used)
15 * created on: 2004aug25
16 * created by: Markus W. Scherer
18 * Character conversion functions moved here from uresbund.c
21 #include "unicode/utypes.h"
22 #include "unicode/putil.h"
23 #include "unicode/ustring.h"
24 #include "unicode/ucnv.h"
25 #include "unicode/ures.h"
29 U_CAPI UResourceBundle * U_EXPORT2
30 ures_openU(const UChar *myPath,
34 char pathBuffer[1024];
36 char *path = pathBuffer;
38 if(status==NULL || U_FAILURE(*status)) {
45 length=u_strlen(myPath);
46 if(length>=sizeof(pathBuffer)) {
47 *status=U_ILLEGAL_ARGUMENT_ERROR;
49 } else if(uprv_isInvariantUString(myPath, length)) {
51 * the invariant converter is sufficient for package and tree names
52 * and is more efficient
54 u_UCharsToChars(myPath, path, length+1); /* length+1 to include the NUL */
56 #if !UCONFIG_NO_CONVERSION
57 /* use the default converter to support variant-character paths */
58 UConverter *cnv=u_getDefaultConverter(status);
59 length=ucnv_fromUChars(cnv, path, (int32_t)sizeof(pathBuffer), myPath, length, status);
60 u_releaseDefaultConverter(cnv);
61 if(U_FAILURE(*status)) {
64 if(length>=sizeof(pathBuffer)) {
65 /* not NUL-terminated - path too long */
66 *status=U_ILLEGAL_ARGUMENT_ERROR;
70 /* the default converter is not available */
71 *status=U_UNSUPPORTED_ERROR;
77 return ures_open(path, localeID, status);