use fstat when we can

This avoids having things change between the stat and open.
This commit is contained in:
Wim Taymans 2020-05-20 13:46:03 +02:00
parent 45c62dfde6
commit ff4a314022
2 changed files with 18 additions and 21 deletions

View file

@ -139,17 +139,15 @@ static int open_read(struct midi_file *mf, const char *filename, struct midi_fil
uint16_t i;
struct stat st;
if (stat(filename, &st) < 0) {
res = -errno;
goto exit;
}
mf->size = st.st_size;
if ((mf->fd = open(filename, O_RDONLY)) < 0) {
res = -errno;
goto exit;
}
if (fstat(mf->fd, &st) < 0) {
res = -errno;
goto exit_close;
}
mf->size = st.st_size;
mf->data = mmap(NULL, mf->size, PROT_READ, MAP_SHARED, mf->fd, 0);
if (mf->data == MAP_FAILED) {