summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7df1709)
raw | patch | inline | side by side (parent: 7df1709)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 20 Jul 2008 23:13:05 +0000 (16:13 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 21 Jul 2008 00:17:09 +0000 (17:17 -0700) |
A few compat/* layer functions call these functions, but we would really
want to keep them thin, without depending too much on the libgit proper.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
want to keep them thin, without depending too much on the libgit proper.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
wrapper.c | patch | blob | history | |
write_or_die.c | patch | blob | history |
diff --git a/wrapper.c b/wrapper.c
index 4e04f7661b4943059243fa5f8a33baeec4a96583..93562f03eef21b26945d2d9bbdc96818f4de6567 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
}
}
+ssize_t read_in_full(int fd, void *buf, size_t count)
+{
+ char *p = buf;
+ ssize_t total = 0;
+
+ while (count > 0) {
+ ssize_t loaded = xread(fd, p, count);
+ if (loaded <= 0)
+ return total ? total : loaded;
+ count -= loaded;
+ p += loaded;
+ total += loaded;
+ }
+
+ return total;
+}
+
+ssize_t write_in_full(int fd, const void *buf, size_t count)
+{
+ const char *p = buf;
+ ssize_t total = 0;
+
+ while (count > 0) {
+ ssize_t written = xwrite(fd, p, count);
+ if (written < 0)
+ return -1;
+ if (!written) {
+ errno = ENOSPC;
+ return -1;
+ }
+ count -= written;
+ p += written;
+ total += written;
+ }
+
+ return total;
+}
+
int xdup(int fd)
{
int ret = dup(fd);
diff --git a/write_or_die.c b/write_or_die.c
index e4c8e225fd232dfd642aa13d7ae5b64b9827c915..4c29255df1b637f93ab3d59e0dcab1fa3b40e10b 100644 (file)
--- a/write_or_die.c
+++ b/write_or_die.c
}
}
-ssize_t read_in_full(int fd, void *buf, size_t count)
-{
- char *p = buf;
- ssize_t total = 0;
-
- while (count > 0) {
- ssize_t loaded = xread(fd, p, count);
- if (loaded <= 0)
- return total ? total : loaded;
- count -= loaded;
- p += loaded;
- total += loaded;
- }
-
- return total;
-}
-
-ssize_t write_in_full(int fd, const void *buf, size_t count)
-{
- const char *p = buf;
- ssize_t total = 0;
-
- while (count > 0) {
- ssize_t written = xwrite(fd, p, count);
- if (written < 0)
- return -1;
- if (!written) {
- errno = ENOSPC;
- return -1;
- }
- count -= written;
- p += written;
- total += written;
- }
-
- return total;
-}
-
void fsync_or_die(int fd, const char *msg)
{
if (fsync(fd) < 0) {