NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
file.h
Go to the documentation of this file.
1
24#ifndef MUTT_MUTT_FILE_H
25#define MUTT_MUTT_FILE_H
26
27#include "config.h"
28#include <dirent.h>
29#include <stdbool.h>
30#include <stdint.h>
31#include <stdio.h>
32#include <sys/types.h>
33
34struct Buffer;
35struct stat;
36extern const char FilenameSafeChars[];
37
38/* Flags for mutt_file_read_line() */
39typedef uint8_t ReadLineFlags;
40#define MUTT_RL_NO_FLAGS 0
41#define MUTT_RL_CONT (1 << 0)
42#define MUTT_RL_EOL (1 << 1)
43
44struct timespec;
45
52{
56};
57
62{
65};
66
71{
72 char *line;
73 size_t size;
75};
76
88typedef bool (*mutt_file_map_t)(char *line, int line_num, void *user_data);
89
90int mutt_file_check_empty(const char *path);
91int mutt_file_chmod_add(const char *path, mode_t mode);
92int mutt_file_chmod_add_stat(const char *path, mode_t mode, struct stat *st);
93int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st);
94int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size);
95int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out);
96time_t mutt_file_decrease_mtime(const char *fp, struct stat *st);
97void mutt_file_expand_fmt(struct Buffer *dest, const char *fmt, const char *src);
98void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src);
99int mutt_file_fclose_full(FILE **fp, const char *file, int line, const char *func);
100FILE * mutt_file_fopen_full(const char *path, const char *mode, const mode_t perms, const char *file, int line, const char *func);
101FILE * mutt_file_fopen_masked_full(const char *path, const char *mode, const char *file, int line, const char *func);
102int mutt_file_fsync_close(FILE **fp);
103long mutt_file_get_size(const char *path);
104long mutt_file_get_size_fp(FILE* fp);
105void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *st, enum MuttStatType type);
106bool mutt_file_iter_line(struct MuttFileIter *iter, FILE *fp, ReadLineFlags flags);
107int mutt_file_lock(int fd, bool excl, bool timeout);
108bool mutt_file_map_lines(mutt_file_map_t func, void *user_data, FILE *fp, ReadLineFlags flags);
109int mutt_file_mkdir(const char *path, mode_t mode);
110int mutt_file_open(const char *path, uint32_t flags, mode_t mode);
111DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode);
112char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen);
113char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags);
114int mutt_file_rename(const char *oldfile, const char *newfile);
115int mutt_file_rmtree(const char *path);
116const char *mutt_file_rotate(const char *path, int num);
117int mutt_file_safe_rename(const char *src, const char *target);
118void mutt_file_sanitize_filename(char *path, bool slash);
119int mutt_file_sanitize_regex(struct Buffer *dest, const char *src);
120size_t mutt_file_save_str(FILE *fp, const char *str);
121bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence);
122void mutt_file_set_mtime(const char *from, const char *to);
123int mutt_file_stat_compare(struct stat *st1, enum MuttStatType st1_type, struct stat *st2, enum MuttStatType st2_type);
124int mutt_file_stat_timespec_compare(struct stat *st, enum MuttStatType type, struct timespec *b);
125int mutt_file_symlink(const char *oldpath, const char *newpath);
126int mutt_file_timespec_compare(struct timespec *a, struct timespec *b);
127void mutt_file_touch_atime(int fd);
128void mutt_file_unlink(const char *s);
129void mutt_file_unlink_empty(const char *path);
130int mutt_file_unlock(int fd);
131void mutt_file_resolve_symlink(struct Buffer *buf);
132
133void buf_quote_filename(struct Buffer *buf, const char *filename, bool add_outer);
134void buf_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src);
135
136// Safest default permissions should be 0600
137#define mutt_file_fopen(PATH, MODE) mutt_file_fopen_full(PATH, MODE, 0600, __FILE__, __LINE__, __func__)
138#define mutt_file_fclose(FP) mutt_file_fclose_full(FP, __FILE__, __LINE__, __func__)
139
140#endif /* MUTT_MUTT_FILE_H */
void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *st, enum MuttStatType type)
Read the stat() time into a time value.
Definition: file.c:1579
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:287
FILE * mutt_file_fopen_full(const char *path, const char *mode, const mode_t perms, const char *file, int line, const char *func)
Call fopen() safely.
Definition: file.c:666
void buf_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell's quoting rules.
Definition: file.c:933
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
Definition: file.c:808
int mutt_file_safe_rename(const char *src, const char *target)
NFS-safe renaming of files.
Definition: file.c:371
void mutt_file_unlink_empty(const char *path)
Delete a file if it's empty.
Definition: file.c:1335
const char FilenameSafeChars[]
Set of characters <=0x7F that are safe to use in filenames.
Definition: file.c:71
MuttOpenDirMode
Mode flag for mutt_file_opendir()
Definition: file.h:62
@ MUTT_OPENDIR_CREATE
Create the directory if it doesn't exist.
Definition: file.h:64
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition: file.h:63
int mutt_file_stat_compare(struct stat *st1, enum MuttStatType st1_type, struct stat *st2, enum MuttStatType st2_type)
Compare two stat infos.
Definition: file.c:1641
int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size)
Copy some content from one file to another.
Definition: file.c:257
char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen)
Read a keyword from a file.
Definition: file.c:1406
void buf_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1456
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition: file.c:1091
int mutt_file_sanitize_regex(struct Buffer *dest, const char *src)
Escape any regex-magic characters in a string.
Definition: file.c:754
int mutt_file_check_empty(const char *path)
Is the mailbox empty.
Definition: file.c:1436
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:974
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
Definition: file.c:1202
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
Definition: file.c:1537
void mutt_file_sanitize_filename(char *path, bool slash)
Replace unsafe characters in a filename.
Definition: file.c:712
int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
Compare to time values.
Definition: file.c:1557
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1249
time_t mutt_file_decrease_mtime(const char *fp, struct stat *st)
Decrease a file's modification time by 1 second.
Definition: file.c:1028
bool mutt_file_map_lines(mutt_file_map_t func, void *user_data, FILE *fp, ReadLineFlags flags)
Process lines of text read from a file pointer.
Definition: file.c:910
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:642
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:778
int mutt_file_fclose_full(FILE **fp, const char *file, int line, const char *func)
Close a FILE handle (and NULL the pointer)
Definition: file.c:165
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1519
int mutt_file_rename(const char *oldfile, const char *newfile)
Rename a file.
Definition: file.c:1371
bool mutt_file_iter_line(struct MuttFileIter *iter, FILE *fp, ReadLineFlags flags)
Iterate over the lines from an open file pointer.
Definition: file.c:889
void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src)
const char * mutt_file_rotate(const char *path, int num)
Rotate a set of numbered files.
Definition: file.c:546
int mutt_file_symlink(const char *oldpath, const char *newpath)
Create a symlink.
Definition: file.c:315
int mutt_file_chmod_add_stat(const char *path, mode_t mode, struct stat *st)
Add permissions to a file.
Definition: file.c:1139
bool(* mutt_file_map_t)(char *line, int line_num, void *user_data)
Definition: file.h:88
void mutt_file_expand_fmt(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1471
void mutt_file_resolve_symlink(struct Buffer *buf)
Resolve a symlink in place.
Definition: file.c:1659
void mutt_file_set_mtime(const char *from, const char *to)
Set the modification time of one file from another.
Definition: file.c:1068
int mutt_file_stat_timespec_compare(struct stat *st, enum MuttStatType type, struct timespec *b)
Compare stat info with a time value.
Definition: file.c:1619
MuttStatType
Flags for mutt_file_get_stat_timespec.
Definition: file.h:52
@ MUTT_STAT_CTIME
File/dir's ctime - creation time.
Definition: file.h:55
@ MUTT_STAT_ATIME
File/dir's atime - last accessed time.
Definition: file.h:53
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
Definition: file.h:54
uint8_t ReadLineFlags
Flags for mutt_file_read_line(), e.g. MUTT_RL_CONT.
Definition: file.h:39
FILE * mutt_file_fopen_masked_full(const char *path, const char *mode, const char *file, int line, const char *func)
Wrapper around mutt_file_fopen_full()
Definition: neomutt.c:230
int mutt_file_chmod_add(const char *path, mode_t mode)
Add permissions to a file.
Definition: file.c:1116
int mutt_file_open(const char *path, uint32_t flags, mode_t mode)
Open a file.
Definition: file.c:577
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:221
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
Definition: file.c:193
int mutt_file_rmtree(const char *path)
Recursively remove a directory.
Definition: file.c:486
size_t mutt_file_save_str(FILE *fp, const char *str)
Save a string to a file.
Definition: file.c:1679
int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st)
Remove permissions from a file.
Definition: file.c:1173
String manipulation buffer.
Definition: buffer.h:36
State record for mutt_file_iter_line()
Definition: file.h:71
char * line
the line data
Definition: file.h:72
int line_num
line number
Definition: file.h:74
size_t size
allocated size of line data
Definition: file.h:73