]> git.ipfire.org Git - thirdparty/git.git/blame - wrapper.h
Merge branch 'jk/use-perl-path-consistently'
[thirdparty/git.git] / wrapper.h
CommitLineData
d5ebb50d
EN
1#ifndef WRAPPER_H
2#define WRAPPER_H
3
4/* set default permissions by passing mode arguments to open(2) */
5int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
6int git_mkstemp_mode(char *pattern, int mode);
7
8ssize_t read_in_full(int fd, void *buf, size_t count);
9ssize_t write_in_full(int fd, const void *buf, size_t count);
10ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
11
12static 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 */
21void 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)))
31void write_file(const char *path, const char *fmt, ...);
32
33/* Return 1 if the file is empty or does not exists, 0 otherwise. */
34int is_empty_or_missing_file(const char *filename);
35
36#endif /* WRAPPER_H */