os/ossrv/genericopenlibs/cstdlib/LCHAR/STRNCPY.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
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
* <<strncpy>>---counted copy string
sl@0
    17
* INDEX
sl@0
    18
* strncpy
sl@0
    19
* ANSI_SYNOPSIS
sl@0
    20
* #include <string.h>
sl@0
    21
* char *strncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>);
sl@0
    22
* TRAD_SYNOPSIS
sl@0
    23
* #include <string.h>
sl@0
    24
* char *strncpy(<[dst]>, <[src]>, <[length]>)
sl@0
    25
* char *<[dst]>;
sl@0
    26
* char *<[src]>;
sl@0
    27
* size_t <[length]>;
sl@0
    28
* <<strncpy>> copies not more than <[length]> characters from the
sl@0
    29
* the string pointed to by <[src]> (including the terminating
sl@0
    30
* null character) to the array pointed to by <[dst]>.  If the
sl@0
    31
* string pointed to by <[src]> is shorter than <[length]>
sl@0
    32
* characters, null characters are appended to the destination
sl@0
    33
* array until a total of <[length]> characters have been
sl@0
    34
* RETURNS
sl@0
    35
* This function returns the initial value of <[dst]>.
sl@0
    36
* PORTABILITY
sl@0
    37
* <<strncpy>> is ANSI C.
sl@0
    38
* <<strncpy>> requires no supporting OS subroutines.
sl@0
    39
* QUICKREF
sl@0
    40
* strncpy ansi pure
sl@0
    41
* 
sl@0
    42
*
sl@0
    43
*/
sl@0
    44
sl@0
    45
sl@0
    46
sl@0
    47
#include <string.h>
sl@0
    48
sl@0
    49
/**
sl@0
    50
Copy characters from one string to another.
sl@0
    51
Copies the first num characters of src to dest.
sl@0
    52
No null-character is implicitly appended to dest after copying process.
sl@0
    53
So dest may not be null-terminated if no null-caracters are copied from src.
sl@0
    54
If num is greater than the length of src, dest is padded with zeros until num.
sl@0
    55
@return dst is returned.
sl@0
    56
@param dst Destination string. Space allocated should be at least 
sl@0
    57
num characters long. 
sl@0
    58
@param src Null-terminated string. 
sl@0
    59
@param n Number of characters to be copied.
sl@0
    60
*/
sl@0
    61
EXPORT_C char *strncpy (char *dst, const char *src, size_t n)
sl@0
    62
	{
sl@0
    63
	char *dscan;
sl@0
    64
	const char *sscan;
sl@0
    65
	size_t count;
sl@0
    66
sl@0
    67
	dscan = dst;
sl@0
    68
	sscan = src;
sl@0
    69
   	count = n;
sl@0
    70
   	while (count > 0)
sl@0
    71
    	{
sl@0
    72
       	--count;
sl@0
    73
       	if ((*dscan++ = *sscan++) == '\0')
sl@0
    74
 		break;
sl@0
    75
     	}
sl@0
    76
   	while (count-- > 0)
sl@0
    77
    	*dscan++ = '\0';
sl@0
    78
 
sl@0
    79
   	return dst;
sl@0
    80
	}