michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 1997-2006, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: ures_cnv.c michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2004aug25 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Character conversion functions moved here from uresbund.c michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/putil.h" michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/ucnv.h" michael@0: #include "unicode/ures.h" michael@0: #include "uinvchar.h" michael@0: #include "ustr_cnv.h" michael@0: michael@0: U_CAPI UResourceBundle * U_EXPORT2 michael@0: ures_openU(const UChar *myPath, michael@0: const char *localeID, michael@0: UErrorCode *status) michael@0: { michael@0: char pathBuffer[1024]; michael@0: int32_t length; michael@0: char *path = pathBuffer; michael@0: michael@0: if(status==NULL || U_FAILURE(*status)) { michael@0: return NULL; michael@0: } michael@0: if(myPath==NULL) { michael@0: path = NULL; michael@0: } michael@0: else { michael@0: length=u_strlen(myPath); michael@0: if(length>=sizeof(pathBuffer)) { michael@0: *status=U_ILLEGAL_ARGUMENT_ERROR; michael@0: return NULL; michael@0: } else if(uprv_isInvariantUString(myPath, length)) { michael@0: /* michael@0: * the invariant converter is sufficient for package and tree names michael@0: * and is more efficient michael@0: */ michael@0: u_UCharsToChars(myPath, path, length+1); /* length+1 to include the NUL */ michael@0: } else { michael@0: #if !UCONFIG_NO_CONVERSION michael@0: /* use the default converter to support variant-character paths */ michael@0: UConverter *cnv=u_getDefaultConverter(status); michael@0: length=ucnv_fromUChars(cnv, path, (int32_t)sizeof(pathBuffer), myPath, length, status); michael@0: u_releaseDefaultConverter(cnv); michael@0: if(U_FAILURE(*status)) { michael@0: return NULL; michael@0: } michael@0: if(length>=sizeof(pathBuffer)) { michael@0: /* not NUL-terminated - path too long */ michael@0: *status=U_ILLEGAL_ARGUMENT_ERROR; michael@0: return NULL; michael@0: } michael@0: #else michael@0: /* the default converter is not available */ michael@0: *status=U_UNSUPPORTED_ERROR; michael@0: return NULL; michael@0: #endif michael@0: } michael@0: } michael@0: michael@0: return ures_open(path, localeID, status); michael@0: }