move more functions in file.c
[apps/madmutt.git] / lib-lib / file.c
index aee3580..946d867 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "lib-lib.h"
 
+#include <utime.h>
+
 #ifndef O_NOFOLLOW
 #  define O_NOFOLLOW  0
 #endif
@@ -353,7 +355,7 @@ int mutt_copy_bytes(FILE *in, FILE *out, ssize_t size)
 
 
 /****************************************************************************/
-/* ligben-like funcs                                                        */
+/* path manipulations                                                       */
 /****************************************************************************/
 
 const char *mutt_basename(const char *f)
@@ -521,3 +523,31 @@ FILE *m_tempfile(char *dst, ssize_t n, const char *dir, const char *fmt)
     int fd = m_tempfd(dst, n, dir, fmt);
     return fd < 0 ? NULL : fdopen(fd, "w+");
 }
+
+/****************************************************************************/
+/* misc                                                                     */
+/****************************************************************************/
+
+/* Decrease a file's modification time by 1 second */
+time_t m_decrease_mtime(const char *path, struct stat *st)
+{
+    struct utimbuf utim;
+    struct stat _st;
+    time_t mtime;
+
+    if (!st) {
+        if (stat(path, &_st) == -1)
+            return -1;
+        st = &_st;
+    }
+
+    if ((mtime = st->st_mtime) == time(NULL)) {
+        mtime -= 1;
+        utim.actime = mtime;
+        utim.modtime = mtime;
+        utime(path, &utim);
+    }
+
+    return mtime;
+}
+