tree-wide: introduce strerror_safe()
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "calendarspec.h"
|
||||
#include "errno-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -23,7 +24,7 @@ static void test_one(const char *input, const char *output) {
|
||||
|
||||
u = now(CLOCK_REALTIME);
|
||||
r = calendar_spec_next_usec(c, u, &u);
|
||||
printf("Next: %s\n", r < 0 ? strerror(-r) : format_timestamp(buf, sizeof(buf), u));
|
||||
printf("Next: %s\n", r < 0 ? strerror_safe(r) : format_timestamp(buf, sizeof(buf), u));
|
||||
calendar_spec_free(c);
|
||||
|
||||
assert_se(calendar_spec_from_string(p, &c) >= 0);
|
||||
@@ -56,7 +57,7 @@ static void test_next(const char *input, const char *new_tz, usec_t after, usec_
|
||||
|
||||
u = after;
|
||||
r = calendar_spec_next_usec(c, after, &u);
|
||||
printf("At: %s\n", r < 0 ? strerror(-r) : format_timestamp_us(buf, sizeof buf, u));
|
||||
printf("At: %s\n", r < 0 ? strerror_safe(r) : format_timestamp_us(buf, sizeof buf, u));
|
||||
if (expect != (usec_t)-1)
|
||||
assert_se(r >= 0 && u == expect);
|
||||
else
|
||||
@@ -103,10 +104,10 @@ static void test_hourly_bug_4031(void) {
|
||||
assert_se((r = calendar_spec_next_usec(c, n, &u)) >= 0);
|
||||
|
||||
printf("Now: %s (%"PRIu64")\n", format_timestamp_us(buf, sizeof buf, n), n);
|
||||
printf("Next hourly: %s (%"PRIu64")\n", r < 0 ? strerror(-r) : format_timestamp_us(buf, sizeof buf, u), u);
|
||||
printf("Next hourly: %s (%"PRIu64")\n", r < 0 ? strerror_safe(r) : format_timestamp_us(buf, sizeof buf, u), u);
|
||||
|
||||
assert_se((r = calendar_spec_next_usec(c, u, &w)) >= 0);
|
||||
printf("Next hourly: %s (%"PRIu64")\n", r < 0 ? strerror(-r) : format_timestamp_us(zaf, sizeof zaf, w), w);
|
||||
printf("Next hourly: %s (%"PRIu64")\n", r < 0 ? strerror_safe(r) : format_timestamp_us(zaf, sizeof zaf, w), w);
|
||||
|
||||
assert_se(n < u);
|
||||
assert_se(u <= n + USEC_PER_HOUR);
|
||||
|
||||
@@ -464,7 +464,7 @@ static void test_path_extract_filename_one(const char *input, const char *output
|
||||
int r;
|
||||
|
||||
r = path_extract_filename(input, &k);
|
||||
log_info("%s → %s/%s [expected: %s/%s]", strnull(input), strnull(k), strerror(-r), strnull(output), strerror(-ret));
|
||||
log_info("%s → %s/%s [expected: %s/%s]", strnull(input), strnull(k), strerror_safe(r), strnull(output), strerror_safe(ret));
|
||||
assert_se(streq_ptr(k, output));
|
||||
assert_se(r == ret);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "log.h"
|
||||
#include "memory-util.h"
|
||||
@@ -95,13 +96,13 @@ static void test_sleep(void) {
|
||||
|
||||
log_info("/= running system =/");
|
||||
r = can_sleep("suspend");
|
||||
log_info("Suspend configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r));
|
||||
log_info("Suspend configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
|
||||
r = can_sleep("hibernate");
|
||||
log_info("Hibernation configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r));
|
||||
log_info("Hibernation configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
|
||||
r = can_sleep("hybrid-sleep");
|
||||
log_info("Hybrid-sleep configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r));
|
||||
log_info("Hybrid-sleep configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
|
||||
r = can_sleep("suspend-then-hibernate");
|
||||
log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r));
|
||||
log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
Reference in New Issue
Block a user