check for the MAGIC bytes at the beginning of the file
This commit is contained in:
parent
127d84b43c
commit
33dbd46983
10
word_util.c
10
word_util.c
|
@ -16,6 +16,7 @@ struct word_handle *word_file_open(const char *fname)
|
|||
int fd;
|
||||
struct stat st;
|
||||
struct word_handle *wh = calloc(1, sizeof(*wh));
|
||||
struct word_file_hdr *wfh;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
|
@ -34,5 +35,14 @@ struct word_handle *word_file_open(const char *fname)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
wfh = (struct word_file_hdr *) wh->base_addr;
|
||||
|
||||
if (memcmp(wfh->magic, word_file_magic, sizeof(wfh->magic))) {
|
||||
fprintf(stderr, "The file does not appear to be a Word for DOS file!\n");
|
||||
close(wh->fd);
|
||||
free(wh);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return wh;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue