chiark / gitweb /
path-util: unify code for detecting OS trees
[elogind.git] / src / shared / hwclock.c
index f9adf0369ea71cc38f23315b43b57d8b66a2dc08..9076d8ffc76b850e20d280d876b6c241e86c8074 100644 (file)
@@ -41,6 +41,7 @@
 #include "log.h"
 #include "strv.h"
 #include "hwclock.h"
+#include "fileio.h"
 
 static int rtc_open(int flags) {
         int fd;
@@ -162,8 +163,7 @@ int hwclock_set_time(const struct tm *tm) {
 }
 
 int hwclock_is_localtime(void) {
-        FILE *f;
-        bool local = false;
+        FILE _cleanup_fclose_ *f;
 
         /*
          * The third line of adjtime is "UTC" or "LOCAL" or nothing.
@@ -180,19 +180,16 @@ int hwclock_is_localtime(void) {
                 b = fgets(line, sizeof(line), f) &&
                         fgets(line, sizeof(line), f) &&
                         fgets(line, sizeof(line), f);
-
-                fclose(f);
-
                 if (!b)
                         return -EIO;
 
                 truncate_nl(line);
-                local = streq(line, "LOCAL");
+                return streq(line, "LOCAL");
 
-        } else if (errno != -ENOENT)
+        } else if (errno != ENOENT)
                 return -errno;
 
-        return local;
+        return 0;
 }
 
 int hwclock_set_timezone(int *min) {