| OLD | NEW |
| 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 #include "utility.h" | 10 #include "utility.h" |
| 10 | 11 |
| 11 #include <stdarg.h> | 12 #include <stdarg.h> |
| 12 #include <stdio.h> | 13 #include <stdio.h> |
| 13 #include <stdlib.h> | 14 #include <stdlib.h> |
| 14 | 15 |
| 15 void error(const char *format, ...) { | 16 void error(const char *format, ...) { |
| 16 va_list ap; | 17 va_list ap; |
| 17 va_start(ap, format); | 18 va_start(ap, format); |
| 18 fprintf(stderr, "ERROR: "); | 19 fprintf(stderr, "ERROR: "); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 int match = 0; | 62 int match = 0; |
| 62 const unsigned char* us1 = s1; | 63 const unsigned char* us1 = s1; |
| 63 const unsigned char* us2 = s2; | 64 const unsigned char* us2 = s2; |
| 64 while (n--) { | 65 while (n--) { |
| 65 if (*us1++ != *us2++) | 66 if (*us1++ != *us2++) |
| 66 match = 1; | 67 match = 1; |
| 67 } | 68 } |
| 68 | 69 |
| 69 return match; | 70 return match; |
| 70 } | 71 } |
| 71 | |
| 72 void* StatefulMemcpy(MemcpyState* state, void* dst, | |
| 73 uint64_t len) { | |
| 74 if (state->overrun) | |
| 75 return NULL; | |
| 76 if (len > state->remaining_len) { | |
| 77 state->overrun = 1; | |
| 78 return NULL; | |
| 79 } | |
| 80 Memcpy(dst, state->remaining_buf, len); | |
| 81 state->remaining_buf += len; | |
| 82 state->remaining_len -= len; | |
| 83 return dst; | |
| 84 } | |
| 85 | |
| 86 const void* StatefulMemcpy_r(MemcpyState* state, const void* src, | |
| 87 uint64_t len) { | |
| 88 if (state->overrun) | |
| 89 return NULL; | |
| 90 if (len > state->remaining_len) { | |
| 91 state->overrun = 1; | |
| 92 return NULL; | |
| 93 } | |
| 94 Memcpy(state->remaining_buf, src, len); | |
| 95 state->remaining_buf += len; | |
| 96 state->remaining_len -= len; | |
| 97 return src; | |
| 98 } | |
| 99 | |
| 100 const void* StatefulMemset_r(MemcpyState* state, const uint8_t val, | |
| 101 uint64_t len) { | |
| 102 if (state->overrun) | |
| 103 return NULL; | |
| 104 if (len > state->remaining_len) { | |
| 105 state->overrun = 1; | |
| 106 return NULL; | |
| 107 } | |
| 108 Memset(state->remaining_buf, val, len); | |
| 109 state->remaining_buf += len; | |
| 110 state->remaining_len -= len; | |
| 111 return state; // have to return something non-NULL | |
| 112 } | |
| OLD | NEW |