Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: libsbutil/
Date: Mon, 25 Feb 2013 04:08:17
Message-Id: 1361765105.f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef.vapier@gentoo
1 commit: f0dbd58bcb7b20ef681e7635f9d4b580816ad5ef
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Thu Dec 27 03:47:11 2012 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Mon Feb 25 04:05:05 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=f0dbd58b
7
8 environ: merge is_env_{on,off} into a single file
9
10 Start a centralized place for environment related helper funcs.
11
12 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
13
14 ---
15 libsbutil/Makefile.am | 3 +--
16 libsbutil/environment.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
17 libsbutil/is_env_off.c | 22 ----------------------
18 libsbutil/is_env_on.c | 22 ----------------------
19 4 files changed, 46 insertions(+), 46 deletions(-)
20
21 diff --git a/libsbutil/Makefile.am b/libsbutil/Makefile.am
22 index f1fed76..39a5ab6 100644
23 --- a/libsbutil/Makefile.am
24 +++ b/libsbutil/Makefile.am
25 @@ -18,8 +18,7 @@ libsbutil_la_SOURCES = \
26 get_sandbox_rc.c \
27 get_sandbox_log.c \
28 get_tmp_dir.c \
29 - is_env_on.c \
30 - is_env_off.c \
31 + environment.c \
32 sb_backtrace.c \
33 sb_efuncs.c \
34 sb_gdb.c \
35
36 diff --git a/libsbutil/environment.c b/libsbutil/environment.c
37 new file mode 100644
38 index 0000000..b24189f
39 --- /dev/null
40 +++ b/libsbutil/environment.c
41 @@ -0,0 +1,45 @@
42 +/*
43 + * environment.c
44 + *
45 + * Environment utility functions.
46 + *
47 + * Copyright 1999-2012 Gentoo Foundation
48 + * Licensed under the GPL-2
49 + */
50 +
51 +#include "headers.h"
52 +#include "sbutil.h"
53 +
54 +static bool env_is_in(const char *env, const char *values[])
55 +{
56 + size_t i = 0;
57 + const char *val;
58 +
59 + if (unlikely(!env))
60 + return false;
61 + val = getenv(env);
62 + if (unlikely(!val))
63 + return false;
64 +
65 + while (values[i])
66 + if (!strcasecmp(val, values[i++]))
67 + return true;
68 +
69 + return false;
70 +}
71 +
72 +bool is_env_on(const char *env)
73 +{
74 + static const char *values[] = {
75 + "1", "true", "yes", NULL,
76 + };
77 + return env_is_in(env, values);
78 +}
79 +
80 +bool is_env_off(const char *env)
81 +{
82 + static const char *values[] = {
83 + "0", "false", "no", NULL,
84 + };
85 + return env_is_in(env, values);
86 +}
87
88 diff --git a/libsbutil/is_env_off.c b/libsbutil/is_env_off.c
89 deleted file mode 100644
90 index 3536ee7..0000000
91 --- a/libsbutil/is_env_off.c
92 +++ /dev/null
93 @@ -1,22 +0,0 @@
94 -/*
95 - * is_env_off.c
96 - *
97 - * Util functions.
98 - *
99 - * Copyright 1999-2008 Gentoo Foundation
100 - * Licensed under the GPL-2
101 - */
102 -
103 -#include "headers.h"
104 -#include "sbutil.h"
105 -
106 -bool is_env_off (const char *env)
107 -{
108 - if ((NULL != env) && (NULL != getenv(env)) &&
109 - ((0 == strncasecmp(getenv(env), "0", 1)) ||
110 - (0 == strncasecmp(getenv(env), "false", 5)) ||
111 - (0 == strncasecmp(getenv(env), "no", 2))))
112 - return true;
113 -
114 - return false;
115 -}
116
117 diff --git a/libsbutil/is_env_on.c b/libsbutil/is_env_on.c
118 deleted file mode 100644
119 index 18a8cc0..0000000
120 --- a/libsbutil/is_env_on.c
121 +++ /dev/null
122 @@ -1,22 +0,0 @@
123 -/*
124 - * is_env_on.c
125 - *
126 - * Util functions.
127 - *
128 - * Copyright 1999-2008 Gentoo Foundation
129 - * Licensed under the GPL-2
130 - */
131 -
132 -#include "headers.h"
133 -#include "sbutil.h"
134 -
135 -bool is_env_on (const char *env)
136 -{
137 - if ((NULL != env) && (NULL != getenv(env)) &&
138 - ((0 == strncasecmp(getenv(env), "1", 1)) ||
139 - (0 == strncasecmp(getenv(env), "true", 4)) ||
140 - (0 == strncasecmp(getenv(env), "yes", 3))))
141 - return true;
142 -
143 - return false;
144 -}