mirror of
https://github.com/git/git.git
synced 2026-03-04 14:37:35 +01:00
In a subsequent commit we're going to add the first caller to writev(3p). Introduce a compatibility wrapper for this syscall that we can use on systems that don't have this syscall. The syscall exists on modern Unixes like Linux and macOS, and seemingly even for NonStop according to [1]. It doesn't seem to exist on Windows though. [1]: http://nonstoptools.com/manuals/OSS-SystemCalls.pdf [2]: https://www.gnu.org/software/gnulib/manual/html_node/writev.html Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
30 lines
671 B
C
30 lines
671 B
C
#include "../git-compat-util.h"
|
|
#include "../wrapper.h"
|
|
|
|
ssize_t git_writev(int fd, const struct iovec *iov, int iovcnt)
|
|
{
|
|
size_t total_written = 0;
|
|
|
|
for (int i = 0; i < iovcnt; i++) {
|
|
const char *bytes = iov[i].iov_base;
|
|
size_t iovec_written = 0;
|
|
|
|
while (iovec_written < iov[i].iov_len) {
|
|
ssize_t bytes_written = xwrite(fd, bytes + iovec_written,
|
|
iov[i].iov_len - iovec_written);
|
|
if (bytes_written < 0) {
|
|
if (total_written)
|
|
goto out;
|
|
return bytes_written;
|
|
}
|
|
if (!bytes_written)
|
|
goto out;
|
|
iovec_written += bytes_written;
|
|
total_written += bytes_written;
|
|
}
|
|
}
|
|
|
|
out:
|
|
return cast_size_t_to_ssize_t(total_written);
|
|
}
|