1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/lib/libc/src/strlen.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,42 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "plstr.h" 1.10 +#include "prtypes.h" 1.11 +#include "prlog.h" 1.12 +#include <string.h> 1.13 + 1.14 +PR_IMPLEMENT(PRUint32) 1.15 +PL_strlen(const char *str) 1.16 +{ 1.17 + size_t l; 1.18 + 1.19 + if( (const char *)0 == str ) return 0; 1.20 + 1.21 + l = strlen(str); 1.22 + 1.23 + /* error checking in case we have a 64-bit platform -- make sure 1.24 + * we don't have ultra long strings that overflow an int32 1.25 + */ 1.26 + if( sizeof(PRUint32) < sizeof(size_t) ) 1.27 + { 1.28 + if( l > PR_INT32_MAX ) 1.29 + PR_Assert("l <= PR_INT32_MAX", __FILE__, __LINE__); 1.30 + } 1.31 + 1.32 + return (PRUint32)l; 1.33 +} 1.34 + 1.35 +PR_IMPLEMENT(PRUint32) 1.36 +PL_strnlen(const char *str, PRUint32 max) 1.37 +{ 1.38 + register const char *s; 1.39 + 1.40 + if( (const char *)0 == str ) return 0; 1.41 + for( s = str; max && *s; s++, max-- ) 1.42 + ; 1.43 + 1.44 + return (PRUint32)(s - str); 1.45 +}