summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2019-01-26 14:49:46 +0000
committerColin Watson <cjwatson@debian.org>2019-01-26 14:49:46 +0000
commit449ac91e70ad7ff7583eaab5b000de3563148f45 (patch)
treec96cbc907afa13c26f65f9cd45c049b62b7dd453 /lib
parent2beae0a82b4a70ddc565960840ebe53142c8746b (diff)
Use bool type where appropriate
Now that we're using <stdbool.h> anyway due to gl_list (with Gnulib providing <stdbool.h> if necessary), it makes sense to use it for our own functions that have essentially boolean semantics. * lib/encodings.c (compatible_encodings, is_roff_device): Return bool. * lib/pathsearch.c (pathsearch, pathsearch_executable, directory_on_path): Likewise. * lib/sandbox.c (search_ld_preload, can_load_seccomp): Likewise. * lib/security.c (running_setuid): Likewise. * lib/wordfnmatch.c (word_fnmatch): Likewise. Update all callers. * src/check_mandirs.c (sanity_check_db): Likewise. * src/man.c (duplicate_candidates): Likewise. * src/manp.c (is_global_mandir): Likewise. Update all callers. * src/whatis.c (suitable_manpath, match): Likewise. (any_set, all_set): Likewise. Update all callers. * lib/encodings.h (is_roff_device): Update prototype. * lib/pathsearch.h (pathsearch_executable, directory_on_path): Likewise. * lib/security.h (running_setuid): Likewise. * lib/wordfnmatch.h (word_fnmatch): Likewise. * src/manp.h (is_global_mandir): Likewise. * src/mandb.c (mandb, process_manpath): Change global_manpath parameter type to bool.
Diffstat (limited to 'lib')
-rw-r--r--lib/encodings.c21
-rw-r--r--lib/encodings.h4
-rw-r--r--lib/pathsearch.c25
-rw-r--r--lib/pathsearch.h12
-rw-r--r--lib/sandbox.c21
-rw-r--r--lib/security.c5
-rw-r--r--lib/security.h3
-rw-r--r--lib/wordfnmatch.c7
-rw-r--r--lib/wordfnmatch.h4
9 files changed, 57 insertions, 45 deletions
diff --git a/lib/encodings.c b/lib/encodings.c
index ec8fb6bc..c033543f 100644
--- a/lib/encodings.c
+++ b/lib/encodings.c
@@ -25,6 +25,7 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -640,27 +641,27 @@ out:
/* Can we take this input encoding and produce this output encoding, perhaps
* with the help of some iconv pipes? */
-static int compatible_encodings (const char *input, const char *output)
+static bool compatible_encodings (const char *input, const char *output)
{
if (STREQ (input, output))
- return 1;
+ return true;
/* If the input is ASCII, recoding should be easy. Try it. */
if (STREQ (input, "ANSI_X3.4-1968"))
- return 1;
+ return true;
/* If the input is UTF-8, it's either a simple recoding of whatever
* we want or else it probably won't work at all no matter what we
* do. We might as well try it for now.
*/
if (STREQ (input, "UTF-8"))
- return 1;
+ return true;
/* If the output is ASCII, this is probably because the caller
* explicitly asked for it, so we have little choice but to try.
*/
if (STREQ (output, "ANSI_X3.4-1968"))
- return 1;
+ return true;
#ifdef MULTIBYTE_GROFF
/* Special case for some CJK UTF-8 locales, which take UTF-8 input
@@ -673,10 +674,10 @@ static int compatible_encodings (const char *input, const char *output)
STREQ (input, "EUC-KR") ||
STREQ (input, "EUC-TW")) &&
STREQ (output, "UTF-8"))
- return 1;
+ return true;
#endif /* MULTIBYTE_GROFF */
- return 0;
+ return false;
}
/* Return the default groff device for the given character set. This may be
@@ -723,16 +724,16 @@ const char *get_default_device (const char *charset_from_locale,
}
/* Is this a known *roff device name? */
-int is_roff_device (const char *device)
+bool is_roff_device (const char *device)
{
const struct device_entry *entry;
for (entry = device_table; entry->roff_device; ++entry) {
if (STREQ (entry->roff_device, device))
- return 1;
+ return true;
}
- return 0;
+ return false;
}
/* Find the input encoding expected by groff, and set the LESSCHARSET
diff --git a/lib/encodings.h b/lib/encodings.h
index 9967a895..b745dae1 100644
--- a/lib/encodings.h
+++ b/lib/encodings.h
@@ -20,6 +20,8 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdbool.h>
+
const char *get_groff_preconv (void);
char *get_page_encoding (const char *lang);
const char *get_source_encoding (const char *lang);
@@ -28,7 +30,7 @@ const char *get_locale_charset (void);
char *find_charset_locale (const char *charset);
const char *get_default_device (const char *locale_charset,
const char *source_encoding);
-int is_roff_device (const char *device);
+bool is_roff_device (const char *device);
const char *get_roff_encoding (const char *device,
const char *source_encoding);
const char *get_output_encoding (const char *device);
diff --git a/lib/pathsearch.c b/lib/pathsearch.c
index 402f7d1a..c733c3a7 100644
--- a/lib/pathsearch.c
+++ b/lib/pathsearch.c
@@ -24,6 +24,7 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
@@ -37,26 +38,26 @@
#include "manconfig.h"
#include "pathsearch.h"
-static int pathsearch (const char *name, const mode_t bits)
+static bool pathsearch (const char *name, const mode_t bits)
{
char *cwd = NULL;
char *path = getenv ("PATH");
char *pathtok;
const char *element;
struct stat st;
- int ret = 0;
+ bool ret = false;
if (!path)
/* Eh? Oh well. */
- return 0;
+ return false;
if (strchr (name, '/')) {
/* Qualified name; look directly. */
if (stat (name, &st) == -1)
- return 0;
+ return false;
if (S_ISREG (st.st_mode) && (st.st_mode & bits))
- return 1;
- return 0;
+ return true;
+ return false;
}
pathtok = path = xstrdup (path);
@@ -81,7 +82,7 @@ static int pathsearch (const char *name, const mode_t bits)
free (filename);
if (S_ISREG (st.st_mode) && (st.st_mode & bits)) {
- ret = 1;
+ ret = true;
break;
}
}
@@ -91,22 +92,22 @@ static int pathsearch (const char *name, const mode_t bits)
return ret;
}
-int pathsearch_executable (const char *name)
+bool pathsearch_executable (const char *name)
{
return pathsearch (name, 0111);
}
-int directory_on_path (const char *dir)
+bool directory_on_path (const char *dir)
{
char *cwd = NULL;
char *path = getenv ("PATH");
char *pathtok;
const char *element;
- int ret = 0;
+ bool ret = false;
if (!path)
/* Eh? Oh well. */
- return 0;
+ return false;
pathtok = path = xstrdup (path);
@@ -119,7 +120,7 @@ int directory_on_path (const char *dir)
}
if (STREQ (element, dir)) {
- ret = 1;
+ ret = true;
break;
}
}
diff --git a/lib/pathsearch.h b/lib/pathsearch.h
index 970fbeef..d9b024d1 100644
--- a/lib/pathsearch.h
+++ b/lib/pathsearch.h
@@ -23,12 +23,14 @@
#ifndef PATHSEARCH_H
#define PATHSEARCH_H
-/* Return non-zero if NAME is found as an executable regular file on the
- * $PATH.
+#include <stdbool.h>
+
+/* Return true if NAME is found as an executable regular file on the $PATH,
+ * otherwise false.
*/
-int pathsearch_executable (const char *name);
+bool pathsearch_executable (const char *name);
-/* Return non-zero if DIR matches an entry on the $PATH. */
-int directory_on_path (const char *dir);
+/* Return true if DIR matches an entry on the $PATH, otherwise false. */
+bool directory_on_path (const char *dir);
#endif /* PATHSEARCH_H */
diff --git a/lib/sandbox.c b/lib/sandbox.c
index c097482b..204bda4c 100644
--- a/lib/sandbox.c
+++ b/lib/sandbox.c
@@ -43,6 +43,7 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include <stdbool.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -86,14 +87,14 @@ static void gripe_seccomp_filter_unavailable (void)
"CONFIG_SECCOMP_FILTER\n");
}
-static int search_ld_preload (const char *needle)
+static bool search_ld_preload (const char *needle)
{
const char *ld_preload_env;
static char *ld_preload_file = NULL;
ld_preload_env = getenv ("LD_PRELOAD");
if (ld_preload_env && strstr (ld_preload_env, needle) != NULL)
- return 1;
+ return true;
if (!ld_preload_file) {
int fd;
@@ -118,9 +119,9 @@ static int search_ld_preload (const char *needle)
* for you.
*/
if (strstr (ld_preload_file, needle) != NULL)
- return 1;
+ return true;
- return 0;
+ return false;
}
/* Can we load a seccomp filter into this process?
@@ -128,20 +129,20 @@ static int search_ld_preload (const char *needle)
* This guard allows us to call sandbox_load in code paths that may
* conditionally do so again.
*/
-static int can_load_seccomp (void)
+static bool can_load_seccomp (void)
{
const char *man_disable_seccomp;
int seccomp_status;
if (seccomp_filter_unavailable) {
gripe_seccomp_filter_unavailable ();
- return 0;
+ return false;
}
man_disable_seccomp = getenv ("MAN_DISABLE_SECCOMP");
if (man_disable_seccomp && *man_disable_seccomp) {
debug ("seccomp filter disabled by user request\n");
- return 0;
+ return false;
}
/* Valgrind causes the child process to make some system calls we
@@ -158,13 +159,13 @@ static int can_load_seccomp (void)
if (search_ld_preload ("/vgpreload")) {
debug ("seccomp filter disabled while running under "
"Valgrind\n");
- return 0;
+ return false;
}
seccomp_status = prctl (PR_GET_SECCOMP);
if (seccomp_status == 0)
- return 1;
+ return true;
if (seccomp_status == -1) {
if (errno == EINVAL)
@@ -177,7 +178,7 @@ static int can_load_seccomp (void)
else
debug ("unknown return value from PR_GET_SECCOMP: %d\n",
seccomp_status);
- return 0;
+ return false;
}
#endif /* HAVE_LIBSECCOMP */
diff --git a/lib/security.c b/lib/security.c
index e739d503..7d66eaf4 100644
--- a/lib/security.c
+++ b/lib/security.c
@@ -27,6 +27,7 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -94,12 +95,12 @@ void init_security (void)
#endif /* MAN_OWNER */
}
-int running_setuid (void)
+bool running_setuid (void)
{
#ifdef MAN_OWNER
return ruid != euid;
#else /* !MAN_OWNER */
- return 0;
+ return false;
#endif
}
diff --git a/lib/security.h b/lib/security.h
index 63ef5332..fdfadc4d 100644
--- a/lib/security.h
+++ b/lib/security.h
@@ -22,6 +22,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdbool.h>
#include <pwd.h>
/* security.c */
@@ -29,7 +30,7 @@ extern void drop_effective_privs (void);
extern void regain_effective_privs (void);
extern void drop_privs (void *data);
extern void init_security (void);
-extern int running_setuid (void);
+extern bool running_setuid (void);
#ifdef MAN_OWNER
extern struct passwd *get_man_owner (void);
#endif /* MAN_OWNER */
diff --git a/lib/wordfnmatch.c b/lib/wordfnmatch.c
index 0ec26500..73fad8e1 100644
--- a/lib/wordfnmatch.c
+++ b/lib/wordfnmatch.c
@@ -24,6 +24,7 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include <stdbool.h>
#include <stdlib.h>
#include <ctype.h>
@@ -37,7 +38,7 @@
/* TODO: How on earth do we allow multiple-word matches without
* reimplementing fnmatch()?
*/
-int word_fnmatch (const char *lowpattern, const char *string)
+bool word_fnmatch (const char *lowpattern, const char *string)
{
char *lowstring = lower (string);
char *begin = lowstring, *p;
@@ -53,12 +54,12 @@ int word_fnmatch (const char *lowpattern, const char *string)
*p = '\0';
if (fnmatch (lowpattern, begin, 0) == 0) {
free (lowstring);
- return 1;
+ return true;
}
begin = p + 1;
}
}
free (lowstring);
- return 0;
+ return false;
}
diff --git a/lib/wordfnmatch.h b/lib/wordfnmatch.h
index 0fc29f0c..82e7cf7b 100644
--- a/lib/wordfnmatch.h
+++ b/lib/wordfnmatch.h
@@ -20,4 +20,6 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-int word_fnmatch (const char *lowpattern, const char *string);
+#include <stdbool.h>
+
+bool word_fnmatch (const char *lowpattern, const char *string);