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
e7be6b76
Commit
e7be6b76
authored
Nov 29, 2021
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
futils: provide an option to read a whole file by fd
parent
b8771227
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
src/util/futils.c
+36
-0
src/util/futils.h
+1
-0
No files found.
src/util/futils.c
View file @
e7be6b76
...
...
@@ -179,6 +179,42 @@ int git_futils_readbuffer_fd(git_str *buf, git_file fd, size_t len)
return
0
;
}
int
git_futils_readbuffer_fd_full
(
git_str
*
buf
,
git_file
fd
)
{
static
size_t
blocksize
=
10240
;
size_t
alloc_len
=
0
,
total_size
=
0
;
ssize_t
read_size
=
0
;
git_str_clear
(
buf
);
while
(
true
)
{
GIT_ERROR_CHECK_ALLOC_ADD
(
&
alloc_len
,
alloc_len
,
blocksize
);
if
(
git_str_grow
(
buf
,
alloc_len
)
<
0
)
return
-
1
;
/* p_read loops internally to read blocksize bytes */
read_size
=
p_read
(
fd
,
buf
->
ptr
,
blocksize
);
if
(
read_size
<
0
)
{
git_error_set
(
GIT_ERROR_OS
,
"failed to read descriptor"
);
git_str_dispose
(
buf
);
return
-
1
;
}
total_size
+=
read_size
;
if
((
size_t
)
read_size
<
blocksize
)
{
break
;
}
}
buf
->
ptr
[
total_size
]
=
'\0'
;
buf
->
size
=
total_size
;
return
0
;
}
int
git_futils_readbuffer_updated
(
git_str
*
out
,
const
char
*
path
,
...
...
src/util/futils.h
View file @
e7be6b76
...
...
@@ -27,6 +27,7 @@ extern int git_futils_readbuffer_updated(
const
char
*
path
,
unsigned
char
checksum
[
GIT_HASH_SHA1_SIZE
],
int
*
updated
);
extern
int
git_futils_readbuffer_fd_full
(
git_str
*
obj
,
git_file
fd
);
extern
int
git_futils_readbuffer_fd
(
git_str
*
obj
,
git_file
fd
,
size_t
len
);
/* Additional constants for `git_futils_writebuffer`'s `open_flags`. We
...
...
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