Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: firmware/stub/utility_stub.c

Issue 3041005: Add lots of debugging to TPM library. (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Fix TPM unit tests Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « firmware/linktest/main.c ('k') | firmware/version.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Stub implementations of utility functions which call their linux-specific 5 * Stub implementations of utility functions which call their linux-specific
6 * equivalents. 6 * equivalents.
7 */ 7 */
8 8
9 #define _STUB_IMPLEMENTATION_ 9 #define _STUB_IMPLEMENTATION_
10 #include "utility.h" 10 #include "utility.h"
11 11
12 #include <stdarg.h> 12 #include <stdarg.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> 15 #include <string.h>
16 16
17 void error(const char *format, ...) { 17 void error(const char *format, ...) {
18 va_list ap; 18 va_list ap;
19 va_start(ap, format); 19 va_start(ap, format);
20 fprintf(stderr, "ERROR: "); 20 fprintf(stderr, "ERROR: ");
21 vfprintf(stderr, format, ap); 21 vfprintf(stderr, format, ap);
22 va_end(ap); 22 va_end(ap);
23 exit(1); 23 exit(1);
24 } 24 }
25 25
26 void debug(const char *format, ...) { 26 void debug(const char *format, ...) {
27 va_list ap; 27 va_list ap;
28 va_start(ap, format); 28 va_start(ap, format);
29 fprintf(stderr, "WARNING: "); 29 fprintf(stderr, "DEBUG: ");
30 vfprintf(stderr, format, ap); 30 vfprintf(stderr, format, ap);
31 va_end(ap); 31 va_end(ap);
32 } 32 }
33 33
34 void* Malloc(size_t size) { 34 void* Malloc(size_t size) {
35 void* p = malloc(size); 35 void* p = malloc(size);
36 if (!p) { 36 if (!p) {
37 /* Fatal Error. We must abort. */ 37 /* Fatal Error. We must abort. */
38 abort(); 38 abort();
39 } 39 }
40 return p; 40 return p;
41 } 41 }
42 42
43 void Free(void* ptr) { 43 void Free(void* ptr) {
44 free(ptr); 44 free(ptr);
45 } 45 }
46 46
47 int Memcmp(const void* src1, const void* src2, size_t n) { 47 int Memcmp(const void* src1, const void* src2, size_t n) {
48 return memcmp(src1, src2, n); 48 return memcmp(src1, src2, n);
49 } 49 }
50 50
51 void* Memcpy(void* dest, const void* src, uint64_t n) { 51 void* Memcpy(void* dest, const void* src, uint64_t n) {
52 return memcpy(dest, src, (size_t)n); 52 return memcpy(dest, src, (size_t)n);
53 } 53 }
54 54
55 void* Memset(void* d, const uint8_t c, uint64_t n) { 55 void* Memset(void* d, const uint8_t c, uint64_t n) {
56 uint8_t *dest = d; /* the only way to keep both cl and gcc happy */ 56 uint8_t* dest = d; /* the only way to keep both cl and gcc happy */
57 while (n--) { 57 while (n--) {
58 *dest++ = c; 58 *dest++ = c;
59 } 59 }
60 return dest; 60 return dest;
61 } 61 }
62 62
63 int SafeMemcmp(const void* s1, const void* s2, size_t n) { 63 int SafeMemcmp(const void* s1, const void* s2, size_t n) {
64 int match = 0; 64 int match = 0;
65 const unsigned char* us1 = s1; 65 const unsigned char* us1 = s1;
66 const unsigned char* us2 = s2; 66 const unsigned char* us2 = s2;
67 while (n--) { 67 while (n--) {
68 if (*us1++ != *us2++) 68 if (*us1++ != *us2++)
69 match = 1; 69 match = 1;
70 } 70 }
71 71
72 return match; 72 return match;
73 } 73 }
OLDNEW
« no previous file with comments | « firmware/linktest/main.c ('k') | firmware/version.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698