Line data Source code
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 5025 : if( (const char *)0 == s )
17 0 : s = "";
18 :
19 5025 : n = strlen(s) + 1;
20 :
21 5025 : rv = (char *)malloc(n);
22 5025 : if( (char *)0 == rv ) return rv;
23 :
24 5025 : (void)memcpy(rv, s, n);
25 :
26 5025 : return rv;
27 : }
28 :
29 : PR_IMPLEMENT(void)
30 : PL_strfree(char *s)
31 : {
32 22 : free(s);
33 22 : }
34 :
35 : PR_IMPLEMENT(char *)
36 : PL_strndup(const char *s, PRUint32 max)
37 : {
38 : char *rv;
39 : size_t l;
40 :
41 0 : if( (const char *)0 == s )
42 0 : s = "";
43 :
44 0 : l = PL_strnlen(s, max);
45 :
46 0 : rv = (char *)malloc(l+1);
47 0 : if( (char *)0 == rv ) return rv;
48 :
49 0 : (void)memcpy(rv, s, l);
50 0 : rv[l] = '\0';
51 :
52 0 : return rv;
53 : }
|