sapling/lib/clib/buffer.c
Wez Furlong 31bcfbe58e hg: disable check-code tests for C code
Summary:
They're actively fighting against the clang-format config
and don't have an auto-fix.

Reviewed By: quark-zju

Differential Revision: D8283622

fbshipit-source-id: 2de45f50e6370a5ed14915c6ff23dc843ff14e8a
2018-06-05 19:21:43 -07:00

42 lines
949 B
C

// Copyright (c) 2004-present, Facebook, Inc.
// All Rights Reserved.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
// buffer.c: implementation for a generic mechanism to expand a heap-allocated
// buffer.
// no-check-code
#include <stdlib.h>
#include <string.h>
#include "lib/clib/buffer.h"
bool buffer_append(
char** buffer,
size_t* buffer_idx,
size_t* buffer_sz,
char* input,
size_t input_sz,
const float factor,
const size_t min_increment,
const size_t max_increment) {
if (expand_to_fit(
(void**)buffer,
*buffer_idx,
buffer_sz,
input_sz,
sizeof(char),
factor,
min_increment,
max_increment) == false) {
return false;
}
memcpy(&(*buffer)[*buffer_idx], input, input_sz);
*buffer_idx += input_sz;
return true;
}