Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: nspr/lib/libc/src/strdup.c

Issue 2078763002: Delete bundled copy of NSS and replace with README. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss@master
Patch Set: Delete bundled copy of NSS and replace with README. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « nspr/lib/libc/src/strcpy.c ('k') | nspr/lib/libc/src/strlen.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « nspr/lib/libc/src/strcpy.c ('k') | nspr/lib/libc/src/strlen.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698