summaryrefslogtreecommitdiff
path: root/src/arscan.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2018-09-16 01:04:10 -0400
committerPaul Smith <psmith@gnu.org>2018-09-16 01:04:10 -0400
commit5d6508a475d66df5fcbbdc2b8800672381303014 (patch)
tree4ef08d5ca4fba10b9e6e564fa8ece2c82c91e543 /src/arscan.c
parentac11ec5497b3b20b43a08da463d8a4460db8116b (diff)
downloadmake-git-5d6508a475d66df5fcbbdc2b8800672381303014.tar.gz
Change output_write() to writebuf(), add readbuf() helper.
* src/misc.c (writebuf, readbuf): Create helper functions that will reliably write a buffer to a file descriptor in the face of EINTR causing short writes, and read from a file descriptor into a buffer in the face of EINTR causing short reads. * src/makeint.h: Declare these functions. * src/output.c: Remove output_write() and replace with writebuf(). (_outputs, out_of_memory): Call writebuf(), not output_write(). * src/arscan.c (ar_scan): Call readbuf() instead of read(2). (ar_member_touch): Remove duplicate header write, call writebuf() instead of output_write(), and readbuf() instead of read(2).
Diffstat (limited to 'src/arscan.c')
-rw-r--r--src/arscan.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/arscan.c b/src/arscan.c
index 22c5438f..94879171 100644
--- a/src/arscan.c
+++ b/src/arscan.c
@@ -425,7 +425,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
{
char buf[SARMAG];
int nread;
- EINTRLOOP (nread, read (desc, buf, SARMAG));
+ nread = readbuf (desc, buf, SARMAG);
if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG))
goto invalid;
}
@@ -433,7 +433,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
#ifdef AIAMAG
{
int nread;
- EINTRLOOP (nread, read (desc, &fl_header, FL_HSZ));
+ nread = readbuf (desc, &fl_header, FL_HSZ);
if (nread != FL_HSZ)
goto invalid;
@@ -452,7 +452,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
goto invalid;
/* re-read the header into the "big" structure */
- EINTRLOOP (nread, read (desc, &fl_header_big, FL_HSZ_BIG));
+ nread = readbuf (desc, &fl_header_big, FL_HSZ_BIG);
if (nread != FL_HSZ_BIG)
goto invalid;
}
@@ -470,7 +470,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
unsigned short int buf;
#endif
int nread;
- EINTRLOOP (nread, read (desc, &buf, sizeof (buf)));
+ nread = readbuf (desc, &buf, sizeof (buf));
if (nread != sizeof (buf) || buf != ARMAG)
goto invalid;
}
@@ -550,8 +550,8 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
#ifdef AIAMAGBIG
if (big_archive)
{
- EINTRLOOP (nread, read (desc, &member_header_big,
- AR_MEMHDR_SZ(member_header_big)));
+ nread = readbuf (desc, &member_header_big,
+ AR_MEMHDR_SZ(member_header_big));
if (nread != AR_MEMHDR_SZ(member_header_big))
goto invalid;
@@ -560,7 +560,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
if (name_len < 1 || name_len > ARNAME_MAX)
goto invalid;
- EINTRLOOP (nread, read (desc, name, name_len));
+ nread = readbuf (desc, name, name_len);
if (nread != name_len)
goto invalid;
@@ -578,8 +578,8 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
else
#endif
{
- EINTRLOOP (nread, read (desc, &member_header,
- AR_MEMHDR_SZ(member_header)));
+ nread = readbuf (desc, &member_header,
+ AR_MEMHDR_SZ(member_header));
if (nread != AR_MEMHDR_SZ(member_header))
goto invalid;
@@ -588,7 +588,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
if (name_len < 1 || name_len > ARNAME_MAX)
goto invalid;
- EINTRLOOP (nread, read (desc, name, name_len));
+ nread = readbuf (desc, name, name_len);
if (nread != name_len)
goto invalid;
@@ -612,7 +612,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
eltmode, arg);
#else /* Not AIAMAG. */
- EINTRLOOP (nread, read (desc, &member_header, AR_HDR_SIZE));
+ nread = readbuf (desc, &member_header, AR_HDR_SIZE);
if (nread == 0)
/* No data left means end of file; that is OK. */
break;
@@ -691,7 +691,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
goto invalid;
name = alloca (name_len + 1);
- EINTRLOOP (nread, read (desc, name, name_len));
+ nread = readbuf (desc, name, name_len);
if (nread != name_len)
goto invalid;
@@ -759,7 +759,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
if (eltsize > INT_MAX)
goto invalid;
namemap = alloca (eltsize + 1);
- EINTRLOOP (nread, read (desc, namemap, eltsize));
+ nread = readbuf (desc, namemap, eltsize);
if (nread != eltsize)
goto invalid;
namemap_size = eltsize;
@@ -897,14 +897,7 @@ ar_member_touch (const char *arname, const char *memname)
EINTRLOOP (o, lseek (fd, pos, 0));
if (o < 0)
goto lose;
- EINTRLOOP (r, read (fd, &ar_hdr, AR_HDR_SIZE));
- if (r != AR_HDR_SIZE)
- goto lose;
- /* Write back the header, thus touching the archive file. */
- EINTRLOOP (o, lseek (fd, pos, 0));
- if (o < 0)
- goto lose;
- r = output_write (fd, &ar_hdr, AR_HDR_SIZE);
+ r = readbuf (fd, &ar_hdr, AR_HDR_SIZE);
if (r != AR_HDR_SIZE)
goto lose;
/* The file's mtime is the time we we want. */
@@ -926,7 +919,7 @@ ar_member_touch (const char *arname, const char *memname)
EINTRLOOP (o, lseek (fd, pos, 0));
if (o < 0)
goto lose;
- r = output_write (fd, &ar_hdr, AR_HDR_SIZE);
+ r = writebuf (fd, &ar_hdr, AR_HDR_SIZE);
if (r != AR_HDR_SIZE)
goto lose;
close (fd);