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: /* andre@0: * libc.c andre@0: * andre@0: * This file contains our wrappers/reimplementations for "standard" andre@0: * libc functions. Things like "memcpy." We add to this as we need andre@0: * it. Oh, and let's keep it in alphabetical order, should it ever andre@0: * get large. Most string/character stuff should be in utf8.c, not andre@0: * here. This file (and maybe utf8.c) should be the only ones in andre@0: * NSS to include files with angle brackets. andre@0: */ andre@0: andre@0: #ifndef BASE_H andre@0: #include "base.h" andre@0: #endif /* BASE_H */ andre@0: andre@0: #include /* memcpy, memset */ andre@0: andre@0: /* andre@0: * nsslibc_memcpy andre@0: * nsslibc_memset andre@0: * nsslibc_offsetof andre@0: * nsslibc_memequal andre@0: */ andre@0: andre@0: /* andre@0: * nsslibc_memcpy andre@0: * andre@0: * Errors: andre@0: * NSS_ERROR_INVALID_POINTER andre@0: * andre@0: * Return value: andre@0: * NULL on error andre@0: * The destination pointer on success andre@0: */ andre@0: andre@0: NSS_IMPLEMENT void * andre@0: nsslibc_memcpy andre@0: ( andre@0: void *dest, andre@0: const void *source, andre@0: PRUint32 n andre@0: ) andre@0: { andre@0: #ifdef NSSDEBUG andre@0: if( ((void *)NULL == dest) || ((const void *)NULL == source) ) { andre@0: nss_SetError(NSS_ERROR_INVALID_POINTER); andre@0: return (void *)NULL; andre@0: } andre@0: #endif /* NSSDEBUG */ andre@0: andre@0: return memcpy(dest, source, (size_t)n); andre@0: } andre@0: andre@0: /* andre@0: * nsslibc_memset andre@0: * andre@0: * Errors: andre@0: * NSS_ERROR_INVALID_POINTER andre@0: * andre@0: * Return value: andre@0: * NULL on error andre@0: * The destination pointer on success andre@0: */ andre@0: andre@0: NSS_IMPLEMENT void * andre@0: nsslibc_memset andre@0: ( andre@0: void *dest, andre@0: PRUint8 byte, andre@0: PRUint32 n andre@0: ) andre@0: { andre@0: #ifdef NSSDEBUG andre@0: if( ((void *)NULL == dest) ) { andre@0: nss_SetError(NSS_ERROR_INVALID_POINTER); andre@0: return (void *)NULL; andre@0: } andre@0: #endif /* NSSDEBUG */ andre@0: andre@0: return memset(dest, (int)byte, (size_t)n); andre@0: } andre@0: andre@0: /* andre@0: * nsslibc_memequal andre@0: * andre@0: * Errors: andre@0: * NSS_ERROR_INVALID_POINTER andre@0: * andre@0: * Return value: andre@0: * PR_TRUE if they match andre@0: * PR_FALSE if they don't andre@0: * PR_FALSE upon error andre@0: */ andre@0: andre@0: NSS_IMPLEMENT PRBool andre@0: nsslibc_memequal andre@0: ( andre@0: const void *a, andre@0: const void *b, andre@0: PRUint32 len, andre@0: PRStatus *statusOpt andre@0: ) andre@0: { andre@0: #ifdef NSSDEBUG andre@0: if( (((void *)NULL == a) || ((void *)NULL == b)) ) { andre@0: nss_SetError(NSS_ERROR_INVALID_POINTER); andre@0: if( (PRStatus *)NULL != statusOpt ) { andre@0: *statusOpt = PR_FAILURE; andre@0: } andre@0: return PR_FALSE; andre@0: } andre@0: #endif /* NSSDEBUG */ andre@0: andre@0: if( (PRStatus *)NULL != statusOpt ) { andre@0: *statusOpt = PR_SUCCESS; andre@0: } andre@0: andre@0: if( 0 == memcmp(a, b, len) ) { andre@0: return PR_TRUE; andre@0: } else { andre@0: return PR_FALSE; andre@0: } andre@0: } andre@0: andre@0: /* andre@0: * nsslibc_memcmp andre@0: */ andre@0: andre@0: NSS_IMPLEMENT PRInt32 andre@0: nsslibc_memcmp andre@0: ( andre@0: const void *a, andre@0: const void *b, andre@0: PRUint32 len, andre@0: PRStatus *statusOpt andre@0: ) andre@0: { andre@0: int v; andre@0: andre@0: #ifdef NSSDEBUG andre@0: if( (((void *)NULL == a) || ((void *)NULL == b)) ) { andre@0: nss_SetError(NSS_ERROR_INVALID_POINTER); andre@0: if( (PRStatus *)NULL != statusOpt ) { andre@0: *statusOpt = PR_FAILURE; andre@0: } andre@0: return -2; andre@0: } andre@0: #endif /* NSSDEBUG */ andre@0: andre@0: if( (PRStatus *)NULL != statusOpt ) { andre@0: *statusOpt = PR_SUCCESS; andre@0: } andre@0: andre@0: v = memcmp(a, b, len); andre@0: return (PRInt32)v; andre@0: } andre@0: andre@0: /* andre@0: * offsetof is a preprocessor definition andre@0: */