mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-10 15:10:22 +00:00
Add printf method to the File Buffer
Signed-off-by: Vicent Marti <tanoku@gmail.com>
This commit is contained in:
parent
af774b012c
commit
5591ea15a5
@ -22,6 +22,7 @@
|
|||||||
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "filebuf.h"
|
#include "filebuf.h"
|
||||||
@ -259,3 +260,27 @@ int git_filebuf_reserve(git_filebuf *file, void **buffer, size_t len)
|
|||||||
return GIT_SUCCESS;
|
return GIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_filebuf_printf(git_filebuf *file, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arglist;
|
||||||
|
size_t space_left = file->buf_size - file->buf_pos;
|
||||||
|
int len, error;
|
||||||
|
|
||||||
|
va_start(arglist, format);
|
||||||
|
|
||||||
|
len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
|
||||||
|
|
||||||
|
if (len < 0 || (size_t)len >= space_left) {
|
||||||
|
if ((error = flush_buffer(file)) < GIT_SUCCESS)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
len = vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
|
||||||
|
if (len < 0 || (size_t)len > file->buf_size)
|
||||||
|
return GIT_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->buf_pos += len;
|
||||||
|
return GIT_SUCCESS;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ typedef struct git_filebuf git_filebuf;
|
|||||||
|
|
||||||
int git_filebuf_write(git_filebuf *lock, void *buff, size_t len);
|
int git_filebuf_write(git_filebuf *lock, void *buff, size_t len);
|
||||||
int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len);
|
int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len);
|
||||||
|
int git_filebuf_printf(git_filebuf *file, const char *format, ...);
|
||||||
|
|
||||||
int git_filebuf_open(git_filebuf *lock, const char *path, int flags);
|
int git_filebuf_open(git_filebuf *lock, const char *path, int flags);
|
||||||
int git_filebuf_commit(git_filebuf *lock);
|
int git_filebuf_commit(git_filebuf *lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user