Changeset 3446

Show
Ignore:
Timestamp:
08/08/07 16:55:33 (1 year ago)
Author:
tg
Message:

more, but I'm hungry now and unable to concentrate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/common-nfo/tools/nfotiser/parser.c

    r3444 r3446  
    3131 
    3232#include <sys/param.h> 
     33#include <sys/mman.h> 
     34#include <sys/stat.h> 
    3335 
    3436#include <err.h> 
     
    4143 
    4244#include "nfotiser.h" 
     45 
     46struct parser_result * 
     47nfo_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 
  • branches/common-nfo/tools/sqlite/dbif.h

    r3441 r3446  
    5050} while (0) 
    5151 
     52__BEGIN_DECLS 
    5253EXTERN int debug I__(0); 
    5354EXTERN sqlite3 *db I__(NULL); 
     
    7980#endif 
    8081#endif 
     82__END_DECLS 
     83 
     84/* useful stuff */ 
     85#define xmalloc(size) ({                                \ 
     86        void *xmalloc_ptr;                              \ 
     87        size_t xmalloc_sz = (size);                     \ 
     88                                                        \ 
     89        if ((xmalloc_ptr = malloc(xmalloc_sz)) == NULL) \ 
     90                err(255, "cannot allocate %zu bytes",   \ 
     91                    xmalloc_sz);                        \ 
     92        (xmalloc_ptr);                                  \ 
     93}) 
    8194 
    8295#endif