X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..374ca955a76ecab1204ca8bfa63ff9238d998416:/icuSources/common/udatamem.c?ds=sidebyside diff --git a/icuSources/common/udatamem.c b/icuSources/common/udatamem.c index 6b39980c..b0778a63 100644 --- a/icuSources/common/udatamem.c +++ b/icuSources/common/udatamem.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 1999-2003, International Business Machines +* Copyright (C) 1999-2004, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************/ @@ -25,6 +25,7 @@ void UDataMemory_init(UDataMemory *This) { uprv_memset(This, 0, sizeof(UDataMemory)); + This->length=-1; } @@ -100,12 +101,58 @@ udata_close(UDataMemory *pData) { U_CAPI const void * U_EXPORT2 udata_getMemory(UDataMemory *pData) { if(pData!=NULL && pData->pHeader!=NULL) { - return (char *)(pData->pHeader)+pData->pHeader->dataHeader.headerSize; + return (char *)(pData->pHeader)+udata_getHeaderSize(pData->pHeader); } else { return NULL; } } +/** + * Get the length of the data item if possible. + * The length may be up to 15 bytes larger than the actual data. + * + * TODO Consider making this function public. + * It would have to return the actual length in more cases. + * For example, the length of the last item in a .dat package could be + * computed from the size of the whole .dat package minus the offset of the + * last item. + * The size of a file that was directly memory-mapped could be determined + * using some system API. + * + * In order to get perfect values for all data items, we may have to add a + * length field to UDataInfo, but that complicates data generation + * and may be overkill. + * + * @param pData The data item. + * @return the length of the data item, or -1 if not known + * @internal Currently used only in cintltst/udatatst.c + */ +U_CAPI int32_t U_EXPORT2 +udata_getLength(const UDataMemory *pData) { + if(pData!=NULL && pData->pHeader!=NULL && pData->length>=0) { + /* + * subtract the header size, + * return only the size of the actual data starting at udata_getMemory() + */ + return pData->length-udata_getHeaderSize(pData->pHeader); + } else { + return -1; + } +} + +/** + * Get the memory including the data header. + * Used in cintltst/udatatst.c + * @internal + */ +U_CAPI const void * U_EXPORT2 +udata_getRawMemory(const UDataMemory *pData) { + if(pData!=NULL && pData->pHeader!=NULL) { + return pData->pHeader; + } else { + return NULL; + } +} UBool UDataMemory_isLoaded(UDataMemory *This) { return This->pHeader != NULL;