diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-07-19 13:22:23 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-19 13:22:23 -0700 |
commit | 2b6456b8089e42232d80672525edbe411ba41549 (patch) | |
tree | b80371caee35146d5cab5c415aac68bfafb1e014 /cache.h | |
parent | 96e08010ee5b9d1dbfbcc8561fa69f972a415a38 (diff) | |
parent | 7eb6e10c9d7f43913615667740d1b22055cfba1f (diff) | |
download | git-2b6456b8089e42232d80672525edbe411ba41549.tar.gz |
Merge branch 'jk/write-file'
General code clean-up around a helper function to write a
single-liner to a file.
* jk/write-file:
branch: use write_file_buf instead of write_file
use write_file_buf where applicable
write_file: add format attribute
write_file: add pointer+len variant
write_file: use xopen
write_file: drop "gently" form
branch: use non-gentle write_file for branch description
am: ignore return value of write_file()
config: fix bogus fd check when setting up default config
Diffstat (limited to 'cache.h')
-rw-r--r-- | cache.h | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1746,8 +1746,21 @@ static inline ssize_t write_str_in_full(int fd, const char *str) return write_in_full(fd, str, strlen(str)); } -extern int write_file(const char *path, const char *fmt, ...); -extern int write_file_gently(const char *path, const char *fmt, ...); +/** + * Open (and truncate) the file at path, write the contents of buf to it, + * and close it. Dies if any errors are encountered. + */ +extern void write_file_buf(const char *path, const char *buf, size_t len); + +/** + * Like write_file_buf(), but format the contents into a buffer first. + * Additionally, write_file() will append a newline if one is not already + * present, making it convenient to write text files: + * + * write_file(path, "counter: %d", ctr); + */ +__attribute__((format (printf, 2, 3))) +extern void write_file(const char *path, const char *fmt, ...); /* pager.c */ extern void setup_pager(void); |