genericopenlibs/cstdlib/LCHAR/STRCPY.C
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * FUNCTION
       
    16 * <<strcpy>>---copy string
       
    17 * INDEX
       
    18 * strcpy
       
    19 * ANSI_SYNOPSIS
       
    20 * #include <string.h>
       
    21 * char *strcpy(char *<[dst]>, const char *<[src]>);
       
    22 * TRAD_SYNOPSIS
       
    23 * #include <string.h>
       
    24 * char *strcpy(<[dst]>, <[src]>)
       
    25 * char *<[dst]>;
       
    26 * char *<[src]>;
       
    27 * <<strcpy>> copies the string pointed to by <[src]>
       
    28 * (including the terminating null character) to the array
       
    29 * pointed to by <[dst]>.
       
    30 * RETURNS
       
    31 * This function returns the initial value of <[dst]>.
       
    32 * PORTABILITY
       
    33 * <<strcpy>> is ANSI C.
       
    34 * <<strcpy>> requires no supporting OS subroutines.
       
    35 * QUICKREF
       
    36 * strcpy ansi pure
       
    37 * 
       
    38 *
       
    39 */
       
    40 
       
    41 
       
    42 
       
    43 #include <string.h>
       
    44 #include <stdlib.h>
       
    45 
       
    46 /*SUPPRESS 560*/
       
    47 /*SUPPRESS 530*/
       
    48 
       
    49 /**
       
    50 Copy string.
       
    51 Copies the content pointed by src to dest stopping after the terminating null-character is copied.
       
    52 dest should have enough memory space allocated to contain src string.
       
    53 @return des is returned
       
    54 @param s1 Destination string. Should be enough long to contain s2. 
       
    55 @param s2 Null-terminated string to copy.
       
    56 */
       
    57 EXPORT_C char *
       
    58 strcpy (char *s1, const char *s2)
       
    59 	{
       
    60 	char *s = s1;
       
    61    	while ((*s1++ = *s2++)!=0);
       
    62    	return s;
       
    63 	}
       
    64 
       
    65 /**
       
    66 Copy  the  wide-character string  pointed to by  s2 (including the terminating null
       
    67 wide-character code) into the array pointed to  by  s1.
       
    68 @return s1
       
    69 @param s1 wide-character string
       
    70 @param s2 wide-character string
       
    71 */
       
    72 EXPORT_C wchar_t * wcscpy (wchar_t *s1, const wchar_t *s2)
       
    73 {
       
    74   wchar_t *s = s1;
       
    75 
       
    76   while ((*s1++ = *s2++)!=L'\0')
       
    77     ;
       
    78 
       
    79   return s;
       
    80 }
       
    81 
       
    82 /**
       
    83 Function shall return a pointer to a new string,
       
    84 which is a duplicate of the string pointed to by str.
       
    85 @return a pointer to a new string
       
    86 @param str string
       
    87 */
       
    88 EXPORT_C char * strdup (const char *str)
       
    89 {
       
    90   size_t len = strlen (str) + 1;
       
    91   char *copy = (char *)malloc (len);
       
    92   if (copy)
       
    93     {
       
    94       memcpy (copy, str, len);
       
    95     }
       
    96   return copy;
       
    97 }
       
    98 
       
    99 EXPORT_C wchar_t * wcsdup (const wchar_t *str)
       
   100 {
       
   101   size_t len = wcslen(str) + 1;
       
   102   wchar_t *copy;
       
   103   
       
   104   len *= sizeof(wchar_t);
       
   105   copy = (wchar_t *)malloc (len);
       
   106   if (copy)
       
   107     {
       
   108       memcpy (copy, str, len);
       
   109     }
       
   110   return copy;
       
   111 }