Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "plstr.h" |
michael@0 | 7 | #include <string.h> |
michael@0 | 8 | |
michael@0 | 9 | PR_IMPLEMENT(char *) |
michael@0 | 10 | PL_strcpy(char *dest, const char *src) |
michael@0 | 11 | { |
michael@0 | 12 | if( ((char *)0 == dest) || ((const char *)0 == src) ) return (char *)0; |
michael@0 | 13 | |
michael@0 | 14 | return strcpy(dest, src); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | PR_IMPLEMENT(char *) |
michael@0 | 18 | PL_strncpy(char *dest, const char *src, PRUint32 max) |
michael@0 | 19 | { |
michael@0 | 20 | char *rv; |
michael@0 | 21 | |
michael@0 | 22 | if( (char *)0 == dest ) return (char *)0; |
michael@0 | 23 | if( (const char *)0 == src ) return (char *)0; |
michael@0 | 24 | |
michael@0 | 25 | for( rv = dest; max && ((*dest = *src) != 0); dest++, src++, max-- ) |
michael@0 | 26 | ; |
michael@0 | 27 | |
michael@0 | 28 | #ifdef JLRU |
michael@0 | 29 | /* XXX I (wtc) think the -- and ++ operators should be postfix. */ |
michael@0 | 30 | while( --max ) |
michael@0 | 31 | *++dest = '\0'; |
michael@0 | 32 | #endif /* JLRU */ |
michael@0 | 33 | |
michael@0 | 34 | return rv; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | PR_IMPLEMENT(char *) |
michael@0 | 38 | PL_strncpyz(char *dest, const char *src, PRUint32 max) |
michael@0 | 39 | { |
michael@0 | 40 | char *rv; |
michael@0 | 41 | |
michael@0 | 42 | if( (char *)0 == dest ) return (char *)0; |
michael@0 | 43 | if( (const char *)0 == src ) return (char *)0; |
michael@0 | 44 | if( 0 == max ) return (char *)0; |
michael@0 | 45 | |
michael@0 | 46 | for( rv = dest, max--; max && ((*dest = *src) != 0); dest++, src++, max-- ) |
michael@0 | 47 | ; |
michael@0 | 48 | |
michael@0 | 49 | *dest = '\0'; |
michael@0 | 50 | |
michael@0 | 51 | return rv; |
michael@0 | 52 | } |