check for the MAGIC bytes at the beginning of the file

This commit is contained in:
Harald Welte 2011-03-26 22:48:33 +01:00
parent 127d84b43c
commit 33dbd46983
1 changed files with 10 additions and 0 deletions

View File

@ -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;
}