clang emits warnings about unused attribute _saved_errno_, which drown
out other—potentially useful—warnings. gcc documentation is not exactly
verbose about the effects of __attribute__((unused)) on variables, but
let's assume that it works if the unit test passes.
}
int cg_path_decode_unit(const char *cgroup, char **unit){
- _cleanup_free_ char *unescaped = NULL;
char *p, *e, *c, *s, *k;
assert(cgroup);
errno = *saved_errno;
}
-#define PROTECT_ERRNO _cleanup_(_reset_errno_) int _saved_errno_ = errno
+#define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno
struct _umask_struct_ {
mode_t mask;
#include <unistd.h>
#include <fcntl.h>
#include <locale.h>
+#include <errno.h>
#include "util.h"
log_info("pid1 $PATH: '%s'", strna(i));
}
+static void test_protect_errno(void) {
+ errno = 12;
+ {
+ PROTECT_ERRNO;
+ errno = 11;
+ }
+ assert(errno == 12);
+}
+
int main(int argc, char *argv[]) {
test_streq_ptr();
test_first_word();
test_hostname_is_valid();
test_u64log2();
test_get_process_comm();
+ test_protect_errno();
return 0;
}