os/ossrv/genericopenlibs/cstdlib/LCHAR/STRNCPY.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRNCPY.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,80 @@
     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 +* <<strncpy>>---counted copy string
    1.20 +* INDEX
    1.21 +* strncpy
    1.22 +* ANSI_SYNOPSIS
    1.23 +* #include <string.h>
    1.24 +* char *strncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>);
    1.25 +* TRAD_SYNOPSIS
    1.26 +* #include <string.h>
    1.27 +* char *strncpy(<[dst]>, <[src]>, <[length]>)
    1.28 +* char *<[dst]>;
    1.29 +* char *<[src]>;
    1.30 +* size_t <[length]>;
    1.31 +* <<strncpy>> copies not more than <[length]> characters from the
    1.32 +* the string pointed to by <[src]> (including the terminating
    1.33 +* null character) to the array pointed to by <[dst]>.  If the
    1.34 +* string pointed to by <[src]> is shorter than <[length]>
    1.35 +* characters, null characters are appended to the destination
    1.36 +* array until a total of <[length]> characters have been
    1.37 +* RETURNS
    1.38 +* This function returns the initial value of <[dst]>.
    1.39 +* PORTABILITY
    1.40 +* <<strncpy>> is ANSI C.
    1.41 +* <<strncpy>> requires no supporting OS subroutines.
    1.42 +* QUICKREF
    1.43 +* strncpy ansi pure
    1.44 +* 
    1.45 +*
    1.46 +*/
    1.47 +
    1.48 +
    1.49 +
    1.50 +#include <string.h>
    1.51 +
    1.52 +/**
    1.53 +Copy characters from one string to another.
    1.54 +Copies the first num characters of src to dest.
    1.55 +No null-character is implicitly appended to dest after copying process.
    1.56 +So dest may not be null-terminated if no null-caracters are copied from src.
    1.57 +If num is greater than the length of src, dest is padded with zeros until num.
    1.58 +@return dst is returned.
    1.59 +@param dst Destination string. Space allocated should be at least 
    1.60 +num characters long. 
    1.61 +@param src Null-terminated string. 
    1.62 +@param n Number of characters to be copied.
    1.63 +*/
    1.64 +EXPORT_C char *strncpy (char *dst, const char *src, size_t n)
    1.65 +	{
    1.66 +	char *dscan;
    1.67 +	const char *sscan;
    1.68 +	size_t count;
    1.69 +
    1.70 +	dscan = dst;
    1.71 +	sscan = src;
    1.72 +   	count = n;
    1.73 +   	while (count > 0)
    1.74 +    	{
    1.75 +       	--count;
    1.76 +       	if ((*dscan++ = *sscan++) == '\0')
    1.77 + 		break;
    1.78 +     	}
    1.79 +   	while (count-- > 0)
    1.80 +    	*dscan++ = '\0';
    1.81 + 
    1.82 +   	return dst;
    1.83 +	}