/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 | 0 | PL_strcpy(char* dest, const char* src) { |
11 | 0 | if (((char*)0 == dest) || ((const char*)0 == src)) { |
12 | 0 | return (char*)0; |
13 | 0 | } |
14 | | |
15 | 0 | return strcpy(dest, src); |
16 | 0 | } |
17 | | |
18 | | PR_IMPLEMENT(char*) |
19 | 0 | PL_strncpy(char* dest, const char* src, PRUint32 max) { |
20 | 0 | char* rv; |
21 | |
|
22 | 0 | if ((char*)0 == dest) { |
23 | 0 | return (char*)0; |
24 | 0 | } |
25 | 0 | if ((const char*)0 == src) { |
26 | 0 | return (char*)0; |
27 | 0 | } |
28 | | |
29 | 0 | for (rv = dest; max && ((*dest = *src) != 0); dest++, src++, max--); |
30 | |
|
31 | | #ifdef JLRU |
32 | | /* XXX I (wtc) think the -- and ++ operators should be postfix. */ |
33 | | while (--max) { |
34 | | *++dest = '\0'; |
35 | | } |
36 | | #endif /* JLRU */ |
37 | |
|
38 | 0 | return rv; |
39 | 0 | } |
40 | | |
41 | | PR_IMPLEMENT(char*) |
42 | 0 | PL_strncpyz(char* dest, const char* src, PRUint32 max) { |
43 | 0 | char* rv; |
44 | |
|
45 | 0 | if ((char*)0 == dest) { |
46 | 0 | return (char*)0; |
47 | 0 | } |
48 | 0 | if ((const char*)0 == src) { |
49 | 0 | return (char*)0; |
50 | 0 | } |
51 | 0 | if (0 == max) { |
52 | 0 | return (char*)0; |
53 | 0 | } |
54 | | |
55 | 0 | for (rv = dest, max--; max && ((*dest = *src) != 0); dest++, src++, max--); |
56 | |
|
57 | 0 | *dest = '\0'; |
58 | |
|
59 | 0 | return rv; |
60 | 0 | } |