summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-10-08 01:10:22 +0100
committerColin Watson <cjwatson@debian.org>2022-10-08 01:10:23 +0100
commita9327d495b2e8dc3b555adf8b7579a4f85e56116 (patch)
tree941cde7fdc9ebabd7b6d716e87aedaee5feb7fcc /lib
parentf5f47aa0a2b05722c59c55ce31d411461f47e3c4 (diff)
Convert many more ints to bools
I don't expect this to make a significant runtime difference, but it makes some things easier to analyse visually. * lib/cleanup.c (do_cleanups_sigsafe): Change `in_sighandler` parameter type to bool. Update all callers. (push_cleanup): Change `handler_installed` local variable type to bool. * lib/cleanup.h (do_cleanups_sigsafe): Update prototype. * lib/compression.c (comp_info): Change `want_stem` parameter type to bool. Update all callers. * lib/compression.h (comp_info): Update prototype. * lib/sandbox.c (seccomp_filter_unavailable): Change type to bool. Update all references. (make_seccomp_filter): Change `permissive` parameter type to bool. Update all callers. (_sandbox_load): Likewise. * lib/util.c (remove_directory): Change `recurse` parameter type to bool. Update all callers. * lib/util.h (remove_directory): Update prototype. * libdb/db_gdbm.c (opening): Change type to bool. Update all references. * libdb/db_store.c (compare_ids): Change `promote_links` parameter type to bool. Update all callers. * libdb/db_storage.h (compare_ids): Update prototype. * src/catman.c (parse_for_sec): Change `message` local variable type to bool. (check_access): Change return type to bool. (purge_whatis): Change `cat` parameter type to bool. Update all callers. (check_multi_key): Change return type to bool. * src/descriptions.c (parse_descriptions): Change `seen_base` local variable type to bool. * src/globbing.c (look_for_file): Change `cat` parameter type to bool. Update all callers. * src/globbing.h (look_for_file): Update prototype. * src/lexgrog.l (fill_mode, waiting_for_quote): Change types to bool. Update all references. * src/man.c (skip, created_tmp_cat): Change types to bool. Update all references. (run_mandb): Change `create` parameter type to bool. Update all callers. (squeeze_blank_lines): Change `in_blank_line` and `got_blank_line` local variable types to bool. (display): Change `format` and `printed` local variable types to bool. (convert_name): Change `fsstnd` parameter type to bool. Update all callers. (add_candidate): Change `dupcand` local variable type to bool. (main): Change `maybe_section` local variable type to bool. * src/manp.c (add_sections): Change `user` parameter type to bool. Update all callers. (add_def): Likewise. (add_mandb_map): Likewise. (add_to_dirlist): Likewise. (read_config_file): Change `done` local variable type to bool. (get_manpath_from_path): Change `mandatory` parameter type to bool. Update all callers. * src/manp.h (get_manpath_from_path): Update prototype. * src/whatis.c (do_apropos): Change `matched` local variable type to bool. * src/zsoelim.l (no_newline): Change type to bool. Update all references. (zsoelim_open_file): Change return type to true. * src/zsoelim.h (zsoelim_open_file): Update prototype.
Diffstat (limited to 'lib')
-rw-r--r--lib/cleanup.c11
-rw-r--r--lib/cleanup.h4
-rw-r--r--lib/compression.c3
-rw-r--r--lib/compression.h4
-rw-r--r--lib/filenames.c2
-rw-r--r--lib/sandbox.c23
-rw-r--r--lib/util.c3
-rw-r--r--lib/util.h4
8 files changed, 32 insertions, 22 deletions
diff --git a/lib/cleanup.c b/lib/cleanup.c
index 65865dd8..42b603b0 100644
--- a/lib/cleanup.c
+++ b/lib/cleanup.c
@@ -23,6 +23,7 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h> /* SunOS's loosing assert.h needs it */
#include <assert.h>
@@ -55,7 +56,7 @@ sighandler (int signo)
struct sigaction act;
sigset_t set;
- do_cleanups_sigsafe (1);
+ do_cleanups_sigsafe (true);
/* set default signal action */
memset (&act, 0, sizeof act);
@@ -174,7 +175,7 @@ static unsigned tos = 0; /* top of stack, 0 <= tos <= nslots */
* called.
*/
void
-do_cleanups_sigsafe (int in_sighandler)
+do_cleanups_sigsafe (bool in_sighandler)
{
unsigned i;
@@ -190,7 +191,7 @@ do_cleanups_sigsafe (int in_sighandler)
void
do_cleanups (void)
{
- do_cleanups_sigsafe (0);
+ do_cleanups_sigsafe (false);
tos = 0;
nslots = 0;
free (stack);
@@ -207,14 +208,14 @@ do_cleanups (void)
int
push_cleanup (cleanup_fun fun, void *arg, int sigsafe)
{
- static int handler_installed = 0;
+ static bool handler_installed = false;
assert (tos <= nslots);
if (!handler_installed) {
if (atexit (do_cleanups))
return -1;
- handler_installed = 1;
+ handler_installed = true;
}
if (tos == nslots) {
diff --git a/lib/cleanup.h b/lib/cleanup.h
index 162249ce..5415b7f1 100644
--- a/lib/cleanup.h
+++ b/lib/cleanup.h
@@ -22,9 +22,11 @@
#ifndef _CLEANUP_H
#define _CLEANUP_H
+#include <stdbool.h>
+
typedef void (*cleanup_fun) (void *);
-extern void do_cleanups_sigsafe (int);
+extern void do_cleanups_sigsafe (bool);
extern void do_cleanups (void);
extern int push_cleanup (cleanup_fun, void *, int);
extern void pop_cleanup (cleanup_fun, void *);
diff --git a/lib/compression.c b/lib/compression.c
index 3f3205ab..fe4696c0 100644
--- a/lib/compression.c
+++ b/lib/compression.c
@@ -28,6 +28,7 @@
#endif /* HAVE_CONFIG_H */
#include <assert.h>
+#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>
@@ -128,7 +129,7 @@ struct compression comp_list[] = {
comp->ext = "gz";
comp->stem = "/usr/man/man1/foo.1";
*/
-struct compression *comp_info (const char *filename, int want_stem)
+struct compression *comp_info (const char *filename, bool want_stem)
{
const char *ext;
static struct compression hpux_comp =
diff --git a/lib/compression.h b/lib/compression.h
index 15df2dc2..52ede354 100644
--- a/lib/compression.h
+++ b/lib/compression.h
@@ -21,6 +21,8 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdbool.h>
+
struct compression {
/* The following are const because they should be pointers to parts
* of strings allocated elsewhere and should not be written through
@@ -36,5 +38,5 @@ struct compression {
extern struct compression comp_list[];
-extern struct compression *comp_info (const char *filename, int want_stem);
+extern struct compression *comp_info (const char *filename, bool want_stem);
extern struct compression *comp_file (const char *filename);
diff --git a/lib/filenames.c b/lib/filenames.c
index 026d942a..5e592c39 100644
--- a/lib/filenames.c
+++ b/lib/filenames.c
@@ -99,7 +99,7 @@ struct mandata *filename_info (const char *file, bool warn_if_bogus)
a missmatch between the section they are under and the
sectional part of their extension. */
- comp = comp_info (basename, 1);
+ comp = comp_info (basename, true);
if (comp) {
info->comp = xstrdup (comp->ext);
*(basename + strlen (comp->stem)) = '\0';
diff --git a/lib/sandbox.c b/lib/sandbox.c
index bfda5e30..f891e533 100644
--- a/lib/sandbox.c
+++ b/lib/sandbox.c
@@ -83,7 +83,7 @@ struct man_sandbox {
};
#ifdef HAVE_LIBSECCOMP
-static int seccomp_filter_unavailable = 0;
+static bool seccomp_filter_unavailable = false;
static void gripe_seccomp_filter_unavailable (void)
{
@@ -231,7 +231,7 @@ static bool can_load_seccomp (void)
* files. Confining these further requires additional tools that can do
* path-based filtering or similar, such as AppArmor.
*/
-static scmp_filter_ctx make_seccomp_filter (int permissive)
+static scmp_filter_ctx make_seccomp_filter (bool permissive)
{
scmp_filter_ctx ctx;
mode_t mode_mask = S_ISUID | S_ISGID | S_IXUSR | S_IXGRP | S_IXOTH;
@@ -244,7 +244,8 @@ static scmp_filter_ctx make_seccomp_filter (int permissive)
if (!can_load_seccomp ())
return NULL;
- debug ("initialising seccomp filter (permissive: %d)\n", permissive);
+ debug ("initialising seccomp filter (permissive: %d)\n",
+ (int) permissive);
ctx = seccomp_init (SCMP_ACT_ERRNO (ENOSYS));
if (!ctx)
fatal (errno, "can't initialise seccomp filter");
@@ -583,8 +584,8 @@ man_sandbox *sandbox_init (void)
man_sandbox *sandbox = XZALLOC (man_sandbox);
#ifdef HAVE_LIBSECCOMP
- sandbox->ctx = make_seccomp_filter (0);
- sandbox->permissive_ctx = make_seccomp_filter (1);
+ sandbox->ctx = make_seccomp_filter (false);
+ sandbox->permissive_ctx = make_seccomp_filter (true);
#else /* !HAVE_LIBSECCOMP */
sandbox->dummy = 0;
#endif /* HAVE_LIBSECCOMP */
@@ -593,7 +594,7 @@ man_sandbox *sandbox_init (void)
}
#ifdef HAVE_LIBSECCOMP
-static void _sandbox_load (man_sandbox *sandbox, int permissive) {
+static void _sandbox_load (man_sandbox *sandbox, bool permissive) {
if (can_load_seccomp ()) {
scmp_filter_ctx ctx;
@@ -604,7 +605,7 @@ static void _sandbox_load (man_sandbox *sandbox, int permissive) {
if (!ctx)
return;
debug ("loading seccomp filter (permissive: %d)\n",
- permissive);
+ (int) permissive);
if (seccomp_load (ctx) < 0) {
if (errno == EINVAL || errno == EFAULT) {
/* The kernel doesn't give us particularly
@@ -619,7 +620,7 @@ static void _sandbox_load (man_sandbox *sandbox, int permissive) {
*/
gripe_seccomp_filter_unavailable ();
/* Don't try this again. */
- seccomp_filter_unavailable = 1;
+ seccomp_filter_unavailable = true;
} else
fatal (errno, "can't load seccomp filter");
}
@@ -627,7 +628,7 @@ static void _sandbox_load (man_sandbox *sandbox, int permissive) {
}
#else /* !HAVE_LIBSECCOMP */
static void _sandbox_load (man_sandbox *sandbox MAYBE_UNUSED,
- int permissive MAYBE_UNUSED)
+ bool permissive MAYBE_UNUSED)
{
}
#endif /* HAVE_LIBSECCOMP */
@@ -637,7 +638,7 @@ void sandbox_load (void *data)
{
man_sandbox *sandbox = data;
- _sandbox_load (sandbox, 0);
+ _sandbox_load (sandbox, false);
}
/* Enter a sandbox for processing untrusted data, allowing limited file
@@ -647,7 +648,7 @@ void sandbox_load_permissive (void *data)
{
man_sandbox *sandbox = data;
- _sandbox_load (sandbox, 1);
+ _sandbox_load (sandbox, true);
}
/* Free a sandbox for processing untrusted data. */
diff --git a/lib/util.c b/lib/util.c
index c9c16d1b..28a4487b 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -36,6 +36,7 @@
#endif /* HAVE_CONFIG_H */
#include <assert.h>
+#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -154,7 +155,7 @@ char *escape_shell (const char *unesc)
/* Remove a directory and all files in it. Only recurse beyond that if
* RECURSE is set.
*/
-int remove_directory (const char *directory, int recurse)
+int remove_directory (const char *directory, bool recurse)
{
DIR *handle = opendir (directory);
struct dirent *entry;
diff --git a/lib/util.h b/lib/util.h
index 48c98440..aec8d179 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -22,10 +22,12 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdbool.h>
+
extern int is_changed (const char *fa, const char *fb);
extern int is_directory (const char *path);
extern char *escape_shell (const char *unesc);
-extern int remove_directory (const char *directory, int recurse);
+extern int remove_directory (const char *directory, bool recurse);
extern char *trim_spaces (const char *s);
extern char *lang_dir (const char *filename);
extern void init_locale (void);