/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
 
/*************************************************************************
 *  Definitions 
 *************************************************************************/


#include <smldef.h>
#include "libstr.h"      
#include "libmem.h"
#ifdef __ANSI_C__
#include <string.h>
#endif
#ifdef __PALM_OS__
#include <StringMgr.h>
#endif



/*************************************************************************
 *  External Functions  for all TOOLKIT Versions
 *************************************************************************/


/**
 * FUNCTION: smlLibStrdup
 *
 * Duplicates the String "constStringP".
 * Returns a pointer to the new copy of "constStringP". 
 *
 * IN:              String_t   constStringP     string, which is duplicated
 * RETURN:          String_t   pointer to the new copy,
 *                             null, if no copy could be allocated
 */
SML_API String_t smlLibStrdup (const char *constStringP)
{
	String_t _new_str;

	/* SCTSTK */
	if (!constStringP) return NULL;

	// allocate memory for new copy
	_new_str = (String_t)smlLibMalloc(smlLibStrlen(constStringP) + 1);
	
	// Copy the string into the new memory
	if (_new_str != NULL)
		smlLibStrcpy(_new_str, constStringP);
	   
	return _new_str;
}


#ifndef __PALM_OS__ 
/* If not Palm OS we use the Standard ANSI C functions */
SML_API String_t smlLibStrcpy(const char *pTarget, const char *pSource) {
	return strcpy((char *)pTarget, (char *)pSource);
}
SML_API String_t smlLibStrncpy(const char *pTarget, const char *pSource, int count){
	return strncpy((char *)pTarget, (char *)pSource, count);
}
SML_API String_t smlLibStrcat(const char *pTarget, const char *pSource){
	return strcat((char *)pTarget, (char *)pSource);
}
SML_API int smlLibStrcmp(const char *pTarget, const char *pSource){
	return strcmp((char *)pTarget, (char *)pSource);
}
SML_API int smlLibStrncmp(const char *pTarget, const char *pSource, int count){
	return strncmp((char *)pTarget, (char *)pSource, count);
}
SML_API String_t smlLibStrchr(const char *pString, char character){
	return strchr((char *)pString, character);
}
SML_API int smlLibStrlen(const char *pString){
	return strlen((char *)pString);
}


#endif



/*************************************************************************
 *  Additional External Functions  for Full Size TOOLKIT ONLY
 *************************************************************************/

#ifndef __SML_LITE__  /* these API calls are NOT included in the Toolkit lite version */
#ifndef __PALM_OS__  /* we use #define to reduce heap usage */
SML_API String_t smlLibStrncat(const char *pTarget, const char *pSource, int count){
	return strncat((char *)pTarget, (char *)pSource, count);
}
SML_API String_t smlLibStrstr(const char *pString, const char *pSubString){
	return strstr((char *)pString, (char *)pSubString);
}
#endif
#endif
