NeoMutt  2021-10-29-225-gb9986f
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 const char filename_safe_chars[];
35 
36 /* Flags for mutt_file_read_line() */
37 typedef uint8_t ReadLineFlags;
38 #define MUTT_RL_NO_FLAGS 0
39 #define MUTT_RL_CONT (1 << 0)
40 #define MUTT_RL_EOL (1 << 1)
41 
42 #ifdef HAVE_STRUCT_TIMESPEC
43 struct timespec;
44 #else
48 struct timespec
49 {
50  time_t tv_sec;
51  long tv_nsec;
52 };
53 #endif
54 
61 {
65 };
66 
71 {
72  char *line;
73  size_t size;
74  int line_num;
75 };
76 
88 typedef bool (*mutt_file_map_t)(char *line, int line_num, void *user_data);
89 
90 int mutt_file_check_empty(const char *path);
91 int mutt_file_chmod(const char *path, mode_t mode);
92 int mutt_file_chmod_add(const char *path, mode_t mode);
93 int mutt_file_chmod_add_stat(const char *path, mode_t mode, struct stat *st);
94 int mutt_file_chmod_rm(const char *path, mode_t mode);
95 int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st);
96 int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size);
97 int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out);
98 time_t mutt_file_decrease_mtime(const char *fp, struct stat *st);
99 void mutt_file_expand_fmt(struct Buffer *dest, const char *fmt, const char *src);
100 void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src);
101 int mutt_file_fclose(FILE **fp);
102 FILE * mutt_file_fopen(const char *path, const char *mode);
103 int mutt_file_fsync_close(FILE **fp);
104 long mutt_file_get_size(const char *path);
105 long mutt_file_get_size_fp(FILE* fp);
106 void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *st, enum MuttStatType type);
107 bool mutt_file_iter_line(struct MuttFileIter *iter, FILE *fp, ReadLineFlags flags);
108 int mutt_file_lock(int fd, bool excl, bool timeout);
109 bool mutt_file_map_lines(mutt_file_map_t func, void *user_data, FILE *fp, ReadLineFlags flags);
110 int mutt_file_mkdir(const char *path, mode_t mode);
111 FILE * mutt_file_mkstemp_full(const char *file, int line, const char *func);
112 #define mutt_file_mkstemp() mutt_file_mkstemp_full(__FILE__, __LINE__, __func__)
113 int mutt_file_open(const char *path, uint32_t flags);
114 size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen);
115 char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen);
116 char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags);
117 int mutt_file_rename(const char *oldfile, const char *newfile);
118 int mutt_file_rmtree(const char *path);
119 int mutt_file_safe_rename(const char *src, const char *target);
120 void mutt_file_sanitize_filename(char *path, bool slash);
121 int mutt_file_sanitize_regex(struct Buffer *dest, const char *src);
122 bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence);
123 void mutt_file_set_mtime(const char *from, const char *to);
124 int mutt_file_stat_compare(struct stat *st1, enum MuttStatType st1_type, struct stat *st2, enum MuttStatType st2_type);
125 int mutt_file_stat_timespec_compare(struct stat *st, enum MuttStatType type, struct timespec *b);
126 int mutt_file_symlink(const char *oldpath, const char *newpath);
127 int mutt_file_timespec_compare(struct timespec *a, struct timespec *b);
128 void mutt_file_touch_atime(int fd);
129 void mutt_file_unlink(const char *s);
130 void mutt_file_unlink_empty(const char *path);
131 int mutt_file_unlock(int fd);
132 void mutt_file_resolve_symlink(struct Buffer *buf);
133 
134 void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename, bool add_outer);
135 void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src);
136 
137 #endif /* MUTT_LIB_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:1586
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_open(const char *path, uint32_t flags)
Open a file.
Definition: file.c:524
int mutt_file_safe_rename(const char *src, const char *target)
NFS-safe renaming of files.
Definition: file.c:355
void mutt_file_unlink_empty(const char *path)
Delete a file if it's empty.
Definition: file.c:1342
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:1648
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_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
void mutt_file_touch_atime(int fd)
Set the access time to current time.
Definition: file.c:1057
int mutt_file_sanitize_regex(struct Buffer *dest, const char *src)
Escape any regex-magic characters in a string.
Definition: file.c:641
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:695
int mutt_file_check_empty(const char *path)
Is the mailbox empty.
Definition: file.c:1443
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:905
const char filename_safe_chars[]
Definition: file.c:61
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
Definition: file.c:1206
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
Definition: file.c:1544
void mutt_file_sanitize_filename(char *path, bool slash)
Replace unsafe characters in a filename.
Definition: file.c:622
int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
Compare to time values.
Definition: file.c:1564
void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell's quoting rules.
Definition: file.c:866
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1254
int mutt_file_chmod_rm(const char *path, mode_t mode)
Remove permissions from a file.
Definition: file.c:1154
time_t mutt_file_decrease_mtime(const char *fp, struct stat *st)
Decrease a file's modification time by 1 second.
Definition: file.c:994
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:797
size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen)
Quote a filename to survive the shell's quoting rules.
Definition: file.c:823
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:665
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1526
int mutt_file_chmod(const char *path, mode_t mode)
Set permissions of a file.
Definition: file.c:1073
int mutt_file_rename(const char *oldfile, const char *newfile)
Rename a file.
Definition: file.c:1378
bool mutt_file_iter_line(struct MuttFileIter *iter, FILE *fp, ReadLineFlags flags)
Iterate over the lines from an open file pointer.
Definition: file.c:776
void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src)
char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen)
Read a keyword from a file.
Definition: file.c:1413
int mutt_file_symlink(const char *oldpath, const char *newpath)
Create a symlink.
Definition: file.c:299
FILE * mutt_file_mkstemp_full(const char *file, int line, const char *func)
Create temporary file safely.
Definition: file.c:960
int mutt_file_chmod_add_stat(const char *path, mode_t mode, struct stat *st)
Add permissions to a file.
Definition: file.c:1121
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:1478
void mutt_file_resolve_symlink(struct Buffer *buf)
Resolve a symlink in place.
Definition: file.c:1666
void mutt_file_set_mtime(const char *from, const char *to)
Set the modification time of one file from another.
Definition: file.c:1034
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:1626
MuttStatType
Flags for mutt_file_get_stat_timespec.
Definition: file.h:61
@ MUTT_STAT_CTIME
File/dir's ctime - creation time.
Definition: file.h:64
@ MUTT_STAT_ATIME
File/dir's atime - last accessed time.
Definition: file.h:62
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
Definition: file.h:63
uint8_t ReadLineFlags
Flags for mutt_file_read_line(), e.g. MUTT_RL_CONT.
Definition: file.h:37
int mutt_file_chmod_add(const char *path, mode_t mode)
Add permissions to a file.
Definition: file.c:1098
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:593
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:195
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
Definition: file.c:169
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:1463
int mutt_file_rmtree(const char *path)
Recursively remove a directory.
Definition: file.c:470
int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st)
Remove permissions from a file.
Definition: file.c:1177
String manipulation buffer.
Definition: buffer.h:34
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
Time value with nanosecond precision.
Definition: file.h:49
long tv_nsec
Number of nanosecond, on top.
Definition: file.h:51
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:50