1/*************************************************************************/ 2/* module: Library for String Functions */ 3/* */ 4/* file: libstr.c */ 5/* target system: ALL */ 6/* target OS: ALL */ 7/* */ 8/* Description: */ 9/* implementation of common string-handling functions */ 10/*************************************************************************/ 11 12/* 13 * Copyright Notice 14 * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication 15 * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc., 16 * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001). 17 * All Rights Reserved. 18 * Implementation of all or part of any Specification may require 19 * licenses under third party intellectual property rights, 20 * including without limitation, patent rights (such a third party 21 * may or may not be a Supporter). The Sponsors of the Specification 22 * are not responsible and shall not be held responsible in any 23 * manner for identifying or failing to identify any or all such 24 * third party intellectual property rights. 25 * 26 * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED 27 * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM, 28 * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA, 29 * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML 30 * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 31 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 32 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 33 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 34 * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO., 35 * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY 36 * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF 37 * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF 38 * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL, 39 * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH 40 * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED 41 * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. 42 * 43 * The above notice and this paragraph must be included on all copies 44 * of this document that are made. 45 * 46 */ 47 48 49/************************************************************************* 50 * Definitions 51 *************************************************************************/ 52 53 54#include <smldef.h> 55#include "libstr.h" 56#include "libmem.h" 57#ifdef __ANSI_C__ 58#include <string.h> 59#endif 60#ifdef __PALM_OS__ 61#include <StringMgr.h> 62#endif 63 64 65 66/************************************************************************* 67 * External Functions for all TOOLKIT Versions 68 *************************************************************************/ 69 70 71/** 72 * FUNCTION: smlLibStrdup 73 * 74 * Duplicates the String "constStringP". 75 * Returns a pointer to the new copy of "constStringP". 76 * 77 * IN: String_t constStringP string, which is duplicated 78 * RETURN: String_t pointer to the new copy, 79 * null, if no copy could be allocated 80 */ 81SML_API String_t smlLibStrdup (const char *constStringP) 82{ 83 String_t _new_str; 84 85 // allocate memory for new copy 86 _new_str = (String_t)smlLibMalloc(smlLibStrlen(constStringP) + 1); 87 88 // Copy the string into the new memory 89 if (_new_str != NULL) 90 smlLibStrcpy(_new_str, constStringP); 91 92 return _new_str; 93} 94 95 96#ifndef __PALM_OS__ 97/* If not Palm OS we use the Standard ANSI C functions */ 98SML_API String_t smlLibStrcpy(const char *pTarget, const char *pSource) { 99 return strcpy((char *)pTarget, (char *)pSource); 100} 101SML_API String_t smlLibStrncpy(const char *pTarget, const char *pSource, int count){ 102 return strncpy((char *)pTarget, (char *)pSource, count); 103} 104SML_API String_t smlLibStrcat(const char *pTarget, const char *pSource){ 105 return strcat((char *)pTarget, (char *)pSource); 106} 107SML_API int smlLibStrcmp(const char *pTarget, const char *pSource){ 108 return strcmp((char *)pTarget, (char *)pSource); 109} 110SML_API int smlLibStrncmp(const char *pTarget, const char *pSource, int count){ 111 return strncmp((char *)pTarget, (char *)pSource, count); 112} 113SML_API String_t smlLibStrchr(const char *pString, char character){ 114 return strchr((char *)pString, character); 115} 116SML_API int smlLibStrlen(const char *pString){ 117 return strlen((char *)pString); 118} 119 120 121#endif 122 123 124 125/************************************************************************* 126 * Additional External Functions for Full Size TOOLKIT ONLY 127 *************************************************************************/ 128 129#ifndef __SML_LITE__ /* these API calls are NOT included in the Toolkit lite version */ 130#ifndef __PALM_OS__ /* we use #define to reduce heap usage */ 131SML_API String_t smlLibStrncat(const char *pTarget, const char *pSource, int count){ 132 return strncat((char *)pTarget, (char *)pSource, count); 133} 134SML_API String_t smlLibStrstr(const char *pString, const char *pSubString){ 135 return strstr((char *)pString, (char *)pSubString); 136} 137#endif 138#endif 139