summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--util.c19
-rw-r--r--util.h10
2 files changed, 29 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;
+}
diff --git a/util.h b/util.h
index 4542a46..1a34fba 100644
--- a/util.h
+++ b/util.h
@@ -264,4 +264,14 @@ size_t xread(int fd, void *buf, size_t nbytes);
*/
size_t xwrite(int fd, const void *buf, size_t nbytes);
+/**
+ * Wrapper for confstr() that allocates with malloc().
+ *
+ * @param name
+ * The ID of the confstr to look up.
+ * @return
+ * The value of the confstr, or NULL on failure.
+ */
+char *xconfstr(int name);
+
#endif // BFS_UTIL_H