blob: 389961b372e1087a761bd175306371f997dc1507 [file] [log] [blame]
Bill Richardsond6ff7212010-05-27 12:27:32 -07001/* 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 * Stub implementations of utility functions which call their linux-specific
6 * equivalents.
7 */
8
9#include "stateful_util.h"
10
11#include <stdarg.h>
12#include <stdio.h>
13#include <stdlib.h>
14
Randall Spanglera9f17aa2010-05-27 16:18:35 -070015void* StatefulSkip(MemcpyState* state, uint64_t len) {
16 if (state->overrun)
17 return NULL;
18 if (len > state->remaining_len) {
19 state->overrun = 1;
20 return NULL;
21 }
22 state->remaining_buf += len;
23 state->remaining_len -= len;
24 return state; // have to return something non-NULL
25}
26
Bill Richardsond6ff7212010-05-27 12:27:32 -070027void* StatefulMemcpy(MemcpyState* state, void* dst,
28 uint64_t len) {
29 if (state->overrun)
30 return NULL;
31 if (len > state->remaining_len) {
32 state->overrun = 1;
33 return NULL;
34 }
35 Memcpy(dst, state->remaining_buf, len);
36 state->remaining_buf += len;
37 state->remaining_len -= len;
38 return dst;
39}
40
41const void* StatefulMemcpy_r(MemcpyState* state, const void* src,
42 uint64_t len) {
43 if (state->overrun)
44 return NULL;
45 if (len > state->remaining_len) {
46 state->overrun = 1;
47 return NULL;
48 }
49 Memcpy(state->remaining_buf, src, len);
50 state->remaining_buf += len;
51 state->remaining_len -= len;
52 return src;
53}
54
55const void* StatefulMemset_r(MemcpyState* state, const uint8_t val,
56 uint64_t len) {
57 if (state->overrun)
58 return NULL;
59 if (len > state->remaining_len) {
60 state->overrun = 1;
61 return NULL;
62 }
63 Memset(state->remaining_buf, val, len);
64 state->remaining_buf += len;
65 state->remaining_len -= len;
66 return state; // have to return something non-NULL
67}