| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/public/c/bindings/buffer.h" |
| 6 |
| 7 #include <assert.h> |
| 8 #include <stddef.h> // for NULL |
| 9 |
| 10 void* MojomBuffer_Allocate(struct MojomBuffer* buf, uint32_t num_bytes) { |
| 11 assert(buf); |
| 12 |
| 13 static const size_t kAlignment = 8; |
| 14 const uint32_t bytes_used = buf->num_bytes_used; |
| 15 |
| 16 // size = num_bytes is rounded to 8 bytes: |
| 17 const uint64_t size = ((uint64_t)num_bytes + (kAlignment-1)) |
| 18 & ~(kAlignment-1); |
| 19 if (bytes_used + size > buf->buf_size) |
| 20 return NULL; |
| 21 |
| 22 buf->num_bytes_used += size; |
| 23 return buf->buf + bytes_used; |
| 24 } |
| OLD | NEW |