summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-01-07 09:10:45 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-01-07 09:10:45 +0000
commit7f0a4e00d6451a92f201f80bd28775fd13ae8424 (patch)
tree260649bccc80bde1d9a0c1597bf29317f2ebe76e
parent99897a99a694bfd305103c4a86567186e8baa884 (diff)
downloadmandoc-7f0a4e00d6451a92f201f80bd28775fd13ae8424.tar.gz
Cache the result of uname(3) such that we don't need to call it
over and over again for each manual; found with gprof(1). Speeds up mandocdb(8) -Q by 3%, now at 39.5% of makewhatis(8).
-rw-r--r--mdoc_validate.c51
1 files changed, 22 insertions, 29 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 9f6e736f..4e58bde0 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -2348,12 +2348,13 @@ post_bx(POST_ARGS)
static int
post_os(POST_ARGS)
{
- struct mdoc_node *n;
char buf[BUFSIZ];
- int c;
#ifndef OSNAME
struct utsname utsname;
+ static char *defbuf;
#endif
+ struct mdoc_node *n;
+ int c;
n = mdoc->last;
@@ -2376,39 +2377,31 @@ post_os(POST_ARGS)
assert(c);
- if ('\0' == buf[0]) {
- if (mdoc->defos) {
- mdoc->meta.os = mandoc_strdup(mdoc->defos);
- return(1);
- }
+ if ('\0' != *buf) {
+ mdoc->meta.os = mandoc_strdup(buf);
+ return(1);
+ }
+
+ if (mdoc->defos) {
+ mdoc->meta.os = mandoc_strdup(mdoc->defos);
+ return(1);
+ }
+
#ifdef OSNAME
- if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) {
- mdoc_nmsg(mdoc, n, MANDOCERR_MEM);
- return(0);
- }
+ mdoc->meta.os = mandoc_strdup(OSNAME);
#else /*!OSNAME */
+ if (NULL == defbuf) {
if (-1 == uname(&utsname)) {
mdoc_nmsg(mdoc, n, MANDOCERR_UNAME);
- mdoc->meta.os = mandoc_strdup("UNKNOWN");
- return(post_prol(mdoc));
- }
-
- if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) {
- mdoc_nmsg(mdoc, n, MANDOCERR_MEM);
- return(0);
- }
- if (strlcat(buf, " ", BUFSIZ) >= BUFSIZ) {
- mdoc_nmsg(mdoc, n, MANDOCERR_MEM);
- return(0);
+ defbuf = mandoc_strdup("UNKNOWN");
+ } else if (-1 == asprintf(&defbuf, "%s %s",
+ utsname.sysname, utsname.release)) {
+ perror(NULL);
+ exit((int)MANDOCLEVEL_SYSERR);
}
- if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) {
- mdoc_nmsg(mdoc, n, MANDOCERR_MEM);
- return(0);
- }
-#endif /*!OSNAME*/
}
-
- mdoc->meta.os = mandoc_strdup(buf);
+ mdoc->meta.os = mandoc_strdup(defbuf);
+#endif /*!OSNAME*/
return(1);
}