diff options
| -rw-r--r-- | src/utils.c | 17 | ||||
| -rw-r--r-- | src/utils.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index c00c3f9..7a762f7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,5 @@ #include "utils.h" +#include "err.h" #include "fm.h" #include "log.h" #include <limits.h> @@ -61,3 +62,19 @@ y_or_n(const char *prompt) return ch == 'y'; } + +int +xsnprintf(char *str, size_t size, const char *restrict format, ...) +{ + va_list ap; + va_start(ap, format); + + size_t len = vsnprintf(str, size, format, ap); + if (len >= size) { + die("Length of items error"); + } + + va_end(ap); + + return SF_OK; +} diff --git a/src/utils.h b/src/utils.h index 7c73fc8..c539ad9 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,5 +7,6 @@ int get_input(const char *prompt, char *buf, size_t len); bool y_or_n(const char *prompt); +int xsnprintf(char *str, size_t size, const char *restrict format, ...); #endif /* SF_UTILS_H */ |
