X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d7e50217d7adf6e52786a38bcaa4cd698cb9a79e..cf7d32b81c573a0536dc4da4157f9c26f8d0bed3:/bsd/hfs/hfscommon/Unicode/UnicodeWrappers.c diff --git a/bsd/hfs/hfscommon/Unicode/UnicodeWrappers.c b/bsd/hfs/hfscommon/Unicode/UnicodeWrappers.c index efd8b8a4c..4436f0146 100644 --- a/bsd/hfs/hfscommon/Unicode/UnicodeWrappers.c +++ b/bsd/hfs/hfscommon/Unicode/UnicodeWrappers.c @@ -1,16 +1,19 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,7 +23,7 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* File: UnicodeWrappers.c @@ -28,6 +31,8 @@ Contains: Wrapper routines for Unicode conversion and comparison. */ + +#if HFS #include #include @@ -48,40 +53,14 @@ enum { ((c) >= 0x30 && (c) <= 0x39)) -#define IsHexDigit(c) (((c) >= (UInt8) '0' && (c) <= (UInt8) '9') || \ - ((c) >= (UInt8) 'A' && (c) <= (UInt8) 'F')) +#define IsHexDigit(c) (((c) >= (u_int8_t) '0' && (c) <= (u_int8_t) '9') || \ + ((c) >= (u_int8_t) 'A' && (c) <= (u_int8_t) 'F')) static void GetFilenameExtension( ItemCount length, ConstUniCharArrayPtr unicodeStr, char* extStr ); -static void GetFileIDString( HFSCatalogNodeID fileID, char* fileIDStr ); - -static UInt32 HexStringToInteger( UInt32 length, const UInt8 *hexStr ); - - -/* - * Convert file ID into a hexidecimal string with no leading zeros - */ -static void -GetFileIDString( HFSCatalogNodeID fileID, char * fileIDStr ) -{ - SInt32 i, b; - UInt8 *translate = (UInt8 *) "0123456789ABCDEF"; - UInt8 c; - - fileIDStr[0] = '#'; - - for ( i = 0, b = 28; b >= 0; b -= 4 ) { - c = *(translate + ((fileID >> b) & 0x0000000F)); - - /* if its not a leading zero add it to our string */ - if ( (c != (UInt8) '0') || (i > 1) || (b == 0) ) - fileIDStr[++i] = c; - } - - fileIDStr[++i] = '\0'; -} +static u_int32_t HexStringToInteger( u_int32_t length, const u_int8_t *hexStr ); /* @@ -90,10 +69,10 @@ GetFileIDString( HFSCatalogNodeID fileID, char * fileIDStr ) static void GetFilenameExtension(ItemCount length, ConstUniCharArrayPtr unicodeStr, char * extStr) { - UInt32 i; + u_int32_t i; UniChar c; - UInt16 extChars; /* number of extension chars (excluding dot) */ - UInt16 maxExtChars; + u_int16_t extChars; /* number of extension chars (excluding dot) */ + u_int16_t maxExtChars; Boolean foundExtension; extStr[0] = '\0'; /* assume there's no extension */ @@ -128,11 +107,11 @@ GetFilenameExtension(ItemCount length, ConstUniCharArrayPtr unicodeStr, char * e /* if we found one then copy it */ if ( foundExtension ) { - UInt8 *extStrPtr = extStr; + u_int8_t *extStrPtr = (u_int8_t *)extStr; const UniChar *unicodeStrPtr = &unicodeStr[i]; for ( i = 0; i <= extChars; ++i ) - *(extStrPtr++) = (UInt8) *(unicodeStrPtr++); + *(extStrPtr++) = (u_int8_t) *(unicodeStrPtr++); extStr[extChars + 1] = '\0'; /* terminate extension + dot */ } } @@ -142,13 +121,13 @@ GetFilenameExtension(ItemCount length, ConstUniCharArrayPtr unicodeStr, char * e /* * Count filename extension characters (if any) */ -static UInt32 -CountFilenameExtensionChars( const unsigned char * filename, UInt32 length ) +static u_int32_t +CountFilenameExtensionChars( const unsigned char * filename, u_int32_t length ) { - UInt32 i; + u_int32_t i; UniChar c; - UInt32 extChars; /* number of extension chars (excluding dot) */ - UInt16 maxExtChars; + u_int32_t extChars; /* number of extension chars (excluding dot) */ + u_int16_t maxExtChars; Boolean foundExtension; if ( length < 3 ) @@ -167,7 +146,7 @@ CountFilenameExtensionChars( const unsigned char * filename, UInt32 length ) c = filename[i--]; /* look for leading dot */ - if ( c == (UInt8) '.' ) { + if ( c == (u_int8_t) '.' ) { if ( extChars > 0 ) /* cannot end with a dot */ return (extChars); @@ -188,11 +167,11 @@ CountFilenameExtensionChars( const unsigned char * filename, UInt32 length ) * extract the file id from a mangled name */ HFSCatalogNodeID -GetEmbeddedFileID(const unsigned char * filename, UInt32 length, UInt32 *prefixLength) +GetEmbeddedFileID(const unsigned char * filename, u_int32_t length, u_int32_t *prefixLength) { short extChars; short i; - UInt8 c; + u_int8_t c; *prefixLength = 0; @@ -234,13 +213,13 @@ GetEmbeddedFileID(const unsigned char * filename, UInt32 length, UInt32 *prefixL -static UInt32 -HexStringToInteger(UInt32 length, const UInt8 *hexStr) +static u_int32_t +HexStringToInteger(u_int32_t length, const u_int8_t *hexStr) { - UInt32 value; - short i; - UInt8 c; - const UInt8 *p; + u_int32_t value; + u_int32_t i; + u_int8_t c; + const u_int8_t *p; value = 0; p = hexStr; @@ -250,7 +229,7 @@ HexStringToInteger(UInt32 length, const UInt8 *hexStr) if (c >= '0' && c <= '9') { value = value << 4; - value += (UInt32) c - (UInt32) '0'; + value += (u_int32_t) c - (u_int32_t) '0'; } else if (c >= 'A' && c <= 'F') { value = value << 4; value += 10 + ((unsigned int) c - (unsigned int) 'A'); @@ -271,12 +250,12 @@ HexStringToInteger(UInt32 length, const UInt8 *hexStr) * return 0 if equal * */ -SInt32 FastRelString( ConstStr255Param str1, ConstStr255Param str2 ) +int32_t FastRelString( ConstStr255Param str1, ConstStr255Param str2 ) { - UInt16* compareTable; - SInt32 bestGuess; - UInt8 length, length2; - UInt8 delta; + u_int16_t* compareTable; + int32_t bestGuess; + u_int8_t length, length2; + u_int8_t delta; delta = 0; length = *(str1++); @@ -295,18 +274,18 @@ SInt32 FastRelString( ConstStr255Param str1, ConstStr255Param str2 ) length = length2; } - compareTable = (UInt16*) gCompareTable; + compareTable = (u_int16_t*) gCompareTable; while (length--) { - UInt8 aChar, bChar; + u_int8_t aChar, bChar; aChar = *(str1++); bChar = *(str2++); if (aChar != bChar) // If they don't match exacly, do case conversion { - UInt16 aSortWord, bSortWord; + u_int16_t aSortWord, bSortWord; aSortWord = compareTable[aChar]; bSortWord = compareTable[bChar]; @@ -385,14 +364,14 @@ SInt32 FastRelString( ConstStr255Param str1, ConstStr255Param str2 ) // return 1; // -SInt32 FastUnicodeCompare ( register ConstUniCharArrayPtr str1, register ItemCount length1, +int32_t FastUnicodeCompare ( register ConstUniCharArrayPtr str1, register ItemCount length1, register ConstUniCharArrayPtr str2, register ItemCount length2) { - register UInt16 c1,c2; - register UInt16 temp; - register UInt16* lowerCaseTable; + register u_int16_t c1,c2; + register u_int16_t temp; + register u_int16_t* lowerCaseTable; - lowerCaseTable = (UInt16*) gLowerCaseTable; + lowerCaseTable = (u_int16_t*) gLowerCaseTable; while (1) { /* Set default values for c1, c2 in case there are no more valid chars */ @@ -451,7 +430,7 @@ ConvertUnicodeToUTF8Mangled(ByteCount srcLen, ConstUniCharArrayPtr srcStr, ByteC char fileIDStr[15]; char extStr[15]; - GetFileIDString(cnid, fileIDStr); + snprintf(fileIDStr, sizeof(fileIDStr), "#%X", cnid); GetFilenameExtension(srcLen/sizeof(UniChar), srcStr, extStr); /* remove extension chars from source */ @@ -460,10 +439,29 @@ ConvertUnicodeToUTF8Mangled(ByteCount srcLen, ConstUniCharArrayPtr srcStr, ByteC (void) utf8_encodestr(srcStr, srcLen, dstStr, &utf8len, subMaxLen, ':', 0); - strcat(dstStr, fileIDStr); - strcat(dstStr, extStr); + strlcat((char *)dstStr, fileIDStr, maxDstLen); + strlcat((char *)dstStr, extStr, maxDstLen); *actualDstLen = utf8len + (strlen(extStr) + strlen(fileIDStr)); return noErr; } +#else /* not HFS - temp workaround until 4277828 is fixed */ +/* stubs for exported routines that aren't present when we build kernel without HFS */ + +#include + +int32_t FastUnicodeCompare( void * str1, u_int32_t length1, void * str2, u_int32_t length2 ); + + +int32_t FastUnicodeCompare( __unused void * str1, + __unused u_int32_t length1, + __unused void * str2, + __unused u_int32_t length2 ) +{ + return( 0 ); +} + + +#endif /* HFS */ +