summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-06-13 15:51:43 -0400
committerTavian Barnes <tavianator@tavianator.com>2021-06-13 15:51:43 -0400
commit78e968dd789ca8d1cac8da3715352184bca2a188 (patch)
treeeca2d39ab8e7728891b18cc490692034c236a2a7 /util.c
parent7b5d98877622f2bea24c9dd745dfcf312df31a87 (diff)
downloadbfs-78e968dd789ca8d1cac8da3715352184bca2a188.tar.xz
util: New xconfstr() wrapper
Diffstat (limited to 'util.c')
-rw-r--r--util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/util.c b/util.c
index 19656e9..207e34d 100644
--- a/util.c
+++ b/util.c
@@ -414,3 +414,22 @@ size_t xwrite(int fd, const void *buf, size_t nbytes) {
return count;
}
+
+char *xconfstr(int name) {
+ size_t len = confstr(name, NULL, 0);
+ if (len == 0) {
+ return NULL;
+ }
+
+ char *str = malloc(len);
+ if (!str) {
+ return NULL;
+ }
+
+ if (confstr(name, str, len) != len) {
+ free(str);
+ return NULL;
+ }
+
+ return str;
+}