sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * FUNCTION sl@0: * <>---counted copy string sl@0: * INDEX sl@0: * strncpy sl@0: * ANSI_SYNOPSIS sl@0: * #include sl@0: * char *strncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>); sl@0: * TRAD_SYNOPSIS sl@0: * #include sl@0: * char *strncpy(<[dst]>, <[src]>, <[length]>) sl@0: * char *<[dst]>; sl@0: * char *<[src]>; sl@0: * size_t <[length]>; sl@0: * <> copies not more than <[length]> characters from the sl@0: * the string pointed to by <[src]> (including the terminating sl@0: * null character) to the array pointed to by <[dst]>. If the sl@0: * string pointed to by <[src]> is shorter than <[length]> sl@0: * characters, null characters are appended to the destination sl@0: * array until a total of <[length]> characters have been sl@0: * RETURNS sl@0: * This function returns the initial value of <[dst]>. sl@0: * PORTABILITY sl@0: * <> is ANSI C. sl@0: * <> requires no supporting OS subroutines. sl@0: * QUICKREF sl@0: * strncpy ansi pure sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: sl@0: /** sl@0: Copy characters from one string to another. sl@0: Copies the first num characters of src to dest. sl@0: No null-character is implicitly appended to dest after copying process. sl@0: So dest may not be null-terminated if no null-caracters are copied from src. sl@0: If num is greater than the length of src, dest is padded with zeros until num. sl@0: @return dst is returned. sl@0: @param dst Destination string. Space allocated should be at least sl@0: num characters long. sl@0: @param src Null-terminated string. sl@0: @param n Number of characters to be copied. sl@0: */ sl@0: EXPORT_C char *strncpy (char *dst, const char *src, size_t n) sl@0: { sl@0: char *dscan; sl@0: const char *sscan; sl@0: size_t count; sl@0: sl@0: dscan = dst; sl@0: sscan = src; sl@0: count = n; sl@0: while (count > 0) sl@0: { sl@0: --count; sl@0: if ((*dscan++ = *sscan++) == '\0') sl@0: break; sl@0: } sl@0: while (count-- > 0) sl@0: *dscan++ = '\0'; sl@0: sl@0: return dst; sl@0: }