diff options
author | Andy Polyakov <appro@openssl.org> | 1999-12-19 16:17:45 +0000 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 1999-12-19 16:17:45 +0000 |
commit | 099f1b32c8a3334699b6884ba23824a49461d01f (patch) | |
tree | 5626fc33981e9902a1b5ae9e23fd890f720a5cc6 /MacOS | |
parent | 9a1e34e5deab94717758384d76a20b39ec9ed030 (diff) |
Initial support for MacOS is now available
Submitted by: Roy Woods <roy@centricsystems.ca>
Reviewed by: Andy Polyakov
Diffstat (limited to 'MacOS')
-rw-r--r-- | MacOS/GetHTTPS.src/CPStringUtils.cpp | 2753 | ||||
-rw-r--r-- | MacOS/GetHTTPS.src/CPStringUtils.hpp | 104 | ||||
-rw-r--r-- | MacOS/GetHTTPS.src/ErrorHandling.cpp | 170 | ||||
-rw-r--r-- | MacOS/GetHTTPS.src/ErrorHandling.hpp | 147 | ||||
-rw-r--r-- | MacOS/GetHTTPS.src/GetHTTPS.cpp | 206 | ||||
-rw-r--r-- | MacOS/GetHTTPS.src/MacSocket.cpp | 1607 | ||||
-rw-r--r-- | MacOS/GetHTTPS.src/MacSocket.h | 103 | ||||
-rw-r--r-- | MacOS/OpenSSL.mcp.hqx | 5103 | ||||
-rw-r--r-- | MacOS/TODO | 18 | ||||
-rw-r--r-- | MacOS/_MWERKS_prefix.h | 5 | ||||
-rw-r--r-- | MacOS/buildinf.h | 5 | ||||
-rw-r--r-- | MacOS/mklinks.as.hqx | 820 | ||||
-rw-r--r-- | MacOS/opensslconf.h | 118 |
13 files changed, 11159 insertions, 0 deletions
diff --git a/MacOS/GetHTTPS.src/CPStringUtils.cpp b/MacOS/GetHTTPS.src/CPStringUtils.cpp new file mode 100644 index 0000000000..5f64afe967 --- /dev/null +++ b/MacOS/GetHTTPS.src/CPStringUtils.cpp @@ -0,0 +1,2753 @@ +/* ==================================================================== + * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + + + #include "CPStringUtils.hpp" +#include "ErrorHandling.hpp" + + + +#define kNumberFormatString "\p########0.00#######;-########0.00#######" + + + +// Useful utility functions which could be optimized a whole lot + + +void CopyPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength) +{ +int i,numPChars; + + + if (thePStr != nil && theCStr != nil && maxCStrLength > 0) + { + numPChars = thePStr[0]; + + for (i = 0;;i++) + { + if (i >= numPChars || i >= maxCStrLength - 1) + { + theCStr[i] = 0; + + break; + } + + else + { + theCStr[i] = thePStr[i + 1]; + } + } + } +} + + +void CopyPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength) +{ +int theMaxDstStrLength; + + + theMaxDstStrLength = maxDstStrLength; + + + if (theDstPStr != nil && theSrcPStr != nil && theMaxDstStrLength > 0) + { + if (theMaxDstStrLength > 255) + { + theMaxDstStrLength = 255; + } + + + if (theMaxDstStrLength - 1 < theSrcPStr[0]) + { + BlockMove(theSrcPStr + 1,theDstPStr + 1,theMaxDstStrLength - 1); + + theDstPStr[0] = theMaxDstStrLength - 1; + } + + else + { + BlockMove(theSrcPStr,theDstPStr,theSrcPStr[0] + 1); + } + } +} + + +void CopyCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxDstStrLength) +{ +int i; + + + if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0) + { + for (i = 0;;i++) + { + if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1) + { + theDstCStr[i] = 0; + + break; + } + + else + { + theDstCStr[i] = theSrcCStr[i]; + } + } + } +} + + + +void CopyCSubstrToCStr(const char *theSrcCStr,const int maxCharsToCopy,char *theDstCStr,const int maxDstStrLength) +{ +int i; + + + if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0) + { + for (i = 0;;i++) + { + if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1 || i >= maxCharsToCopy) + { + theDstCStr[i] = 0; + + break; + } + + else + { + theDstCStr[i] = theSrcCStr[i]; + } + } + } +} + + + +void CopyCSubstrToPStr(const char *theSrcCStr,const int maxCharsToCopy,unsigned char *theDstPStr,const int maxDstStrLength) +{ +int i; +int theMaxDstStrLength; + + + theMaxDstStrLength = maxDstStrLength; + + if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0) + { + if (theMaxDstStrLength > 255) + { + theMaxDstStrLength = 255; + } + + + for (i = 0;;i++) + { + if (theSrcCStr[i] == 0 || i >= theMaxDstStrLength - 1 || i >= maxCharsToCopy) + { + theDstPStr[0] = i; + + break; + } + + else + { + theDstPStr[i + 1] = theSrcCStr[i]; + } + } + } +} + + + +void CopyCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength) +{ +int i; +int theMaxDstStrLength; + + + theMaxDstStrLength = maxDstStrLength; + + if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0) + { + if (theMaxDstStrLength > 255) + { + theMaxDstStrLength = 255; + } + + + for (i = 0;;i++) + { + if (i >= theMaxDstStrLength - 1 || theSrcCStr[i] == 0) + { + theDstPStr[0] = i; + + break; + } + + else + { + theDstPStr[i + 1] = theSrcCStr[i]; + } + } + } +} + + +void ConcatPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength) +{ +int i,numPChars,cStrLength; + + + if (thePStr != nil && theCStr != nil && maxCStrLength > 0) + { + for (cStrLength = 0;theCStr[cStrLength] != 0;cStrLength++) + { + + } + + + numPChars = thePStr[0]; + + + for (i = 0;;i++) + { + if (i >= numPChars || cStrLength >= maxCStrLength - 1) + { + theCStr[cStrLength++] = 0; + + break; + } + + else + { + theCStr[cStrLength++] = thePStr[i + 1]; + } + } + } +} + + + +void ConcatPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength) +{ +int theMaxDstStrLength; + + + theMaxDstStrLength = maxDstStrLength; + + if (theSrcPStr != nil && theDstPStr != nil && theMaxDstStrLength > 0) + { + if (theMaxDstStrLength > 255) + { + theMaxDstStrLength = 255; + } + + + if (theMaxDstStrLength - theDstPStr[0] - 1 < theSrcPStr[0]) + { + BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theMaxDstStrLength - 1 - theDstPStr[0]); + + theDstPStr[0] = theMaxDstStrLength - 1; + } + + else + { + BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theSrcPStr[0]); + + theDstPStr[0] += theSrcPStr[0]; + } + } +} + + + +void ConcatCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength) +{ +int i,thePStrLength; +int theMaxDstStrLength; + + + theMaxDstStrLength = maxDstStrLength; + + if (theSrcCStr != nil && theDstPStr != nil && theMaxDstStrLength > 0) + { + if (theMaxDstStrLength > 255) + { + theMaxDstStrLength = 255; + } + + + thePStrLength = theDstPStr[0]; + + for (i = 0;;i++) + { + if (theSrcCStr[i] == 0 || thePStrLength >= theMaxDstStrLength - 1) + { + theDstPStr[0] = thePStrLength; + + break; + } + + else + { + theDstPStr[thePStrLength + 1] = theSrcCStr[i]; + + thePStrLength++; + } + } + } +} + + + +void ConcatCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxCStrLength) +{ +int cStrLength; + + + if (theSrcCStr != nil && theDstCStr != nil && maxCStrLength > 0) + { + for (cStrLength = 0;theDstCStr[cStrLength] != 0;cStrLength++) + { + + } + + + for (;;) + { + if (*theSrcCStr == 0 || cStrLength >= maxCStrLength - 1) + { + theDstCStr[cStrLength++] = 0; + + break; + } + + else + { + theDstCStr[cStrLength++] = *theSrcCStr++; + } + } + } +} + + + +void ConcatCharToCStr(const char theChar,char *theDstCStr,const int maxCStrLength) +{ +int cStrLength; + + + if (theDstCStr != nil && maxCStrLength > 0) + { + cStrLength = CStrLength(theDstCStr); + + if (cStrLength < maxCStrLength - 1) + { + theDstCStr[cStrLength++] = theChar; + theDstCStr[cStrLength++] = '\0'; + } + } +} + + + +void ConcatCharToPStr(const char theChar,unsigned char *theDstPStr,const int maxPStrLength) +{ +int pStrLength; + + + if (theDstPStr != nil && maxPStrLength > 0) + { + pStrLength = PStrLength(theDstPStr); + + if (pStrLength < maxPStrLength - 1 && pStrLength < 255) + { + theDstPStr[pStrLength + 1] = theChar; + theDstPStr[0] += 1; + } + } +} + + + + +int CompareCStrs(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase) +{ +int returnValue; +char firstChar,secondChar; + + + returnValue = 0; + + + if (theFirstCStr != nil && theSecondCStr != nil) + { + for (;;) + { + firstChar = *theFirstCStr; + secondChar = *theSecondCStr; + + if (ignoreCase == true) + { + if (firstChar >= 'A' && firstChar <= 'Z') + { + firstChar = 'a' + (firstChar - 'A'); + } + + if (secondChar >= 'A' && secondChar <= 'Z') + { + secondChar = 'a' + (secondChar - 'A'); + } + } + + + if (firstChar == 0 && secondChar != 0) + { + returnValue = -1; + + break; + } + + else if (firstChar != 0 && secondChar == 0) + { + returnValue = 1; + + break; + } + + else if (firstChar == 0 && secondChar == 0) + { + returnValue = 0; + + break; + } + + else if (firstChar < secondChar) + { + returnValue = -1; + + break; + } + + else if (firstChar > secondChar) + { + returnValue = 1; + + break; + } + + theFirstCStr++; + theSecondCStr++; + } + } + + + return(returnValue); +} + + + +Boolean CStrsAreEqual(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase) +{ + if (CompareCStrs(theFirstCStr,theSecondCStr,ignoreCase) == 0) + { + return true; + } + + else + { + return false; + } +} + + +Boolean PStrsAreEqual(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase) +{ + if (ComparePStrs(theFirstPStr,theSecondPStr,ignoreCase) == 0) + { + return true; + } + + else + { + return false; + } +} + + + +int ComparePStrs(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase) +{ +int i,returnValue; +char firstChar,secondChar; + + + returnValue = 0; + + + if (theFirstPStr != nil && theSecondPStr != nil) + { + for (i = 1;;i++) + { + firstChar = theFirstPStr[i]; + secondChar = theSecondPStr[i]; + + if (ignoreCase == true) + { + if (firstChar >= 'A' && firstChar <= 'Z') + { + firstChar = 'a' + (firstChar - 'A'); + } + + if (secondChar >= 'A' && secondChar <= 'Z') + { + secondChar = 'a' + (secondChar - 'A'); + } + } + + + if (theFirstPStr[0] < i && theSecondPStr[0] >= i) + { + returnValue = -1; + + break; + } + + else if (theFirstPStr[0] >= i && theSecondPStr[0] < i) + { + returnValue = 1; + + break; + } + + else if (theFirstPStr[0] < i && theSecondPStr[0] < i) + { + returnValue = 0; + + break; + } + + else if (firstChar < secondChar) + { + returnValue = -1; + + break; + } + + else if (firstChar > secondChar) + { + returnValue = 1; + + break; + } + } + } + + + return(returnValue); +} + + + +int CompareCStrToPStr(const char *theCStr,const unsigned char *thePStr,const Boolean ignoreCase) +{ +int returnValue; +char tempString[256]; + + + returnValue = 0; + + if (theCStr != nil && thePStr != nil) + { + CopyPStrToCStr(thePStr,tempString,sizeof(tempString)); + + returnValue = CompareCStrs(theCStr,tempString,ignoreCase); + } + + + return(returnValue); +} + + + +void ConcatLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits) +{ +Str255 theStr255; + + + NumToString(theNum,theStr255); + + + if (numDigits > 0) + { + int charsToInsert; + + + charsToInsert = numDigits - PStrLength(theStr255); + + if (charsToInsert > 0) + { + char tempString[256]; + + CopyCStrToCStr("",tempString,sizeof(tempString)); + + for (;charsToInsert > 0;charsToInsert--) + { + ConcatCStrToCStr("0",tempString,sizeof(tempString)); + } + + ConcatPStrToCStr(theStr255,tempString,sizeof(tempString)); + + CopyCStrToPStr(tempString,theStr255,sizeof(theStr255)); + } + } + + + ConcatPStrToCStr(theStr255,theCStr,maxCStrLength); +} + + + + +void ConcatLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits) +{ +Str255 theStr255; + + + NumToString(theNum,theStr255); + + + if (numDigits > 0) + { + int charsToInsert; + + + charsToInsert = numDigits - PStrLength(theStr255); + + if (charsToInsert > 0) + { + char tempString[256]; + + CopyCStrToCStr("",tempString,sizeof(tempString)); + + for (;charsToInsert > 0;charsToInsert--) + { + ConcatCStrToCStr("0",tempString,sizeof(tempString)); + } + + ConcatPStrToCStr(theStr255,tempString,sizeof(tempString)); + + CopyCStrToPStr(tempString,theStr255,sizeof(theStr255)); + } + } + + + ConcatPStrToPStr(theStr255,thePStr,maxPStrLength); +} + + + +void CopyCStrAndConcatLongIntToCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength) +{ + CopyCStrToCStr(theSrcCStr,theDstCStr,maxDstStrLength); + + ConcatLongIntToCStr(theNum,theDstCStr,maxDstStrLength); +} + + + +void CopyLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits) +{ +Str255 theStr255; + + + NumToString(theNum,theStr255); + + + if (numDigits > 0) + { + int charsToInsert; + + + charsToInsert = numDigits - PStrLength(theStr255); + + if (charsToInsert > 0) + { + char tempString[256]; + + CopyCStrToCStr("",tempString,sizeof(tempString)); + + for (;charsToInsert > 0;charsToInsert--) + { + ConcatCStrToCStr("0",tempString,sizeof(tempString)); + } + + ConcatPStrToCStr(theStr255,tempString,sizeof(tempString)); + + CopyCStrToPStr(tempString,theStr255,sizeof(theStr255)); + } + } + + + CopyPStrToCStr(theStr255,theCStr,maxCStrLength); +} + + + + + +void CopyUnsignedLongIntToCStr(const unsigned long theNum,char *theCStr,const int maxCStrLength) +{ +char tempString[256]; +int srcCharIndex,dstCharIndex; +unsigned long tempNum,quotient,remainder; + + + if (theNum == 0) + { + CopyCStrToCStr("0",theCStr,maxCStrLength); + } + + else + { + srcCharIndex = 0; + + tempNum = theNum; + + for (;;) + { + if (srcCharIndex >= sizeof(tempString) - 1 || tempNum == 0) + { + for (dstCharIndex = 0;;) + { + if (dstCharIndex >= maxCStrLength - 1 || srcCharIndex <= 0) + { + theCStr[dstCharIndex] = 0; + + break; + } + + theCStr[dstCharIndex++] = tempString[--srcCharIndex]; + } + + break; + } + + + quotient = tempNum / 10; + + remainder = tempNum - (quotient * 10); + + tempString[srcCharIndex] = '0' + remainder; + + srcCharIndex++; + + tempNum = quotient; + } + } +} + + + + +void CopyLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits) +{ +char tempString[256]; + + + CopyLongIntToCStr(theNum,tempString,sizeof(tempString),numDigits); + + CopyCStrToPStr(tempString,thePStr,maxPStrLength); +} + + + +OSErr CopyLongIntToNewHandle(const long inTheLongInt,Handle *theHandle) +{ +OSErr errCode = noErr; +char tempString[32]; + + + CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString)); + + errCode = CopyCStrToNewHandle(tempString,theHandle); + + return(errCode); +} + + +OSErr CopyLongIntToExistingHandle(const long inTheLongInt,Handle theHandle) +{ +OSErr errCode = noErr; +char tempString[32]; + + + CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString)); + + errCode = CopyCStrToExistingHandle(tempString,theHandle); + + return(errCode); +} + + + + +OSErr CopyCStrToExistingHandle(const char *theCString,Handle theHandle) +{ +OSErr errCode = noErr; +long stringLength; + + + if (theCString == nil) + { + SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theCString == nil")); + } + + if (theHandle == nil) + { + SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theHandle == nil")); + } + + if (*theHandle == nil) + { + SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, *theHandle == nil")); + } + + + + stringLength = CStrLength(theCString) + 1; + + SetHandleSize(theHandle,stringLength); + + if (GetHandleSize(theHandle) < stringLength) + { + SetErrorMessageAndLongIntAndBail("CopyCStrToExistingHandle: Can't set Handle size, MemError() = ",MemError()); + } + + + ::BlockMove(theCString,*theHandle,stringLength); + + +EXITPOINT: + + return(errCode); +} + + + + + +OSErr CopyCStrToNewHandle(const char *theCString,Handle *theHandle) +{ +OSErr errCode = noErr; +long stringLength; + + + if (theCString == nil) + { + SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theCString == nil")); + } + + if (theHandle == nil) + { + SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theHandle == nil")); + } + + + + stringLength = CStrLength(theCString) + 1; + + *theHandle = NewHandle(stringLength); + + if (*theHandle == nil) + { + SetErrorMessageAndLongIntAndBail("CopyCStrToNewHandle: Can't allocate Handle, MemError() = ",MemError()); + } + + + ::BlockMove(theCString,**theHandle,stringLength); + + +EXITPOINT: + + return(errCode); +} + + + +OSErr CopyPStrToNewHandle(const unsigned char *thePString,Handle *theHandle) +{ +OSErr errCode = noErr; +long stringLength; + + + if (thePString == nil) + { + SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, thePString == nil")); + } + + if (theHandle == nil) + { + SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, theHandle == nil")); + } + + + + stringLength = PStrLength(thePString) + 1; + + *theHandle = NewHandle(stringLength); + + if (*theHandle == nil) + { + SetErrorMessageAndLongIntAndBail("CopyPStrToNewHandle: Can't allocate Handle, MemError() = ",MemError()); + } + + + if (stringLength > 1) + { + BlockMove(thePString + 1,**theHandle,stringLength - 1); + } + + (**theHandle)[stringLength - 1] = 0; + + +EXITPOINT: + + return(errCode); +} + + +OSErr AppendPStrToHandle(const unsigned char *thePString,Handle theHandle,long *currentLength) +{ +OSErr errCode = noErr; +char tempString[256]; + + + CopyPStrToCStr(thePString,tempString,sizeof(tempString)); + + errCode = AppendCStrToHandle(tempString,theHandle,currentLength); + + +EXITPOINT: + + return(errCode); +} + + + +OSErr AppendCStrToHandle(const char *theCString,Handle theHandle,long *currentLength,long *maxLength) +{ +OSErr errCode = noErr; +long handleMaxLength,handleCurrentLength,stringLength,byteCount; + + + if (theCString == nil) + { + SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theCString == nil")); + } + + if (theHandle == nil) + { + SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theHandle == nil")); + } + + + if (maxLength != nil) + { + handleMaxLength = *maxLength; + } + + else + { + handleMaxLength = GetHandleSize(theHandle); + } + + + if (currentLength != nil && *currentLength >= 0) + { + handleCurrentLength = *currentLength; + } + + else + { + handleCurrentLength = CStrLength(*theHandle); + } + + + stringLength = CStrLength(theCString); + + byteCount = handleCurrentLength + stringLength + 1; + + if (byteCount > handleMaxLength) + { + SetHandleSize(theHandle,handleCurrentLength + stringLength + 1); + + if (maxLength != nil) + { + *maxLength = GetHandleSize(theHandle); + + handleMaxLength = *maxLength; + } + + else + { + handleMaxLength = GetHandleSize(theHandle); + } + + if (byteCount > handleMaxLength) + { + SetErrorMessageAndLongIntAndBail("AppendCStrToHandle: Can't increase Handle allocation, MemError() = ",MemError()); + } + } + + + BlockMove(theCString,*theHandle + handleCurrentLength,stringLength + 1); + + + if (currentLength != nil) + { + *currentLength += stringLength; + } + + + errCode = noErr; + + +EXITPOINT: + + return(errCode); +} + + + +OSErr AppendCharsToHandle(const char *theChars,const int numChars,Handle theHandle,long *currentLength,long *maxLength) +{ +OSErr errCode = noErr; +long handleMaxLength,handleCurrentLength,byteCount; + + + if (theChars == nil) + { + SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theChars == nil")); + } + + if (theHandle == nil) + { + SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theHandle == nil")); + } + + + if (maxLength != nil) + { + handleMaxLength = *maxLength; + } + + else + { + handleMaxLength = GetHandleSize(theHandle); + } + + + if (currentLength != nil && *currentLength >= 0) + { + handleCurrentLength = *currentLength; + } + + else + { + handleCurrentLength = CStrLength(*theHandle); + } + + + byteCount = handleCurrentLength + numChars + 1; + + if (byteCount > handleMaxLength) + { + SetHandleSize(theHandle,handleCurrentLength + numChars + 1); + + if (maxLength != nil) + { + *maxLength = GetHandleSize(theHandle); + + handleMaxLength = *maxLength; + } + + else + { + handleMaxLength = GetHandleSize(theHandle); + } + + if (byteCount > handleMaxLength) + { + SetErrorMessageAndLongIntAndBail("AppendCharsToHandle: Can't increase Handle allocation, MemError() = ",MemError()); + } + } + + + BlockMove(theChars,*theHandle + handleCurrentLength,numChars); + + (*theHandle)[handleCurrentLength + numChars] = '\0'; + + if (currentLength != nil) + { + *currentLength += numChars; + } + + + errCode = noErr; + + +EXITPOINT: + + return(errCode); +} + + + +OSErr AppendLongIntToHandle(const long inTheLongInt,Handle theHandle,long *currentLength) +{ +OSErr errCode = noErr; +char tempString[32]; + + + CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString)); + + errCode = AppendCStrToHandle(tempString,theHandle,currentLength); + + return(errCode); +} + + + + +long CStrLength(const char *theCString) +{ +long cStrLength = 0; + + + if (theCString != nil) + { + for (cStrLength = 0;theCString[cStrLength] != 0;cStrLength++) + { + + } + } + + + return(cStrLength); +} + + + +long PStrLength(const unsigned char *thePString) +{ +long pStrLength = 0; + + + if (thePString != nil) + { + pStrLength = thePString[0]; + } + + + return(pStrLength); +} + + + + + +void ZeroMem(void *theMemPtr,const unsigned long numBytes) +{ +unsigned char *theBytePtr; +unsigned long *theLongPtr; +unsigned long numSingleBytes; +unsigned long theNumBytes; + + + theNumBytes = numBytes; + + if (theMemPtr != nil && theNumBytes > 0) + { + theBytePtr = (unsigned char *) theMemPtr; + + numSingleBytes = (unsigned long) theBytePtr & 0x0003; + + while (numSingleBytes > 0) + { + *theBytePtr++ = 0; + + theNumBytes--; + numSingleBytes--; + } + + + theLongPtr = (unsigned long *) theBytePtr; + + while (theNumBytes >= 4) + { + *theLongPtr++ = 0; + + theNumBytes -= 4; + } |