#include "lib-lib.h"
+#include <utime.h>
+
#ifndef O_NOFOLLOW
# define O_NOFOLLOW 0
#endif
/****************************************************************************/
-/* ligben-like funcs */
+/* path manipulations */
/****************************************************************************/
const char *mutt_basename(const char *f)
return p ? p + 1 : f;
}
+ssize_t m_dirname(char *dst, ssize_t dlen, const char *path)
+{
+ ssize_t plen = m_strlen(path);
+
+ while (plen > 0 && path[plen - 1] == '/')
+ plen--;
+
+ while (plen > 0 && path[plen - 1] != '/')
+ plen--;
+
+ while (plen > 0 && path[plen - 1] == '/')
+ plen--;
+
+ if (plen)
+ return m_strncpy(dst, dlen, path, plen);
+
+ if (*path == '/')
+ return m_strcpy(dst, dlen, "/");
+ return m_strcpy(dst, dlen, ".");
+}
char *
mutt_concat_path(char *d, ssize_t n, const char *dir, const char *fname)
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)
{
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;
+}
+