commit - 748d5cab9a3d0d5d0edc28c8fd38430c684b1e55
commit + 4cc6a5a5fa3d5a5351d59385e614a0a78d167987
blob - 5fa8ffa0d2de4c2d61942eb2eed66a240149f6d0
blob + d3127f6f9acf465b17b825b7deb3d42b7a42fe7d
--- include/got_error.h
+++ include/got_error.h
*/
const struct got_error *got_error_from_errno3(const char *, const char *,
const char *);
+
+/*
+ * Get a statically allocated error object with code GOT_ERR_ERRNO
+ * and an error message obtained from strerror(3), prefixed with a
+ * string built with vsnprintf(3) from the provided format string
+ * and the variable-length list of additional arguments.
+ */
+const struct got_error *got_error_from_errno_fmt(const char *, ...);
/*
* Set errno to the specified error code and return a statically
blob - 6cbb7ca6b8a72218dbc5725fed24856910329b8f
blob + f8cf59b20a799b2b360c647f8eb7f1c331257431
--- lib/error.c
+++ lib/error.c
#include <errno.h>
#include <limits.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
const struct got_error *
+got_error_from_errno_fmt(const char *fmt, ...)
+{
+ static struct got_error err;
+ static char err_msg[PATH_MAX * 4 + 64];
+ char buf[PATH_MAX * 4];
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+
+ snprintf(err_msg, sizeof(err_msg), "%s: %s", buf, strerror(errno));
+
+ err.code = GOT_ERR_ERRNO;
+ err.msg = err_msg;
+ return &err;
+}
+
+const struct got_error *
got_error_set_errno(int code, const char *prefix)
{
errno = code;