andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #include "plstr.h" andre@0: #include "prtypes.h" andre@0: #include "prlog.h" andre@0: #include andre@0: andre@0: PR_IMPLEMENT(PRUint32) andre@0: PL_strlen(const char *str) andre@0: { andre@0: size_t l; andre@0: andre@0: if( (const char *)0 == str ) return 0; andre@0: andre@0: l = strlen(str); andre@0: andre@0: /* error checking in case we have a 64-bit platform -- make sure andre@0: * we don't have ultra long strings that overflow an int32 andre@0: */ andre@0: if( sizeof(PRUint32) < sizeof(size_t) ) andre@0: { andre@0: if( l > PR_INT32_MAX ) andre@0: PR_Assert("l <= PR_INT32_MAX", __FILE__, __LINE__); andre@0: } andre@0: andre@0: return (PRUint32)l; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRUint32) andre@0: PL_strnlen(const char *str, PRUint32 max) andre@0: { andre@0: register const char *s; andre@0: andre@0: if( (const char *)0 == str ) return 0; andre@0: for( s = str; max && *s; s++, max-- ) andre@0: ; andre@0: andre@0: return (PRUint32)(s - str); andre@0: }