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:
committed by
Junio C Hamano
parent
471793f91e
commit
c697ad143b
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;
|
||||
|
||||
Reference in New Issue
Block a user