NeoMutt  2021-02-05
Teaching an old dog new tricks
DOXYGEN
file.h
Go to the documentation of this file.
1 
23 #ifndef MUTT_LIB_FILE_H
24 #define MUTT_LIB_FILE_H
25 
26 #include "config.h"
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <stdio.h>
30 #include <sys/types.h>
31 
32 struct Buffer;
33 struct stat;
34 extern char *C_Tmpdir;
35 extern const char filename_safe_chars[];
36 
37 /* Flags for mutt_file_read_line() */
38 typedef uint8_t ReadLineFlags;
39 #define MUTT_RL_NO_FLAGS 0
40 #define MUTT_RL_CONT (1 << 0)
41 #define MUTT_RL_EOL (1 << 1)
42 
43 #ifdef HAVE_STRUCT_TIMESPEC
44 struct timespec;
45 #else
46 
49 struct timespec
50 {
51  time_t tv_sec;
52  long tv_nsec;
53 };
54 #endif
55 
62 {
66 };
67 
72 {
73  char *line;
74  size_t size;
75  int line_num;
76 };
77 
86 typedef bool (*mutt_file_map_t)(char *line, int line_num, void *user_data);
87 
88 int mutt_file_check_empty(const char *path);
89 int mutt_file_chmod(const char *path, mode_t mode);
90 int mutt_file_chmod_add(const char *path, mode_t mode);
91 int mutt_file_chmod_add_stat(const char *path, mode_t mode, struct stat *st);
92 int mutt_file_chmod_rm(const char *path, mode_t mode);
93 int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st);
94 int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size);
95 int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out);
96 time_t mutt_file_decrease_mtime(const char *fp, struct stat *st);
97 void mutt_file_expand_fmt(struct Buffer *dest, const char *fmt, const char *src);
98 void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src);
99 int mutt_file_fclose(FILE **fp);
100 FILE * mutt_file_fopen(const char *path, const char *mode);
101 int mutt_file_fsync_close(FILE **fp);
102 long mutt_file_get_size(const char *path);
103 void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type);
104 bool mutt_file_iter_line(struct MuttFileIter *iter, FILE *fp, ReadLineFlags flags);
105 int mutt_file_lock(int fd, bool excl, bool timeout);
106 bool mutt_file_map_lines(mutt_file_map_t func, void *user_data, FILE *fp, ReadLineFlags flags);
107 int mutt_file_mkdir(const char *path, mode_t mode);
108 FILE * mutt_file_mkstemp_full(const char *file, int line, const char *func);
109 #define mutt_file_mkstemp() mutt_file_mkstemp_full(__FILE__, __LINE__, __func__)
110 int mutt_file_open(const char *path, uint32_t flags);
111 size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen);
112 char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen);
113 char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags);
114 int mutt_file_rename(const char *oldfile, const char *newfile);
115 int mutt_file_rmtree(const char *path);
116 int mutt_file_safe_rename(const char *src, const char *target);
117 void mutt_file_sanitize_filename(char *path, bool slash);
118 int mutt_file_sanitize_regex(struct Buffer *dest, const char *src);
119 void mutt_file_set_mtime(const char *from, const char *to);
120 int mutt_file_stat_compare(struct stat *sba, enum MuttStatType sba_type, struct stat *sbb, enum MuttStatType sbb_type);
121 int mutt_file_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b);
122 int mutt_file_symlink(const char *oldpath, const char *newpath);
123 int mutt_file_timespec_compare(struct timespec *a, struct timespec *b);
124 void mutt_file_touch_atime(int fd);
125 void mutt_file_unlink(const char *s);
126 void mutt_file_unlink_empty(const char *path);
127 int mutt_file_unlock(int fd);
128 void mutt_file_resolve_symlink(struct Buffer *buf);
129 
130 void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename, bool add_outer);
131 void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src);
132 
133 #endif /* MUTT_LIB_FILE_H */
void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1432
int mutt_file_chmod_add(const char *path, mode_t mode)
Add permissions to a file.
Definition: file.c:1067
File/dir&#39;s ctime - creation time.
Definition: file.h:65
char * line
the line data
Definition: file.h:73
int mutt_file_rename(const char *oldfile, const char *newfile)
Rename a file.
Definition: file.c:1347
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
Definition: file.c:169
void mutt_file_unlink_empty(const char *path)
Delete a file if it&#39;s empty.
Definition: file.c:1311
String manipulation buffer.
Definition: buffer.h:33
void mutt_file_set_mtime(const char *from, const char *to)
Set the modification time of one file from another.
Definition: file.c:1003
const char filename_safe_chars[]
Definition: file.c:61
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:195
int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
Compare to time values.
Definition: file.c:1515
void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type)
Read the stat() time into a time value.
Definition: file.c:1537
int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st)
Remove permissions from a file.
Definition: file.c:1146
int mutt_file_chmod_add_stat(const char *path, mode_t mode, struct stat *st)
Add permissions to a file.
Definition: file.c:1090
time_t tv_sec
Definition: file.h:51
int mutt_file_chmod_rm(const char *path, mode_t mode)
Remove permissions from a file.
Definition: file.c:1123
char * C_Tmpdir
Config: Directory for temporary files.
Definition: file.c:56
int mutt_file_chmod(const char *path, mode_t mode)
Set permissions of a file.
Definition: file.c:1042
MuttStatType
Flags for mutt_file_get_stat_timespec.
Definition: file.h:61
int mutt_file_lock(int fd, bool excl, bool timeout)
(try to) lock a file using fcntl()
Definition: file.c:1175
File/dir&#39;s mtime - last modified time.
Definition: file.h:64
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:875
long tv_nsec
Definition: file.h:52
int mutt_file_symlink(const char *oldpath, const char *newpath)
Create a symlink.
Definition: file.c:299
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:667
void mutt_file_resolve_symlink(struct Buffer *buf)
Resolve a symlink in place.
Definition: file.c:1617
uint8_t ReadLineFlags
Flags for mutt_file_read_line(), e.g. MUTT_RL_CONT.
Definition: file.h:38
FILE * mutt_file_mkstemp_full(const char *file, int line, const char *func)
Create temporary file safely.
Definition: file.c:930
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:271
int mutt_file_sanitize_regex(struct Buffer *dest, const char *src)
Escape any regex-magic characters in a string.
Definition: file.c:637
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1223
char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen)
Read a keyword from a file.
Definition: file.c:1382
int line_num
line number
Definition: file.h:75
int mutt_file_safe_rename(const char *src, const char *target)
NFS-safe renaming of files.
Definition: file.c:354
void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src)
size_t size
allocated size of line data
Definition: file.h:74
int mutt_file_open(const char *path, uint32_t flags)
Open a file.
Definition: file.c:522
void mutt_file_sanitize_filename(char *path, bool slash)
Replace unsafe characters in a filename.
Definition: file.c:618
int mutt_file_check_empty(const char *path)
Is the mailbox empty.
Definition: file.c:1412
State record for mutt_file_iter_line()
Definition: file.h:71
bool(* mutt_file_map_t)(char *line, int line_num, void *user_data)
Callback function for mutt_file_map_lines()
Definition: file.h:86
int mutt_file_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b)
Compare stat info with a time value.
Definition: file.c:1577
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:1447
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:767
bool mutt_file_iter_line(struct MuttFileIter *iter, FILE *fp, ReadLineFlags flags)
iterate over the lines from an open file pointer
Definition: file.c:747
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:589
void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell&#39;s quoting rules.
Definition: file.c:836
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:241
int mutt_file_rmtree(const char *path)
Recursively remove a directory.
Definition: file.c:468
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition: file.c:1026
Time value with nanosecond precision.
Definition: file.h:49
int mutt_file_stat_compare(struct stat *sba, enum MuttStatType sba_type, struct stat *sbb, enum MuttStatType sbb_type)
Compare two stat infos.
Definition: file.c:1599
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1495
size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen)
Quote a filename to survive the shell&#39;s quoting rules.
Definition: file.c:793
time_t mutt_file_decrease_mtime(const char *fp, struct stat *st)
Decrease a file&#39;s modification time by 1 second.
Definition: file.c:963
File/dir&#39;s atime - last accessed time.
Definition: file.h:63