OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 #include "mojo/public/c/bindings/buffer.h" | 5 #include <mojo/bindings/buffer.h> |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <mojo/bindings/internal/util.h> |
8 #include <stddef.h> | 9 #include <stddef.h> |
9 | 10 |
10 #include "mojo/public/c/bindings/lib/util.h" | |
11 | |
12 void* MojomBuffer_Allocate(struct MojomBuffer* buf, uint32_t num_bytes) { | 11 void* MojomBuffer_Allocate(struct MojomBuffer* buf, uint32_t num_bytes) { |
13 assert(buf); | 12 assert(buf); |
14 | 13 |
15 const uint32_t bytes_used = buf->num_bytes_used; | 14 const uint32_t bytes_used = buf->num_bytes_used; |
16 const uint64_t size = MOJOM_INTERNAL_ROUND_TO_8((uint64_t)num_bytes); | 15 const uint64_t size = MOJOM_INTERNAL_ROUND_TO_8((uint64_t)num_bytes); |
17 if (bytes_used + size > buf->buf_size) | 16 if (bytes_used + size > buf->buf_size) |
18 return NULL; | 17 return NULL; |
19 | 18 |
20 buf->num_bytes_used += size; | 19 buf->num_bytes_used += size; |
21 return buf->buf + bytes_used; | 20 return buf->buf + bytes_used; |
22 } | 21 } |
OLD | NEW |