| OLD | NEW |
| (Empty) |
| 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 "prmem.h" | |
| 8 #include <string.h> | |
| 9 | |
| 10 PR_IMPLEMENT(char *) | |
| 11 PL_strdup(const char *s) | |
| 12 { | |
| 13 char *rv; | |
| 14 size_t n; | |
| 15 | |
| 16 if( (const char *)0 == s ) | |
| 17 s = ""; | |
| 18 | |
| 19 n = strlen(s) + 1; | |
| 20 | |
| 21 rv = (char *)malloc(n); | |
| 22 if( (char *)0 == rv ) return rv; | |
| 23 | |
| 24 (void)memcpy(rv, s, n); | |
| 25 | |
| 26 return rv; | |
| 27 } | |
| 28 | |
| 29 PR_IMPLEMENT(void) | |
| 30 PL_strfree(char *s) | |
| 31 { | |
| 32 free(s); | |
| 33 } | |
| 34 | |
| 35 PR_IMPLEMENT(char *) | |
| 36 PL_strndup(const char *s, PRUint32 max) | |
| 37 { | |
| 38 char *rv; | |
| 39 size_t l; | |
| 40 | |
| 41 if( (const char *)0 == s ) | |
| 42 s = ""; | |
| 43 | |
| 44 l = PL_strnlen(s, max); | |
| 45 | |
| 46 rv = (char *)malloc(l+1); | |
| 47 if( (char *)0 == rv ) return rv; | |
| 48 | |
| 49 (void)memcpy(rv, s, l); | |
| 50 rv[l] = '\0'; | |
| 51 | |
| 52 return rv; | |
| 53 } | |
| OLD | NEW |