#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.206 2014/04/30 21:41:02 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.207 2014/05/04 18:57:35 christos Exp $")
#endif /* lint */
#include "magic.h"
return NULL;
}
-private const uint32_t ar[] = {
- MAGICNO, VERSIONNO
-};
-
/*
* handle an mmaped file.
*/
char *dbname;
int rv = -1;
uint32_t i;
+ union {
+ struct magic m;
+ uint32_t h[2 + MAGIC_SETS];
+ } hdr;
dbname = mkdbname(ms, fn, 1);
file_error(ms, errno, "cannot open `%s'", dbname);
goto out;
}
+ memset(&hdr, 0, sizeof(hdr));
+ hdr.h[0] = MAGICNO;
+ hdr.h[1] = VERSIONNO;
+ memcpy(hdr.h + 2, map->nmagic, nm);
- if (write(fd, ar, sizeof(ar)) != (ssize_t)sizeof(ar)) {
- file_error(ms, errno, "error writing `%s'", dbname);
- goto out;
- }
-
- if (write(fd, map->nmagic, nm) != (ssize_t)nm) {
+ if (write(fd, &hdr, sizeof(hdr)) != (ssize_t)sizeof(hdr)) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
- assert(nm + sizeof(ar) < m);
-
- if (lseek(fd, (off_t)m, SEEK_SET) != (off_t)m) {
- file_error(ms, errno, "error seeking `%s'", dbname);
- goto out;
- }
-
for (i = 0; i < MAGIC_SETS; i++) {
len = m * map->nmagic[i];
if (write(fd, map->magic[i], len) != (ssize_t)len) {