comparison nss/lib/base/libc.c @ 0:1e5118fa0cb1

This is NSS with a Cmake Buildsyste To compile a static NSS library for Windows we've used the Chromium-NSS fork and added a Cmake buildsystem to compile it statically for Windows. See README.chromium for chromium changes and README.trustbridge for our modifications.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 28 Jul 2014 10:47:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e5118fa0cb1
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
42 (
43 void *dest,
44 const void *source,
45 PRUint32 n
46 )
47 {
48 #ifdef NSSDEBUG
49 if( ((void *)NULL == dest) || ((const void *)NULL == source) ) {
50 nss_SetError(NSS_ERROR_INVALID_POINTER);
51 return (void *)NULL;
52 }
53 #endif /* NSSDEBUG */
54
55 return memcpy(dest, source, (size_t)n);
56 }
57
58 /*
59 * nsslibc_memset
60 *
61 * Errors:
62 * NSS_ERROR_INVALID_POINTER
63 *
64 * Return value:
65 * NULL on error
66 * The destination pointer on success
67 */
68
69 NSS_IMPLEMENT void *
70 nsslibc_memset
71 (
72 void *dest,
73 PRUint8 byte,
74 PRUint32 n
75 )
76 {
77 #ifdef NSSDEBUG
78 if( ((void *)NULL == dest) ) {
79 nss_SetError(NSS_ERROR_INVALID_POINTER);
80 return (void *)NULL;
81 }
82 #endif /* NSSDEBUG */
83
84 return memset(dest, (int)byte, (size_t)n);
85 }
86
87 /*
88 * nsslibc_memequal
89 *
90 * Errors:
91 * NSS_ERROR_INVALID_POINTER
92 *
93 * Return value:
94 * PR_TRUE if they match
95 * PR_FALSE if they don't
96 * PR_FALSE upon error
97 */
98
99 NSS_IMPLEMENT PRBool
100 nsslibc_memequal
101 (
102 const void *a,
103 const void *b,
104 PRUint32 len,
105 PRStatus *statusOpt
106 )
107 {
108 #ifdef NSSDEBUG
109 if( (((void *)NULL == a) || ((void *)NULL == b)) ) {
110 nss_SetError(NSS_ERROR_INVALID_POINTER);
111 if( (PRStatus *)NULL != statusOpt ) {
112 *statusOpt = PR_FAILURE;
113 }
114 return PR_FALSE;
115 }
116 #endif /* NSSDEBUG */
117
118 if( (PRStatus *)NULL != statusOpt ) {
119 *statusOpt = PR_SUCCESS;
120 }
121
122 if( 0 == memcmp(a, b, len) ) {
123 return PR_TRUE;
124 } else {
125 return PR_FALSE;
126 }
127 }
128
129 /*
130 * nsslibc_memcmp
131 */
132
133 NSS_IMPLEMENT PRInt32
134 nsslibc_memcmp
135 (
136 const void *a,
137 const void *b,
138 PRUint32 len,
139 PRStatus *statusOpt
140 )
141 {
142 int v;
143
144 #ifdef NSSDEBUG
145 if( (((void *)NULL == a) || ((void *)NULL == b)) ) {
146 nss_SetError(NSS_ERROR_INVALID_POINTER);
147 if( (PRStatus *)NULL != statusOpt ) {
148 *statusOpt = PR_FAILURE;
149 }
150 return -2;
151 }
152 #endif /* NSSDEBUG */
153
154 if( (PRStatus *)NULL != statusOpt ) {
155 *statusOpt = PR_SUCCESS;
156 }
157
158 v = memcmp(a, b, len);
159 return (PRInt32)v;
160 }
161
162 /*
163 * offsetof is a preprocessor definition
164 */
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)