]> git.ipfire.org Git - thirdparty/git.git/blob - wrapper.h
Merge branch 'tz/lib-gpg-prereq-fix'
[thirdparty/git.git] / wrapper.h
1 #ifndef WRAPPER_H
2 #define WRAPPER_H
3
4 /* set default permissions by passing mode arguments to open(2) */
5 int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
6 int git_mkstemp_mode(char *pattern, int mode);
7
8 ssize_t read_in_full(int fd, void *buf, size_t count);
9 ssize_t write_in_full(int fd, const void *buf, size_t count);
10 ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
11
12 static inline ssize_t write_str_in_full(int fd, const char *str)
13 {
14 return write_in_full(fd, str, strlen(str));
15 }
16
17 /**
18 * Open (and truncate) the file at path, write the contents of buf to it,
19 * and close it. Dies if any errors are encountered.
20 */
21 void write_file_buf(const char *path, const char *buf, size_t len);
22
23 /**
24 * Like write_file_buf(), but format the contents into a buffer first.
25 * Additionally, write_file() will append a newline if one is not already
26 * present, making it convenient to write text files:
27 *
28 * write_file(path, "counter: %d", ctr);
29 */
30 __attribute__((format (printf, 2, 3)))
31 void write_file(const char *path, const char *fmt, ...);
32
33 /* Return 1 if the file is empty or does not exists, 0 otherwise. */
34 int is_empty_or_missing_file(const char *filename);
35
36 #endif /* WRAPPER_H */