OLD | NEW |
(Empty) | |
| 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 |
| 3 * found in the LICENSE file. |
| 4 * |
| 5 * Utility functions that need to be built as part of the firmware. |
| 6 */ |
| 7 |
| 8 #include "utility.h" |
| 9 |
| 10 void* Memset(void* d, const uint8_t c, uint64_t n) { |
| 11 uint8_t* dest = d; /* the only way to keep both cl and gcc happy */ |
| 12 while (n--) { |
| 13 *dest++ = c; |
| 14 } |
| 15 return dest; |
| 16 } |
| 17 |
| 18 int SafeMemcmp(const void* s1, const void* s2, size_t n) { |
| 19 int result = 0; |
| 20 if (0 == n) |
| 21 return 1; |
| 22 |
| 23 const unsigned char* us1 = s1; |
| 24 const unsigned char* us2 = s2; |
| 25 /* Code snippet without data-dependent branch due to |
| 26 * Nate Lawson (nate@root.org) of Root Labs. */ |
| 27 while (n--) |
| 28 result |= *us1++ ^ *us2++; |
| 29 |
| 30 return result != 0; |
| 31 } |
OLD | NEW |