summaryrefslogtreecommitdiffstats
path: root/src/bfstd.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/bfstd.h')
-rw-r--r--src/bfstd.h38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/bfstd.h b/src/bfstd.h
index f5d8622..557f253 100644
--- a/src/bfstd.h
+++ b/src/bfstd.h
@@ -8,8 +8,8 @@
#ifndef BFS_BFSTD_H
#define BFS_BFSTD_H
-#include "prelude.h"
-#include "sanity.h"
+#include "bfs.h"
+
#include <stddef.h>
#include <ctype.h>
@@ -18,7 +18,7 @@
* Work around https://github.com/llvm/llvm-project/issues/65532 by forcing a
* function, not a macro, to be called.
*/
-#if __FreeBSD__ && SANITIZE_MEMORY
+#if __FreeBSD__ && __SANITIZE_MEMORY__
# define BFS_INTERCEPT(fn) (fn)
#else
# define BFS_INTERCEPT(fn) fn
@@ -179,6 +179,23 @@ int open_cterm(int flags);
const char *xgetprogname(void);
/**
+ * Wrapper for strtoll() that forbids leading spaces.
+ *
+ * @param str
+ * The string to parse.
+ * @param end
+ * If non-NULL, will hold a pointer to the first invalid character.
+ * If NULL, the entire string must be valid.
+ * @param base
+ * The base for the conversion, or 0 to auto-detect.
+ * @param value
+ * Will hold the parsed integer value, on success.
+ * @return
+ * 0 on success, -1 on failure.
+ */
+int xstrtoll(const char *str, char **end, int base, long long *value);
+
+/**
* Process a yes/no prompt.
*
* @return 1 for yes, 0 for no, and -1 for unknown.
@@ -359,7 +376,7 @@ size_t xread(int fd, void *buf, size_t nbytes);
* writes.
*
* @return
- The number of bytes written. A value != nbytes indicates an error.
+ * The number of bytes written. A value != nbytes indicates an error.
*/
size_t xwrite(int fd, const void *buf, size_t nbytes);
@@ -430,6 +447,19 @@ int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *
*/
long xsysconf(int name);
+/**
+ * Check for a POSIX option[1] at runtime.
+ *
+ * [1]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap02.html#tag_02_01_06
+ *
+ * @param name
+ * The symbolic name of the POSIX option (e.g. SPAWN).
+ * @return
+ * The value of the option, either -1 or a date like 202405.
+ */
+#define sysoption(name) \
+ (_POSIX_##name == 0 ? xsysconf(_SC_##name) : _POSIX_##name)
+
#include <wchar.h>
/**