summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 471793f)
raw | patch | inline | side by side (parent: 471793f)
author | Heikki Orsila <heikki.orsila@iki.fi> | |
Sat, 3 May 2008 13:27:26 +0000 (16:27 +0300) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 4 May 2008 05:15:25 +0000 (22:15 -0700) |
Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
combine-diff.c | patch | blob | history | |
pack-write.c | patch | blob | history | |
pkt-line.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
diff --git a/combine-diff.c b/combine-diff.c
index 41aaf83dd315746ae26d1c31ddd78b43c0cb6663..588c58bc55dfe78998d40a4dcce2a7b6ea6f7f5a 100644 (file)
--- a/combine-diff.c
+++ b/combine-diff.c
else if (0 <= (fd = open(elem->path, O_RDONLY)) &&
!fstat(fd, &st)) {
size_t len = xsize_t(st.st_size);
- size_t sz = 0;
+ ssize_t done;
int is_file, i;
elem->mode = canon_mode(st.st_mode);
result_size = len;
result = xmalloc(len + 1);
- while (sz < len) {
- ssize_t done = xread(fd, result+sz, len-sz);
- if (done == 0 && sz != len)
- die("early EOF '%s'", elem->path);
- else if (done < 0)
- die("read error '%s'", elem->path);
- sz += done;
- }
+
+ done = read_in_full(fd, result, len);
+ if (done < 0)
+ die("read error '%s'", elem->path);
+ else if (done < len)
+ die("early EOF '%s'", elem->path);
+
result[len] = 0;
}
else {
diff --git a/pack-write.c b/pack-write.c
index 665e2b29b8817aa6a8aa83ccd859ab51e7bb2234..c66c8af725f6d37b4edaeab75eebac7a387f4922 100644 (file)
--- a/pack-write.c
+++ b/pack-write.c
char *index_pack_lockfile(int ip_out)
{
- int len, s;
char packname[46];
/*
* case, we need it to remove the corresponding .keep file
* later on. If we don't get that then tough luck with it.
*/
- for (len = 0;
- len < 46 && (s = xread(ip_out, packname+len, 46-len)) > 0;
- len += s);
- if (len == 46 && packname[45] == '\n' &&
- memcmp(packname, "keep\t", 5) == 0) {
+ if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n' &&
+ memcmp(packname, "keep\t", 5) == 0) {
char path[PATH_MAX];
packname[45] = 0;
snprintf(path, sizeof(path), "%s/pack/pack-%s.keep",
diff --git a/pkt-line.c b/pkt-line.c
index 355546a1ad844492234dc7ee91528c525af5610a..f5d00863a6234c16db33637d19fefd2014780e87 100644 (file)
--- a/pkt-line.c
+++ b/pkt-line.c
static void safe_read(int fd, void *buffer, unsigned size)
{
- size_t n = 0;
-
- while (n < size) {
- ssize_t ret = xread(fd, (char *) buffer + n, size - n);
- if (ret < 0)
- die("read error (%s)", strerror(errno));
- if (!ret)
- die("The remote end hung up unexpectedly");
- n += ret;
- }
+ ssize_t ret = read_in_full(fd, buffer, size);
+ if (ret < 0)
+ die("read error (%s)", strerror(errno));
+ else if (ret < size)
+ die("The remote end hung up unexpectedly");
}
int packet_read_line(int fd, char *buffer, unsigned size)
diff --git a/sha1_file.c b/sha1_file.c
index c2ab7ea11d7a838c54e5cc8f91ae06a3ee0a2e67..3516777bc7614c23da02dd7a9aa28a48294d56cb 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2466,16 +2466,10 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
int read_pack_header(int fd, struct pack_header *header)
{
- char *c = (char*)header;
- ssize_t remaining = sizeof(struct pack_header);
- do {
- ssize_t r = xread(fd, c, remaining);
- if (r <= 0)
- /* "eof before pack header was fully read" */
- return PH_ERROR_EOF;
- remaining -= r;
- c += r;
- } while (remaining > 0);
+ if (read_in_full(fd, header, sizeof(*header)) < sizeof(*header))
+ /* "eof before pack header was fully read" */
+ return PH_ERROR_EOF;
+
if (header->hdr_signature != htonl(PACK_SIGNATURE))
/* "protocol error (pack signature mismatch detected)" */
return PH_ERROR_PACK_SIGNATURE;