1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRCPY.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,111 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* FUNCTION
1.19 +* <<strcpy>>---copy string
1.20 +* INDEX
1.21 +* strcpy
1.22 +* ANSI_SYNOPSIS
1.23 +* #include <string.h>
1.24 +* char *strcpy(char *<[dst]>, const char *<[src]>);
1.25 +* TRAD_SYNOPSIS
1.26 +* #include <string.h>
1.27 +* char *strcpy(<[dst]>, <[src]>)
1.28 +* char *<[dst]>;
1.29 +* char *<[src]>;
1.30 +* <<strcpy>> copies the string pointed to by <[src]>
1.31 +* (including the terminating null character) to the array
1.32 +* pointed to by <[dst]>.
1.33 +* RETURNS
1.34 +* This function returns the initial value of <[dst]>.
1.35 +* PORTABILITY
1.36 +* <<strcpy>> is ANSI C.
1.37 +* <<strcpy>> requires no supporting OS subroutines.
1.38 +* QUICKREF
1.39 +* strcpy ansi pure
1.40 +*
1.41 +*
1.42 +*/
1.43 +
1.44 +
1.45 +
1.46 +#include <string.h>
1.47 +#include <stdlib.h>
1.48 +
1.49 +/*SUPPRESS 560*/
1.50 +/*SUPPRESS 530*/
1.51 +
1.52 +/**
1.53 +Copy string.
1.54 +Copies the content pointed by src to dest stopping after the terminating null-character is copied.
1.55 +dest should have enough memory space allocated to contain src string.
1.56 +@return des is returned
1.57 +@param s1 Destination string. Should be enough long to contain s2.
1.58 +@param s2 Null-terminated string to copy.
1.59 +*/
1.60 +EXPORT_C char *
1.61 +strcpy (char *s1, const char *s2)
1.62 + {
1.63 + char *s = s1;
1.64 + while ((*s1++ = *s2++)!=0);
1.65 + return s;
1.66 + }
1.67 +
1.68 +/**
1.69 +Copy the wide-character string pointed to by s2 (including the terminating null
1.70 +wide-character code) into the array pointed to by s1.
1.71 +@return s1
1.72 +@param s1 wide-character string
1.73 +@param s2 wide-character string
1.74 +*/
1.75 +EXPORT_C wchar_t * wcscpy (wchar_t *s1, const wchar_t *s2)
1.76 +{
1.77 + wchar_t *s = s1;
1.78 +
1.79 + while ((*s1++ = *s2++)!=L'\0')
1.80 + ;
1.81 +
1.82 + return s;
1.83 +}
1.84 +
1.85 +/**
1.86 +Function shall return a pointer to a new string,
1.87 +which is a duplicate of the string pointed to by str.
1.88 +@return a pointer to a new string
1.89 +@param str string
1.90 +*/
1.91 +EXPORT_C char * strdup (const char *str)
1.92 +{
1.93 + size_t len = strlen (str) + 1;
1.94 + char *copy = (char *)malloc (len);
1.95 + if (copy)
1.96 + {
1.97 + memcpy (copy, str, len);
1.98 + }
1.99 + return copy;
1.100 +}
1.101 +
1.102 +EXPORT_C wchar_t * wcsdup (const wchar_t *str)
1.103 +{
1.104 + size_t len = wcslen(str) + 1;
1.105 + wchar_t *copy;
1.106 +
1.107 + len *= sizeof(wchar_t);
1.108 + copy = (wchar_t *)malloc (len);
1.109 + if (copy)
1.110 + {
1.111 + memcpy (copy, str, len);
1.112 + }
1.113 + return copy;
1.114 +}