X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Ffile.c;h=4cd3b833a749936440e222ccc2d0cefd94964430;hp=aee35803fdb7a8234535c125de64ffce6d9bdc47;hb=16be8d10413bbcf822577afd4019d65aba7459e0;hpb=70e9ad0d77eb1c2d7ef76afdba6825de75d5599f diff --git a/lib-lib/file.c b/lib-lib/file.c index aee3580..4cd3b83 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) @@ -362,6 +364,26 @@ 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) @@ -521,3 +543,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; +} +