strcpy.c (1278B)
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 if (((char*)0 == dest) || ((const char*)0 == src)) { 12 return (char*)0; 13 } 14 15 return strcpy(dest, src); 16 } 17 18 PR_IMPLEMENT(char*) 19 PL_strncpy(char* dest, const char* src, PRUint32 max) { 20 char* rv; 21 22 if ((char*)0 == dest) { 23 return (char*)0; 24 } 25 if ((const char*)0 == src) { 26 return (char*)0; 27 } 28 29 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 return rv; 39 } 40 41 PR_IMPLEMENT(char*) 42 PL_strncpyz(char* dest, const char* src, PRUint32 max) { 43 char* rv; 44 45 if ((char*)0 == dest) { 46 return (char*)0; 47 } 48 if ((const char*)0 == src) { 49 return (char*)0; 50 } 51 if (0 == max) { 52 return (char*)0; 53 } 54 55 for (rv = dest, max--; max && ((*dest = *src) != 0); dest++, src++, max--); 56 57 *dest = '\0'; 58 59 return rv; 60 }