X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-lib%2Ffile.c;h=946d86725533c443cc32a5a906c06d850b816ff1;hb=6c292f6b369f019cc9a72a0ee65d60e172ee3370;hp=584fcdbb69286d0589dbdd1781b9c8993bc10e21;hpb=9ed7a487e3a922f2cbb222961c2c9710c3a65f91;p=apps%2Fmadmutt.git diff --git a/lib-lib/file.c b/lib-lib/file.c index 584fcdb..946d867 100644 --- a/lib-lib/file.c +++ b/lib-lib/file.c @@ -28,6 +28,8 @@ #include "lib-lib.h" +#include + #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) @@ -455,6 +457,14 @@ ssize_t m_file_fmt(char *dst, ssize_t n, const char *fmt, const char *src) return pos; } +ssize_t +m_quotefile_fmt(char *dst, ssize_t n, const char *fmt, const char *src) +{ + char tmp[LONG_STRING]; + mutt_quote_filename(tmp, sizeof(tmp), src); + return m_file_fmt(dst, n, fmt, tmp); +} + static ssize_t m_tempftplize(char *dst, ssize_t dlen, const char *fmt, const char *s) { @@ -513,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; +} +