Seek to start of file before reading mop file header

Originally, functions assumed that the current location in the
file was correct and did not seek before reads. The Check
functions would seek back to the start after the read, so the
next function would have its expectation met. The file info
functions did not seek after the read, because mop and a.out
file data always starts immediately after the header.

CheckElfFile() broke this convention, seeking before the read,
and not after. The previous commit changes a.out functions to
seek before reading, and not after. Now this changes mop file
functions similarly, so all three work together.

mopFileRead() still assumes the current location in the file is
correct for reading data from a.out and mop files, and does reads
without seeking.
This commit is contained in:
Boris Gjenero 2020-10-29 20:22:53 -04:00
parent 2f79266747
commit 83003f30d7

View File

@ -155,11 +155,11 @@ CheckMopFile(int fd)
u_char header[512];
short image_type;
(void)lseek(fd, (off_t) 0, SEEK_SET);
if (read(fd, header, 512) != 512)
return(-1);
(void)lseek(fd, (off_t) 0, SEEK_SET);
image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
header[IHD_W_ALIAS]);
@ -186,6 +186,8 @@ GetMopFileInfo(struct dllist *dl)
short image_type;
u_int32_t load_addr, xfr_addr, isd, iha, hbcnt, isize;
(void)lseek(dl->ldfd, (off_t) 0, SEEK_SET);
if (read(dl->ldfd, header, 512) != 512)
return(-1);
@ -880,6 +882,11 @@ GetFileInfo(struct dllist *dl)
return(-1);
}
/* For mop and a.out files, this function assumes the current position in the
* file is correct, and reads sequentially, without seeking. For those files,
* the position needs to start after the header and not change between calls
* to this function.
*/
ssize_t
mopFileRead(struct dllist *dlslot, u_char *buf)
{