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