aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__prepare_parse.c
blob: 1cf86a4892e55609eacd8e5ea24d7b28beec37f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "parselib.h"

void __prepare_parse(const char* filename,struct state* s) /*EXTRACT_INCL*/{
  int fd;
  s->cur=0;
  if (s->buffirst) return;	/* already mapped */
  fd=open(filename,O_RDONLY);
  if (fd>=0) {
    s->buflen=lseek(fd,0,SEEK_END);
    s->buffirst=mmap(0,s->buflen,PROT_READ,MAP_PRIVATE,fd,0);
    if (s->buffirst==(const char*)-1)
      s->buffirst=0;
    close(fd);
  } else {
    s->buflen=0;
    s->buffirst=0;
  }
}