зеркало из https://github.com/microsoft/git.git
Cleanup xread() loops to use read_in_full()
Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
471793f91e
Коммит
c697ad143b
|
@ -701,7 +701,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
|||
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);
|
||||
|
@ -716,14 +716,13 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
|||
|
||||
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 {
|
||||
|
|
|
@ -183,7 +183,6 @@ void fixup_pack_header_footer(int pack_fd,
|
|||
|
||||
char *index_pack_lockfile(int ip_out)
|
||||
{
|
||||
int len, s;
|
||||
char packname[46];
|
||||
|
||||
/*
|
||||
|
@ -193,11 +192,8 @@ char *index_pack_lockfile(int ip_out)
|
|||
* 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",
|
||||
|
|
15
pkt-line.c
15
pkt-line.c
|
@ -65,16 +65,11 @@ void packet_write(int fd, const char *fmt, ...)
|
|||
|
||||
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)
|
||||
|
|
14
sha1_file.c
14
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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче