]>
git.proxmox.com Git - libgit2.git/blob - src/buf.h
2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_buf_h__
8 #define INCLUDE_buf_h__
10 #include "git2/buffer.h"
14 * Adapts a private API that takes a `git_str` into a public API that
18 #define GIT_BUF_WRAP_PRIVATE(buf, fn, ...) \
20 git_str str = GIT_STR_INIT; \
22 if ((error = git_buf_tostr(&str, buf)) == 0 && \
23 (error = fn(&str, __VA_ARGS__)) == 0) \
24 error = git_buf_fromstr(buf, &str); \
25 git_str_dispose(&str); \
30 * "Sanitizes" a buffer from user input. This simply ensures that the
31 * `git_buf` has nice defaults if the user didn't set the members to
32 * anything, so that if we return early we don't leave it populated
35 extern int git_buf_sanitize(git_buf
*from_user
);
38 * Populate a `git_str` from a `git_buf` for passing to libgit2 internal
39 * functions. Sanitizes the given `git_buf` before proceeding. The
40 * `git_buf` will no longer point to this memory.
42 extern int git_buf_tostr(git_str
*out
, git_buf
*buf
);
45 * Populate a `git_buf` from a `git_str` for returning to a user.
46 * The `git_str` will no longer point to this memory.
48 extern int git_buf_fromstr(git_buf
*out
, git_str
*str
);