/src/nspr/lib/libc/src/strcpy.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "plstr.h" |
7 | | #include <string.h> |
8 | | |
9 | | PR_IMPLEMENT(char *) |
10 | | PL_strcpy(char *dest, const char *src) |
11 | 0 | { |
12 | 0 | if( ((char *)0 == dest) || ((const char *)0 == src) ) { |
13 | 0 | return (char *)0; |
14 | 0 | } |
15 | | |
16 | 0 | return strcpy(dest, src); |
17 | 0 | } |
18 | | |
19 | | PR_IMPLEMENT(char *) |
20 | | PL_strncpy(char *dest, const char *src, PRUint32 max) |
21 | 0 | { |
22 | 0 | char *rv; |
23 | |
|
24 | 0 | if( (char *)0 == dest ) { |
25 | 0 | return (char *)0; |
26 | 0 | } |
27 | 0 | if( (const char *)0 == src ) { |
28 | 0 | return (char *)0; |
29 | 0 | } |
30 | | |
31 | 0 | for( rv = dest; max && ((*dest = *src) != 0); dest++, src++, max-- ) |
32 | 0 | ; |
33 | |
|
34 | | #ifdef JLRU |
35 | | /* XXX I (wtc) think the -- and ++ operators should be postfix. */ |
36 | | while( --max ) { |
37 | | *++dest = '\0'; |
38 | | } |
39 | | #endif /* JLRU */ |
40 | |
|
41 | 0 | return rv; |
42 | 0 | } |
43 | | |
44 | | PR_IMPLEMENT(char *) |
45 | | PL_strncpyz(char *dest, const char *src, PRUint32 max) |
46 | 0 | { |
47 | 0 | char *rv; |
48 | |
|
49 | 0 | if( (char *)0 == dest ) { |
50 | 0 | return (char *)0; |
51 | 0 | } |
52 | 0 | if( (const char *)0 == src ) { |
53 | 0 | return (char *)0; |
54 | 0 | } |
55 | 0 | if( 0 == max ) { |
56 | 0 | return (char *)0; |
57 | 0 | } |
58 | | |
59 | 0 | for( rv = dest, max--; max && ((*dest = *src) != 0); dest++, src++, max-- ) |
60 | 0 | ; |
61 | |
|
62 | 0 | *dest = '\0'; |
63 | |
|
64 | 0 | return rv; |
65 | 0 | } |