if ((snprintf(path, sizeof(path), "%s/.mh_sequences", m->path) < sizeof(path)) &&
(stat(path, &sb) == 0))
{
- return (mutt_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) > 0);
+ return (mutt_file_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) > 0);
}
return -1;
}
if ((snprintf(path, sizeof(path), "%s/%d", m->path, msgno) < sizeof(path)) &&
(stat(path, &sb) == 0))
{
- return (mutt_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) <= 0);
+ return (mutt_file_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) <= 0);
}
return -1;
}
{
snprintf(buf, sizeof(buf), "%s/%s", m->path, "cur");
if (stat(buf, &st) == 0)
- mutt_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME);
snprintf(buf, sizeof(buf), "%s/%s", m->path, "new");
}
else
{
snprintf(buf, sizeof(buf), "%s/.mh_sequences", m->path);
if (stat(buf, &st) == 0)
- mutt_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME);
mutt_str_strfcpy(buf, m->path, sizeof(buf));
}
if (stat(buf, &st) == 0)
- mutt_get_stat_timespec(&m->mtime, &st, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&m->mtime, &st, MUTT_STAT_MTIME);
}
/**
}
/* determine which subdirectories need to be scanned */
- if (mutt_stat_timespec_compare(&st_new, MUTT_STAT_MTIME, &m->mtime) > 0)
+ if (mutt_file_stat_timespec_compare(&st_new, MUTT_STAT_MTIME, &m->mtime) > 0)
changed = 1;
- if (mutt_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_cur) > 0)
+ if (mutt_file_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_cur) > 0)
changed |= 2;
if (!changed)
else
#endif
{
- mutt_get_stat_timespec(&mdata->mtime_cur, &st_cur, MUTT_STAT_MTIME);
- mutt_get_stat_timespec(&m->mtime, &st_new, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&mdata->mtime_cur, &st_cur, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&m->mtime, &st_new, MUTT_STAT_MTIME);
}
/* do a fast scan of just the filenames in
if (i == -1 && stat(buf, &st_cur) == -1)
modified = true;
- if ((mutt_stat_timespec_compare(&st, MUTT_STAT_MTIME, &m->mtime) > 0) ||
- (mutt_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_cur) > 0))
+ if ((mutt_file_stat_timespec_compare(&st, MUTT_STAT_MTIME, &m->mtime) > 0) ||
+ (mutt_file_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_cur) > 0))
{
modified = true;
}
else
#endif
{
- mutt_get_stat_timespec(&mdata->mtime_cur, &st_cur, MUTT_STAT_MTIME);
- mutt_get_stat_timespec(&m->mtime, &st, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&mdata->mtime_cur, &st_cur, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&m->mtime, &st, MUTT_STAT_MTIME);
}
md = NULL;
if (check_new && MailCheckRecent)
{
if (stat(mutt_b2s(path), &sb) == 0 &&
- mutt_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) < 0)
+ mutt_file_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) < 0)
{
rc = 0;
check_new = false;
mutt_buffer_printf(msgpath, "%s/%s", mutt_b2s(path), de->d_name);
/* ensure this message was received since leaving this m */
if (stat(mutt_b2s(msgpath), &sb) == 0 &&
- (mutt_stat_timespec_compare(&sb, MUTT_STAT_CTIME, &m->last_visited) <= 0))
+ (mutt_file_stat_timespec_compare(&sb, MUTT_STAT_CTIME, &m->last_visited) <= 0))
{
continue;
}
mutt_perror(m->path);
return -1;
}
- mutt_get_stat_timespec(&adata->atime, &sb, MUTT_STAT_ATIME);
- mutt_get_stat_timespec(&m->mtime, &sb, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&adata->atime, &sb, MUTT_STAT_ATIME);
+ mutt_file_get_stat_timespec(&m->mtime, &sb, MUTT_STAT_MTIME);
m->size = sb.st_size;
buf[sizeof(buf) - 1] = '\0';
}
m->size = sb.st_size;
- mutt_get_stat_timespec(&m->mtime, &sb, MUTT_STAT_MTIME);
- mutt_get_stat_timespec(&adata->atime, &sb, MUTT_STAT_ATIME);
+ mutt_file_get_stat_timespec(&m->mtime, &sb, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&adata->atime, &sb, MUTT_STAT_ATIME);
if (!m->readonly)
m->readonly = access(m->path, W_OK) ? true : false;
if (stat(m->path, &st) == 0)
{
- if ((mutt_stat_timespec_compare(&st, MUTT_STAT_MTIME, &m->mtime) == 0) &&
+ if ((mutt_file_stat_timespec_compare(&st, MUTT_STAT_MTIME, &m->mtime) == 0) &&
st.st_size == m->size)
{
return 0;
if (st.st_size == m->size)
{
/* the file was touched, but it is still the same length, so just exit */
- mutt_get_stat_timespec(&m->mtime, &st, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&m->mtime, &st, MUTT_STAT_MTIME);
return 0;
}
/* fix up the times so mailbox won't get confused */
if (m->peekonly && (m->path[0] != '\0') &&
- (mutt_timespec_compare(&m->mtime, &adata->atime) > 0))
+ (mutt_file_timespec_compare(&m->mtime, &adata->atime) > 0))
{
#ifdef HAVE_UTIMENSAT
struct timespec ts[2];
*/
#ifdef HAVE_UTIMENSAT
struct timespec ts[2];
- mutt_get_stat_timespec(&ts[0], &st, MUTT_STAT_ATIME);
- mutt_get_stat_timespec(&ts[1], &st, MUTT_STAT_MTIME);
+ mutt_file_get_stat_timespec(&ts[0], &st, MUTT_STAT_ATIME);
+ mutt_file_get_stat_timespec(&ts[1], &st, MUTT_STAT_MTIME);
utimensat(0, path, ts, 0);
#else
struct utimbuf times;
else
{
new_or_changed =
- (mutt_stat_compare(sb, MUTT_STAT_MTIME, sb, MUTT_STAT_ATIME) > 0) ||
+ (mutt_file_stat_compare(sb, MUTT_STAT_MTIME, sb, MUTT_STAT_ATIME) > 0) ||
(m->newly_created &&
- (mutt_stat_compare(sb, MUTT_STAT_CTIME, sb, MUTT_STAT_MTIME) == 0) &&
- (mutt_stat_compare(sb, MUTT_STAT_CTIME, sb, MUTT_STAT_ATIME) == 0));
+ (mutt_file_stat_compare(sb, MUTT_STAT_CTIME, sb, MUTT_STAT_MTIME) == 0) &&
+ (mutt_file_stat_compare(sb, MUTT_STAT_CTIME, sb, MUTT_STAT_ATIME) == 0));
}
if (new_or_changed)
{
if (!MailCheckRecent ||
- (mutt_stat_timespec_compare(sb, MUTT_STAT_MTIME, &m->last_visited) > 0))
+ (mutt_file_stat_timespec_compare(sb, MUTT_STAT_MTIME, &m->last_visited) > 0))
{
rc = 1;
m->has_new = true;
m->newly_created = false;
if (check_stats &&
- (mutt_stat_timespec_compare(sb, MUTT_STAT_MTIME, &m->stats_last_checked) > 0))
+ (mutt_file_stat_timespec_compare(sb, MUTT_STAT_MTIME, &m->stats_last_checked) > 0))
{
struct Context *ctx =
mx_mbox_open(m, NULL, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK);
#define fgetc fgetc_unlocked
#endif
-#ifndef HAVE_STRUCT_TIMESPEC
-/**
- * struct timespec - Time value with nanosecond precision
- */
-struct timespec
-{
- time_t tv_sec;
- long tv_nsec;
-};
-#endif
-
-/**
- * enum MuttStatType - Flags for mutt_get_stat_timespec
- *
- * These represent filesystem timestamps returned by stat()
- */
-enum MuttStatType
-{
- MUTT_STAT_ATIME,
- MUTT_STAT_MTIME,
- MUTT_STAT_CTIME
-};
-
/* flags for mutt_enter_string_full() */
#define MUTT_ALIAS (1 << 0) /**< do alias "completion" by calling up the alias-menu */
#define MUTT_FILE (1 << 1) /**< do file completion */
return sb.st_size;
}
+
+/**
+ * mutt_file_timespec_compare - Compare to time values
+ * @param a First time value
+ * @param b Second time value
+ * @retval -1 a precedes b
+ * @retval 0 a and b are identical
+ * @retval 1 b precedes a
+ */
+int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
+{
+ if (a->tv_sec < b->tv_sec)
+ return -1;
+ if (a->tv_sec > b->tv_sec)
+ return 1;
+
+ if (a->tv_nsec < b->tv_nsec)
+ return -1;
+ if (a->tv_nsec > b->tv_nsec)
+ return 1;
+ return 0;
+}
+
+/**
+ * mutt_file_get_stat_timespec - Read the stat() time into a time value
+ * @param dest Time value to populate
+ * @param sb stat info
+ * @param type Type of stat info to read, e.g. #MUTT_STAT_ATIME
+ */
+void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type)
+{
+ dest->tv_sec = 0;
+ dest->tv_nsec = 0;
+
+ switch (type)
+ {
+ case MUTT_STAT_ATIME:
+ dest->tv_sec = sb->st_atime;
+#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
+ dest->tv_nsec = sb->st_atim.tv_nsec;
+#endif
+ break;
+ case MUTT_STAT_MTIME:
+ dest->tv_sec = sb->st_mtime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ dest->tv_nsec = sb->st_mtim.tv_nsec;
+#endif
+ break;
+ case MUTT_STAT_CTIME:
+ dest->tv_sec = sb->st_ctime;
+#ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC
+ dest->tv_nsec = sb->st_ctim.tv_nsec;
+#endif
+ break;
+ }
+}
+
+/**
+ * mutt_file_stat_timespec_compare - Compare stat info with a time value
+ * @param sba stat info
+ * @param type Type of stat info, e.g. #MUTT_STAT_ATIME
+ * @param b Time value
+ * @retval -1 a precedes b
+ * @retval 0 a and b are identical
+ * @retval 1 b precedes a
+ */
+int mutt_file_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b)
+{
+ struct timespec a = { 0 };
+
+ mutt_file_get_stat_timespec(&a, sba, type);
+ return mutt_file_timespec_compare(&a, b);
+}
+
+/**
+ * mutt_file_stat_compare - Compare two stat infos
+ * @param sba First stat info
+ * @param sba_type Type of first stat info, e.g. #MUTT_STAT_ATIME
+ * @param sbb Second stat info
+ * @param sbb_type Type of second stat info, e.g. #MUTT_STAT_ATIME
+ * @retval -1 a precedes b
+ * @retval 0 a and b are identical
+ * @retval 1 b precedes a
+ */
+int mutt_file_stat_compare(struct stat *sba, enum MuttStatType sba_type,
+ struct stat *sbb, enum MuttStatType sbb_type)
+{
+ struct timespec a = { 0 };
+ struct timespec b = { 0 };
+
+ mutt_file_get_stat_timespec(&a, sba, sba_type);
+ mutt_file_get_stat_timespec(&b, sbb, sbb_type);
+ return mutt_file_timespec_compare(&a, &b);
+}
+
#ifndef MUTT_LIB_FILE_H
#define MUTT_LIB_FILE_H
+#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
#define MUTT_CONT (1 << 0) /**< \-continuation */
#define MUTT_EOL (1 << 1) /**< don't strip `\n` / `\r\n` */
+#ifndef HAVE_STRUCT_TIMESPEC
+/**
+ * struct timespec - Time value with nanosecond precision
+ */
+struct timespec
+{
+ time_t tv_sec;
+ long tv_nsec;
+};
+#endif
+
+/**
+ * enum MuttStatType - Flags for mutt_file_get_stat_timespec
+ *
+ * These represent filesystem timestamps returned by stat()
+ */
+enum MuttStatType
+{
+ MUTT_STAT_ATIME,
+ MUTT_STAT_MTIME,
+ MUTT_STAT_CTIME
+};
+
int mutt_file_check_empty(const char *path);
int mutt_file_chmod(const char *path, mode_t mode);
int mutt_file_chmod_add(const char *path, mode_t mode);
FILE * mutt_file_fopen(const char *path, const char *mode);
int mutt_file_fsync_close(FILE **f);
long mutt_file_get_size(const char *path);
+void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type);
int mutt_file_lock(int fd, bool excl, bool timeout);
int mutt_file_mkdir(const char *path, mode_t mode);
FILE * mutt_file_mkstemp_full(const char *file, int line, const char *func);
void mutt_file_sanitize_filename(char *f, bool slash);
int mutt_file_sanitize_regex(char *dest, size_t destlen, const char *src);
void mutt_file_set_mtime(const char *from, const char *to);
+int mutt_file_stat_compare(struct stat *sba, enum MuttStatType sba_type, struct stat *sbb, enum MuttStatType sbb_type);
+int mutt_file_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b);
int mutt_file_symlink(const char *oldpath, const char *newpath);
+int mutt_file_timespec_compare(struct timespec *a, struct timespec *b);
void mutt_file_touch_atime(int fd);
void mutt_file_unlink(const char *s);
void mutt_file_unlink_empty(const char *path);
sleep(s);
}
-/**
- * mutt_timespec_compare - Compare to time values
- * @param a First time value
- * @param b Second time value
- * @retval -1 a precedes b
- * @retval 0 a and b are identical
- * @retval 1 b precedes a
- */
-int mutt_timespec_compare(struct timespec *a, struct timespec *b)
-{
- if (a->tv_sec < b->tv_sec)
- return -1;
- if (a->tv_sec > b->tv_sec)
- return 1;
-
- if (a->tv_nsec < b->tv_nsec)
- return -1;
- if (a->tv_nsec > b->tv_nsec)
- return 1;
- return 0;
-}
-
-/**
- * mutt_get_stat_timespec - Read the stat() time into a time value
- * @param dest Time value to populate
- * @param sb stat info
- * @param type Type of stat info to read, e.g. #MUTT_STAT_ATIME
- */
-void mutt_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type)
-{
- dest->tv_sec = 0;
- dest->tv_nsec = 0;
-
- switch (type)
- {
- case MUTT_STAT_ATIME:
- dest->tv_sec = sb->st_atime;
-#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
- dest->tv_nsec = sb->st_atim.tv_nsec;
-#endif
- break;
- case MUTT_STAT_MTIME:
- dest->tv_sec = sb->st_mtime;
-#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
- dest->tv_nsec = sb->st_mtim.tv_nsec;
-#endif
- break;
- case MUTT_STAT_CTIME:
- dest->tv_sec = sb->st_ctime;
-#ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC
- dest->tv_nsec = sb->st_ctim.tv_nsec;
-#endif
- break;
- }
-}
-
-/**
- * mutt_stat_timespec_compare - Compare stat info with a time value
- * @param sba stat info
- * @param type Type of stat info, e.g. #MUTT_STAT_ATIME
- * @param b Time value
- * @retval -1 a precedes b
- * @retval 0 a and b are identical
- * @retval 1 b precedes a
- */
-int mutt_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b)
-{
- struct timespec a = { 0 };
-
- mutt_get_stat_timespec(&a, sba, type);
- return mutt_timespec_compare(&a, b);
-}
-
-/**
- * mutt_stat_compare - Compare two stat infos
- * @param sba First stat info
- * @param sba_type Type of first stat info, e.g. #MUTT_STAT_ATIME
- * @param sbb Second stat info
- * @param sbb_type Type of second stat info, e.g. #MUTT_STAT_ATIME
- * @retval -1 a precedes b
- * @retval 0 a and b are identical
- * @retval 1 b precedes a
- */
-int mutt_stat_compare(struct stat *sba, enum MuttStatType sba_type,
- struct stat *sbb, enum MuttStatType sbb_type)
-{
- struct timespec a = { 0 };
- struct timespec b = { 0 };
-
- mutt_get_stat_timespec(&a, sba, sba_type);
- mutt_get_stat_timespec(&b, sbb, sbb_type);
- return mutt_timespec_compare(&a, &b);
-}
-
/**
* mutt_make_version - Generate the NeoMutt version string
* @retval ptr Version string
void mutt_save_path(char *d, size_t dsize, struct Address *a);
void mutt_sleep(short s);
-int mutt_timespec_compare(struct timespec *a, struct timespec *b);
-void mutt_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type);
-int mutt_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b);
-int mutt_stat_compare(struct stat *sba, enum MuttStatType sba_type, struct stat *sbb, enum MuttStatType sbb_type);
-
#define mutt_mktemp(a, b) mutt_mktemp_pfx_sfx(a, b, "neomutt", NULL)
#define mutt_mktemp_pfx_sfx(a, b, c, d) mutt_mktemp_full(a, b, c, d, __FILE__, __LINE__)