util.h: add new UNPROTECT_ERRNO macro
THis is inspired by #11395, but much simpler.
This commit is contained in:
@@ -361,11 +361,11 @@ static void test_unlink_noerrno(void) {
|
||||
|
||||
{
|
||||
PROTECT_ERRNO;
|
||||
errno = -42;
|
||||
errno = 42;
|
||||
assert_se(unlink_noerrno(name) >= 0);
|
||||
assert_se(errno == -42);
|
||||
assert_se(errno == 42);
|
||||
assert_se(unlink_noerrno(name) < 0);
|
||||
assert_se(errno == -42);
|
||||
assert_se(errno == 42);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,6 +213,30 @@ static void test_protect_errno(void) {
|
||||
assert_se(errno == 12);
|
||||
}
|
||||
|
||||
static void test_unprotect_errno_inner_function(void) {
|
||||
PROTECT_ERRNO;
|
||||
|
||||
errno = 2222;
|
||||
}
|
||||
|
||||
static void test_unprotect_errno(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
errno = 4711;
|
||||
|
||||
PROTECT_ERRNO;
|
||||
|
||||
errno = 815;
|
||||
|
||||
UNPROTECT_ERRNO;
|
||||
|
||||
assert_se(errno == 4711);
|
||||
|
||||
test_unprotect_errno_inner_function();
|
||||
|
||||
assert_se(errno == 4711);
|
||||
}
|
||||
|
||||
static void test_in_set(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
@@ -383,6 +407,7 @@ int main(int argc, char *argv[]) {
|
||||
test_div_round_up();
|
||||
test_u64log2();
|
||||
test_protect_errno();
|
||||
test_unprotect_errno();
|
||||
test_in_set();
|
||||
test_log2i();
|
||||
test_eqzero();
|
||||
|
||||
Reference in New Issue
Block a user