Changeset 3452

Show
Ignore:
Timestamp:
08/09/07 13:22:16 (1 year ago)
Author:
tg
Message:

sometimes, the best ideas come on the way to work
after mmapping the file, make a local NUL-terminated copy (i.e. read-writable)
this will greatly simplify the following algorithm.

Files:

Legend:

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

    r3449 r3452  
    9898                err(255, "cannot stat"); 
    9999 
    100         buf = mmap(NULL, (len = sb.st_size), PROT_READ, MAP_FILE, fd, 0); 
    101         if (buf == MAP_FAILED) 
     100        /* slurp whole file into mapped memory */ 
     101        if ((cp = mmap(NULL, (len = sb.st_size), PROT_READ, MAP_FILE, fd, 0)) 
     102            == MAP_FAILED) 
    102103                err(255, "cannot mmap %zu bytes", len); 
     104        /* make a nice NUL-terminated copy (malloc'd) */ 
     105        buf = str_nsave(cp, len); 
     106        if (munmap(cp, len)) 
     107                err(255, "cannot munmap"); 
     108        /* don't need the file any more */ 
     109        close(fd); 
    103110 
     111        /* now we can operate on the NUL-terminated R/W string “buf” */