enum mandoclevel mparse_readmem(struct mparse *curp, void *buf, size_t len, const char *file) { struct buf blk; blk.buf = buf; blk.sz = len; mparse_parse_buffer(curp, blk, file); return curp->file_status; }
/* * Read the whole file into memory and call the parsers. * Called recursively when an .so request is encountered. */ enum mandoclevel mparse_readfd(struct mparse *curp, int fd, const char *file) { struct buf blk; int with_mmap; int save_filenc; if (read_whole_file(curp, file, fd, &blk, &with_mmap)) { save_filenc = curp->filenc; curp->filenc = curp->options & (MPARSE_UTF8 | MPARSE_LATIN1); mparse_parse_buffer(curp, blk, file); curp->filenc = save_filenc; #if HAVE_MMAP if (with_mmap) munmap(blk.buf, blk.sz); else #endif free(blk.buf); } return curp->file_status; }
enum mandoclevel mparse_readfd(struct mparse *curp, int fd, const char *file) { struct buf blk; int with_mmap; if (-1 == fd && -1 == (fd = open(file, O_RDONLY, 0))) { curp->file_status = MANDOCLEVEL_SYSERR; if (curp->mmsg) (*curp->mmsg)(MANDOCERR_SYSOPEN, curp->file_status, file, 0, 0, strerror(errno)); goto out; } /* * Run for each opened file; may be called more than once for * each full parse sequence if the opened file is nested (i.e., * from `so'). Simply sucks in the whole file and moves into * the parse phase for the file. */ if ( ! read_whole_file(curp, file, fd, &blk, &with_mmap)) goto out; mparse_parse_buffer(curp, blk, file); #ifdef HAVE_MMAP if (with_mmap) munmap(blk.buf, blk.sz); else #endif free(blk.buf); if (STDIN_FILENO != fd && -1 == close(fd)) perror(file); out: return(curp->file_status); }