[BACK]Return to cgi.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/cgi.c between version 1.43 and 1.47

version 1.43, 2012/03/25 00:46:39 version 1.47, 2014/01/05 20:41:04
Line 18 
Line 18 
 #include "config.h"  #include "config.h"
 #endif  #endif
   
 #include <sys/param.h>  
 #include <sys/wait.h>  #include <sys/wait.h>
   
 #include <assert.h>  #include <assert.h>
Line 35 
Line 34 
 #include <string.h>  #include <string.h>
 #include <unistd.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 "apropos_db.h"
 #include "mandoc.h"  #include "mandoc.h"
 #include "mdoc.h"  #include "mdoc.h"
Line 43 
Line 49 
 #include "manpath.h"  #include "manpath.h"
 #include "mandocdb.h"  #include "mandocdb.h"
   
 #ifdef __linux__  #if defined(__linux__) || defined(__sun)
 # include <db_185.h>  # include <db_185.h>
 #else  #else
 # include <db.h>  # include <db.h>
Line 726  format(const struct req *req, const char *file)
Line 732  format(const struct req *req, const char *file)
         struct man      *man;          struct man      *man;
         void            *vp;          void            *vp;
         enum mandoclevel rc;          enum mandoclevel rc;
         char             opts[MAXPATHLEN + 128];          char             opts[PATH_MAX + 128];
   
         if (-1 == (fd = open(file, O_RDONLY, 0))) {          if (-1 == (fd = open(file, O_RDONLY, 0))) {
                 resp_baddb();                  resp_baddb();
                 return;                  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);          rc = mparse_readfd(mp, fd, file);
         close(fd);          close(fd);
   
Line 777  pg_show(const struct req *req, char *path)
Line 783  pg_show(const struct req *req, char *path)
         struct manpaths  ps;          struct manpaths  ps;
         size_t           sz;          size_t           sz;
         char            *sub;          char            *sub;
         char             file[MAXPATHLEN];          char             file[PATH_MAX];
         const char      *cp;          const char      *cp;
         int              rc, catm;          int              rc, catm;
         unsigned int     vol, rec, mr;          unsigned int     vol, rec, mr;
Line 831  pg_show(const struct req *req, char *path)
Line 837  pg_show(const struct req *req, char *path)
                 goto out;                  goto out;
         }          }
   
         sz = strlcpy(file, ps.paths[vol], MAXPATHLEN);          sz = strlcpy(file, ps.paths[vol], PATH_MAX);
         assert(sz < MAXPATHLEN);          assert(sz < PATH_MAX);
         strlcat(file, "/", MAXPATHLEN);          strlcat(file, "/", PATH_MAX);
         strlcat(file, MANDOC_IDX, MAXPATHLEN);          strlcat(file, MANDOC_IDX, PATH_MAX);
   
         /* Open the index recno(3) database. */          /* Open the index recno(3) database. */
   
Line 863  pg_show(const struct req *req, char *path)
Line 869  pg_show(const struct req *req, char *path)
                 resp_baddb();                  resp_baddb();
         else {          else {
                 file[(int)sz] = '\0';                  file[(int)sz] = '\0';
                 strlcat(file, "/", MAXPATHLEN);                  strlcat(file, "/", PATH_MAX);
                 strlcat(file, cp, MAXPATHLEN);                  strlcat(file, cp, PATH_MAX);
                 if (catm)                  if (catm)
                         catman(req, file);                          catman(req, file);
                 else                  else
Line 973  int
Line 979  int
 main(void)  main(void)
 {  {
         int              i;          int              i;
         char             buf[MAXPATHLEN];          char             buf[PATH_MAX];
         DIR             *cwd;          DIR             *cwd;
         struct req       req;          struct req       req;
         char            *p, *path, *subpath;          char            *p, *path, *subpath;
Line 1010  main(void)
Line 1016  main(void)
   
         memset(&req, 0, sizeof(struct req));          memset(&req, 0, sizeof(struct req));
   
         strlcpy(buf, ".", MAXPATHLEN);          strlcpy(buf, ".", PATH_MAX);
         pathgen(cwd, buf, &req);          pathgen(cwd, buf, &req);
         closedir(cwd);          closedir(cwd);
   
Line 1098  static int
Line 1104  static int
 pathstop(DIR *dir)  pathstop(DIR *dir)
 {  {
         struct dirent   *d;          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)                  if (DT_REG == d->d_type)
   #endif
                         if (0 == strcmp(d->d_name, "catman.conf"))                          if (0 == strcmp(d->d_name, "catman.conf"))
                                 return(1);                                  return(1);
     }
   
         return(0);          return(0);
 }  }
Line 1119  pathgen(DIR *dir, char *path, struct req *req)
Line 1134  pathgen(DIR *dir, char *path, struct req *req)
         DIR             *cd;          DIR             *cd;
         int              rc;          int              rc;
         size_t           sz, ssz;          size_t           sz, ssz;
   #if defined(__sun)
           struct stat      sb;
   #endif
   
         sz = strlcat(path, "/", MAXPATHLEN);          sz = strlcat(path, "/", PATH_MAX);
         if (sz >= MAXPATHLEN) {          if (sz >= PATH_MAX) {
                 fprintf(stderr, "%s: Path too long", path);                  fprintf(stderr, "%s: Path too long", path);
                 return;                  return;
         }          }
Line 1134  pathgen(DIR *dir, char *path, struct req *req)
Line 1152  pathgen(DIR *dir, char *path, struct req *req)
   
         rc = 0;          rc = 0;
         while (0 == rc && NULL != (d = readdir(dir))) {          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;                          continue;
   
                 path[(int)sz] = '\0';                  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);                          fprintf(stderr, "%s: Path too long", path);
                         return;                          return;
                 } else if (NULL == (cd = opendir(path))) {                  } else if (NULL == (cd = opendir(path))) {
Line 1183  pathgen(DIR *dir, char *path, struct req *req)
Line 1207  pathgen(DIR *dir, char *path, struct req *req)
   
         rewinddir(dir);          rewinddir(dir);
         while (NULL != (d = readdir(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;                          continue;
   
                 path[(int)sz] = '\0';                  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);                          fprintf(stderr, "%s: Path too long", path);
                         return;                          return;
                 } else if (NULL == (cd = opendir(path))) {                  } else if (NULL == (cd = opendir(path))) {

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.47

CVSweb