-/* $Id: cgi.c,v 1.43 2012/03/25 00:46:39 kristaps Exp $ */
+/* $Id: cgi.c,v 1.47 2014/01/05 20:41:04 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
*
#include "config.h"
#endif
-#include <sys/param.h>
#include <sys/wait.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
+#if defined(__sun)
+/* for stat() */
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+
#include "apropos_db.h"
#include "mandoc.h"
#include "mdoc.h"
#include "manpath.h"
#include "mandocdb.h"
-#ifdef __linux__
+#if defined(__linux__) || defined(__sun)
# include <db_185.h>
#else
# include <db.h>
struct man *man;
void *vp;
enum mandoclevel rc;
- char opts[MAXPATHLEN + 128];
+ char opts[PATH_MAX + 128];
if (-1 == (fd = open(file, O_RDONLY, 0))) {
resp_baddb();
return;
}
- mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);
+ mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, 0);
rc = mparse_readfd(mp, fd, file);
close(fd);
struct manpaths ps;
size_t sz;
char *sub;
- char file[MAXPATHLEN];
+ char file[PATH_MAX];
const char *cp;
int rc, catm;
unsigned int vol, rec, mr;
goto out;
}
- sz = strlcpy(file, ps.paths[vol], MAXPATHLEN);
- assert(sz < MAXPATHLEN);
- strlcat(file, "/", MAXPATHLEN);
- strlcat(file, MANDOC_IDX, MAXPATHLEN);
+ sz = strlcpy(file, ps.paths[vol], PATH_MAX);
+ assert(sz < PATH_MAX);
+ strlcat(file, "/", PATH_MAX);
+ strlcat(file, MANDOC_IDX, PATH_MAX);
/* Open the index recno(3) database. */
resp_baddb();
else {
file[(int)sz] = '\0';
- strlcat(file, "/", MAXPATHLEN);
- strlcat(file, cp, MAXPATHLEN);
+ strlcat(file, "/", PATH_MAX);
+ strlcat(file, cp, PATH_MAX);
if (catm)
catman(req, file);
else
main(void)
{
int i;
- char buf[MAXPATHLEN];
+ char buf[PATH_MAX];
DIR *cwd;
struct req req;
char *p, *path, *subpath;
memset(&req, 0, sizeof(struct req));
- strlcpy(buf, ".", MAXPATHLEN);
+ strlcpy(buf, ".", PATH_MAX);
pathgen(cwd, buf, &req);
closedir(cwd);
pathstop(DIR *dir)
{
struct dirent *d;
+#if defined(__sun)
+ struct stat sb;
+#endif
- while (NULL != (d = readdir(dir)))
+ while (NULL != (d = readdir(dir))) {
+#if defined(__sun)
+ stat(d->d_name, &sb);
+ if (S_IFREG & sb.st_mode)
+#else
if (DT_REG == d->d_type)
+#endif
if (0 == strcmp(d->d_name, "catman.conf"))
return(1);
+ }
return(0);
}
DIR *cd;
int rc;
size_t sz, ssz;
+#if defined(__sun)
+ struct stat sb;
+#endif
- sz = strlcat(path, "/", MAXPATHLEN);
- if (sz >= MAXPATHLEN) {
+ sz = strlcat(path, "/", PATH_MAX);
+ if (sz >= PATH_MAX) {
fprintf(stderr, "%s: Path too long", path);
return;
}
rc = 0;
while (0 == rc && NULL != (d = readdir(dir))) {
- if (DT_DIR != d->d_type || strcmp(d->d_name, "etc"))
+#if defined(__sun)
+ stat(d->d_name, &sb);
+ if (!(S_IFDIR & sb.st_mode)
+#else
+ if (DT_DIR != d->d_type
+#endif
+ || strcmp(d->d_name, "etc"))
continue;
path[(int)sz] = '\0';
- ssz = strlcat(path, d->d_name, MAXPATHLEN);
+ ssz = strlcat(path, d->d_name, PATH_MAX);
- if (ssz >= MAXPATHLEN) {
+ if (ssz >= PATH_MAX) {
fprintf(stderr, "%s: Path too long", path);
return;
} else if (NULL == (cd = opendir(path))) {
rewinddir(dir);
while (NULL != (d = readdir(dir))) {
- if (DT_DIR != d->d_type || '.' == d->d_name[0])
+#if defined(__sun)
+ stat(d->d_name, &sb);
+ if (!(S_IFDIR & sb.st_mode)
+#else
+ if (DT_DIR != d->d_type
+#endif
+ || '.' == d->d_name[0])
continue;
path[(int)sz] = '\0';
- ssz = strlcat(path, d->d_name, MAXPATHLEN);
+ ssz = strlcat(path, d->d_name, PATH_MAX);
- if (ssz >= MAXPATHLEN) {
+ if (ssz >= PATH_MAX) {
fprintf(stderr, "%s: Path too long", path);
return;
} else if (NULL == (cd = opendir(path))) {