commit 2d7c327

default  ·  2022-11-25 12:33:13 +0000 UTC
parent afeec97
New function mtime_nl().
2 files changed,  +12, -5
M data.c
M snac.h
M data.c
+10, -4
 1@@ -185,14 +185,20 @@ d_char *user_list(void)
 2 }
 3 
 4 
 5-double mtime(const char *fn)
 6-/* returns the mtime of a file or directory, or 0.0 */
 7+double mtime_nl(const char *fn, int *n_link)
 8+/* returns the mtime and number of links of a file or directory, or 0.0 */
 9 {
10     struct stat st;
11     double r = 0.0;
12+    int n = 0;
13+
14+    if (fn && stat(fn, &st) != -1) {
15+        r = (double) st.st_mtim.tv_sec;
16+        n = st.st_nlink;
17+    }
18 
19-    if (fn && stat(fn, &st) != -1)
20-        r = (double)st.st_mtim.tv_sec;
21+    if (*n_link)
22+        *n_link = n;
23 
24     return r;
25 }
M snac.h
+2, -1
 1@@ -50,7 +50,8 @@ int check_password(char *uid, char *passwd, char *hash);
 2 void srv_archive(char *direction, char *req, char *payload, int p_size,
 3                  int status, char *headers, char *body, int b_size);
 4 
 5-double mtime(const char *fn);
 6+double mtime_nl(const char *fn, int *n_link);
 7+#define mtime(fn) mtime_nl(fn, NULL)
 8 
 9 int index_add(const char *fn, const char *md5);
10 int index_del(const char *fn, const char *md5);