os/ossrv/genericopenlibs/cstdlib/LCHAR/STRNCAT.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 * <<strncat>>---concatenate strings
    17 * INDEX
    18 * strncat
    19 * ANSI_SYNOPSIS
    20 * #include <string.h>
    21 * char *strncat(char *<[dst]>, const char *<[src]>, size_t <[length]>);
    22 * TRAD_SYNOPSIS
    23 * #include <string.h>
    24 * char *strncat(<[dst]>, <[src]>, <[length]>)
    25 * char *<[dst]>;
    26 * char *<[src]>;
    27 * size_t <[length]>;
    28 * <<strncat>> appends not more than <[length]> characters from
    29 * the string pointed to by <[src]> (including the	terminating
    30 * null character) to the end of the string pointed to by
    31 * <[dst]>.  The initial character of <[src]> overwrites the null
    32 * character at the end of <[dst]>.  A terminating null character
    33 * is always appended to the result
    34 * WARNINGS
    35 * Note that a null is always appended, so that if the copy is
    36 * limited by the <[length]> argument, the number of characters
    37 * appended to <[dst]> is <<n + 1>>.
    38 * RETURNS
    39 * This function returns the initial value of <[dst]>
    40 * PORTABILITY
    41 * <<strncat>> is ANSI C.
    42 * <<strncat>> requires no supporting OS subroutines.
    43 * QUICKREF
    44 * strncat ansi pure
    45 * 
    46 *
    47 */
    48 
    49 
    50 
    51 #include <string.h>
    52 
    53 /**
    54 Append substring to string.
    55 Appends num characters of src string to dest string. 
    56 If the terminating null-character appears in src string 
    57 before num character have been appended, the function appends 
    58 the null-character to dest and ends.
    59 The terminating null character in dest is overwritten by the first character of src.
    60 The resulting string includes a null-character at end.
    61 @return s1 is returned
    62 @param s1 Pointer to a null-terminated string with enough space allocated to contain src
    63 plus num characters. 
    64 @param s2 Null-terminated string containing characters to be appended. 
    65 @param n Number of characters to be appended from src to dest.
    66 */
    67 EXPORT_C char *
    68 strncat (char *s1, const char *s2, size_t n)
    69 {
    70   char *s = s1;
    71 
    72   while (*s1)
    73     s1++;
    74   while (n-- != 0 && (*s1++ = *s2++)!=0)
    75     {
    76       if (n == 0)
    77 	*s1 = '\0';
    78     }
    79 
    80   return s;
    81 }