- memset(&ps, 0, sizeof(struct manpaths));
- manpath_manconf(&ps, "etc/catman.conf");
-
- if (vol >= (unsigned int)ps.sz) {
- resp_error400();
- goto out;
- }
-
- sz = strlcpy(file, ps.paths[vol], MAXPATHLEN);
- assert(sz < MAXPATHLEN);
- strlcat(file, "/", MAXPATHLEN);
- strlcat(file, MANDOC_IDX, MAXPATHLEN);
-
- /* Open the index recno(3) database. */
-
- idx = dbopen(file, O_RDONLY, 0, DB_RECNO, NULL);
- if (NULL == idx) {
- perror(file);
- resp_baddb();
- goto out;
- }
-
- key.data = &rec;
- key.size = 4;
-
- if (0 != (rc = (*idx->get)(idx, &key, &val, 0))) {
- rc < 0 ? resp_baddb() : resp_error400();
- goto out;
- } else if (0 == val.size) {
- resp_baddb();
- goto out;
- }
-
- cp = (char *)val.data;
- catm = 'c' == *cp++;
-
- if (NULL == memchr(cp, '\0', val.size - 1))
- resp_baddb();
- else {
- file[(int)sz] = '\0';
- strlcat(file, "/", MAXPATHLEN);
- strlcat(file, cp, MAXPATHLEN);
- if (catm)
- catman(req, file);
- else
- format(req, file);
- }
-out:
- if (idx)
- (*idx->close)(idx);
- manpath_free(&ps);