]> git.ipfire.org Git - pakfire.git/commitdiff
path: Move pakfire_path_age
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 26 Oct 2024 12:35:47 +0000 (12:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 26 Oct 2024 12:35:47 +0000 (12:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/path.h
src/libpakfire/include/pakfire/util.h
src/libpakfire/path.c
src/libpakfire/util.c

index 005372b62ef82e5849357730d744dda6d1d73ce4..906824f814b723b10b20dac9d0dd4a8998ad7760 100644 (file)
@@ -22,6 +22,7 @@
 #define PAKFIRE_PATH_H
 
 #include <stddef.h>
+#include <time.h>
 
 #define pakfire_path_normalize(path) \
        __pakfire_path_normalize(path, sizeof(path))
@@ -65,4 +66,6 @@ int __pakfire_path_realpath(char* dest, const size_t length, const char* path);
 
 int pakfire_path_exists(const char* path);
 
+time_t pakfire_path_age(const char* path);
+
 #endif /* PAKFIRE_PATH_H */
index e8066f54c5a075e0bbc88b2e40983686d8a8cc59..0d26af3f753df0c8d19579313d8c07a9991ae755 100644 (file)
@@ -49,8 +49,6 @@ static inline void* pakfire_realloc(void* p, size_t size) {
        return n;
 }
 
-time_t pakfire_path_age(const char* path);
-
 int pakfire_read_file_into_buffer(FILE* f, char** buffer, size_t* len);
 
 #define pakfire_hexlify(digest) __pakfire_hexlify(digest, sizeof(digest))
index 6a71369479e0f0dcc70ccee610149063cfef4c7e..4ec117cacb7bca10015a165232cb50fe7cc40613 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <time.h>
 #include <unistd.h>
 
 #include <pakfire/path.h>
@@ -683,3 +685,17 @@ int __pakfire_path_realpath(char* dest, const size_t length, const char* path) {
 int pakfire_path_exists(const char* path) {
        return !access(path, F_OK);
 }
+
+time_t pakfire_path_age(const char* path) {
+       struct stat st;
+
+       int r = stat(path, &st);
+       if (r < 0)
+               return -errno;
+
+       // Get current timestamp
+       time_t now = time(NULL);
+
+       // Return the difference since the file has been created and now
+       return now - st.st_ctime;
+}
index ec9fb9860ebc947907111e3c6b9901b6f1949a33..5f49a5acd9a5a7224bf869c88a415a4c3be2330f 100644 (file)
@@ -68,21 +68,6 @@ const char* pakfire_path_relpath(const char* root, const char* path) {
        return NULL;
 }
 
-time_t pakfire_path_age(const char* path) {
-       struct stat st;
-
-       int r = stat(path, &st);
-       if (r == 0) {
-               // Get current timestamp
-               time_t now = time(NULL);
-
-               // Return the difference since the file has been created and now
-               return now - st.st_ctime;
-       }
-
-       return -1;
-}
-
 int pakfire_file_write(struct pakfire* pakfire, const char* path,
                uid_t owner, gid_t group, mode_t mode, const char* format, ...) {
        va_list args;