Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
5591ea15
Commit
5591ea15
authored
Feb 22, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add printf method to the File Buffer
Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent
af774b01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
src/filebuf.c
+25
-0
src/filebuf.h
+1
-0
No files found.
src/filebuf.c
View file @
5591ea15
...
...
@@ -22,6 +22,7 @@
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stdarg.h>
#include "common.h"
#include "filebuf.h"
...
...
@@ -259,3 +260,27 @@ int git_filebuf_reserve(git_filebuf *file, void **buffer, size_t len)
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
;
}
src/filebuf.h
View file @
5591ea15
...
...
@@ -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_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_commit
(
git_filebuf
*
lock
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment