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