]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/test/test-clock.c
fileio: simplify mkostemp_safe() (#4090)
[thirdparty/systemd.git] / src / test / test-clock.c
index b049d97ce7d04235966c53f6d987582db8a2d4c6..7d97328416b433ffa49382883c3d5d94e6bae4cc 100644 (file)
@@ -28,8 +28,8 @@
 
 static void test_clock_is_localtime(void) {
         char adjtime[] = "/tmp/test-adjtime.XXXXXX";
-        _cleanup_close_ int fd = -1;
-        FILE* f;
+        int fd = -1;
+        _cleanup_fclose_ FILE* f = NULL;
 
         static const struct scenario {
                 const char* contents;
@@ -55,11 +55,11 @@ static void test_clock_is_localtime(void) {
         /* without an adjtime file we default to UTC */
         assert_se(clock_is_localtime("/nonexisting/adjtime") == 0);
 
-        fd = mkostemp_safe(adjtime, O_WRONLY|O_CLOEXEC);
-        assert(fd > 0);
+        fd = mkostemp_safe(adjtime);
+        assert_se(fd >= 0);
         log_info("adjtime test file: %s", adjtime);
         f = fdopen(fd, "w");
-        assert(f);
+        assert_se(f);
 
         for (size_t i = 0; i < ELEMENTSOF(scenarios); ++i) {
                 log_info("scenario #%zu:, expected result %i", i, scenarios[i].expected_result);
@@ -82,10 +82,10 @@ static void test_clock_is_localtime_system(void) {
                 log_info("/etc/adjtime exists, clock_is_localtime() == %i", r);
                 /* if /etc/adjtime exists we expect some answer, no error or
                  * crash */
-                assert(r == 0 || r == 1);
+                assert_se(r == 0 || r == 1);
         } else
                 /* default is UTC if there is no /etc/adjtime */
-                assert(r == 0);
+                assert_se(r == 0);
 }
 
 int main(int argc, char *argv[]) {