| 30 |
*/ |
*/ |
| 31 |
|
|
| 32 |
#include <sys/param.h> |
#include <sys/param.h> |
| 33 |
|
#include <sys/mman.h> |
| 34 |
|
#include <sys/stat.h> |
| 35 |
|
|
| 36 |
#include <err.h> |
#include <err.h> |
| 37 |
#include <errno.h> |
#include <errno.h> |
| 42 |
#include <unistd.h> |
#include <unistd.h> |
| 43 |
|
|
| 44 |
#include "nfotiser.h" |
#include "nfotiser.h" |
| 45 |
|
|
| 46 |
|
struct parser_result * |
| 47 |
|
nfo_parse(int fd, const struct parser_keywords *kws) |
| 48 |
|
{ |
| 49 |
|
struct parser_result *res; |
| 50 |
|
struct parser_res *entry; |
| 51 |
|
char ch, *cp, *t, *buf; |
| 52 |
|
size_t len, n; |
| 53 |
|
struct stat sb; |
| 54 |
|
|
| 55 |
|
res = xmalloc(sizeof (struct parser_result)); |
| 56 |
|
CIRCLEQ_INIT(res); |
| 57 |
|
|
| 58 |
|
if (fstat(fd, &sb)) |
| 59 |
|
err(255, "cannot stat"); |
| 60 |
|
|
| 61 |
|
buf = mmap(NULL, (len = sb.st_size), PROT_READ, MAP_FILE, fd, 0); |
| 62 |
|
if (buf == MAP_FAILED) |
| 63 |
|
err(255, "cannot mmap %zu bytes", len); |
| 64 |
|
|