| OLD | NEW |
| (Empty) |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| 4 | |
| 5 /* | |
| 6 * libc.c | |
| 7 * | |
| 8 * This file contains our wrappers/reimplementations for "standard" | |
| 9 * libc functions. Things like "memcpy." We add to this as we need | |
| 10 * it. Oh, and let's keep it in alphabetical order, should it ever | |
| 11 * get large. Most string/character stuff should be in utf8.c, not | |
| 12 * here. This file (and maybe utf8.c) should be the only ones in | |
| 13 * NSS to include files with angle brackets. | |
| 14 */ | |
| 15 | |
| 16 #ifndef BASE_H | |
| 17 #include "base.h" | |
| 18 #endif /* BASE_H */ | |
| 19 | |
| 20 #include <string.h> /* memcpy, memset */ | |
| 21 | |
| 22 /* | |
| 23 * nsslibc_memcpy | |
| 24 * nsslibc_memset | |
| 25 * nsslibc_offsetof | |
| 26 * nsslibc_memequal | |
| 27 */ | |
| 28 | |
| 29 /* | |
| 30 * nsslibc_memcpy | |
| 31 * | |
| 32 * Errors: | |
| 33 * NSS_ERROR_INVALID_POINTER | |
| 34 * | |
| 35 * Return value: | |
| 36 * NULL on error | |
| 37 * The destination pointer on success | |
| 38 */ | |
| 39 | |
| 40 NSS_IMPLEMENT void * | |
| 41 nsslibc_memcpy(void *dest, const void *source, PRUint32 n) | |
| 42 { | |
| 43 #ifdef NSSDEBUG | |
| 44 if (((void *)NULL == dest) || ((const void *)NULL == source)) { | |
| 45 nss_SetError(NSS_ERROR_INVALID_POINTER); | |
| 46 return (void *)NULL; | |
| 47 } | |
| 48 #endif /* NSSDEBUG */ | |
| 49 | |
| 50 return memcpy(dest, source, (size_t)n); | |
| 51 } | |
| 52 | |
| 53 /* | |
| 54 * nsslibc_memset | |
| 55 * | |
| 56 * Errors: | |
| 57 * NSS_ERROR_INVALID_POINTER | |
| 58 * | |
| 59 * Return value: | |
| 60 * NULL on error | |
| 61 * The destination pointer on success | |
| 62 */ | |
| 63 | |
| 64 NSS_IMPLEMENT void * | |
| 65 nsslibc_memset(void *dest, PRUint8 byte, PRUint32 n) | |
| 66 { | |
| 67 #ifdef NSSDEBUG | |
| 68 if (((void *)NULL == dest)) { | |
| 69 nss_SetError(NSS_ERROR_INVALID_POINTER); | |
| 70 return (void *)NULL; | |
| 71 } | |
| 72 #endif /* NSSDEBUG */ | |
| 73 | |
| 74 return memset(dest, (int)byte, (size_t)n); | |
| 75 } | |
| 76 | |
| 77 /* | |
| 78 * nsslibc_memequal | |
| 79 * | |
| 80 * Errors: | |
| 81 * NSS_ERROR_INVALID_POINTER | |
| 82 * | |
| 83 * Return value: | |
| 84 * PR_TRUE if they match | |
| 85 * PR_FALSE if they don't | |
| 86 * PR_FALSE upon error | |
| 87 */ | |
| 88 | |
| 89 NSS_IMPLEMENT PRBool | |
| 90 nsslibc_memequal(const void *a, const void *b, PRUint32 len, | |
| 91 PRStatus *statusOpt) | |
| 92 { | |
| 93 #ifdef NSSDEBUG | |
| 94 if ((((void *)NULL == a) || ((void *)NULL == b))) { | |
| 95 nss_SetError(NSS_ERROR_INVALID_POINTER); | |
| 96 if ((PRStatus *)NULL != statusOpt) { | |
| 97 *statusOpt = PR_FAILURE; | |
| 98 } | |
| 99 return PR_FALSE; | |
| 100 } | |
| 101 #endif /* NSSDEBUG */ | |
| 102 | |
| 103 if ((PRStatus *)NULL != statusOpt) { | |
| 104 *statusOpt = PR_SUCCESS; | |
| 105 } | |
| 106 | |
| 107 if (0 == memcmp(a, b, len)) { | |
| 108 return PR_TRUE; | |
| 109 } else { | |
| 110 return PR_FALSE; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 /* | |
| 115 * nsslibc_memcmp | |
| 116 */ | |
| 117 | |
| 118 NSS_IMPLEMENT PRInt32 | |
| 119 nsslibc_memcmp(const void *a, const void *b, PRUint32 len, PRStatus *statusOpt) | |
| 120 { | |
| 121 int v; | |
| 122 | |
| 123 #ifdef NSSDEBUG | |
| 124 if ((((void *)NULL == a) || ((void *)NULL == b))) { | |
| 125 nss_SetError(NSS_ERROR_INVALID_POINTER); | |
| 126 if ((PRStatus *)NULL != statusOpt) { | |
| 127 *statusOpt = PR_FAILURE; | |
| 128 } | |
| 129 return -2; | |
| 130 } | |
| 131 #endif /* NSSDEBUG */ | |
| 132 | |
| 133 if ((PRStatus *)NULL != statusOpt) { | |
| 134 *statusOpt = PR_SUCCESS; | |
| 135 } | |
| 136 | |
| 137 v = memcmp(a, b, len); | |
| 138 return (PRInt32)v; | |
| 139 } | |
| 140 | |
| 141 /* | |
| 142 * offsetof is a preprocessor definition | |
| 143 */ | |
| OLD | NEW |