diff options
author | Jeff King <peff@peff.net> | 2016-07-08 05:12:42 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-08 09:47:29 -0700 |
commit | e04d08a4b3373972717c805ae8e788219b873b2a (patch) | |
tree | d94a1eae9969ac1d71025b9c2a130f6a01827a31 /cache.h | |
parent | write_file: add pointer+len variant (diff) | |
download | tgif-e04d08a4b3373972717c805ae8e788219b873b2a.tar.xz |
write_file: add format attribute
This gives us compile-time checking of our format strings,
which is a good thing.
I had also hoped it would help with confusing write_file()
and write_file_buf(), since the former's "..." can make it
match the signature of the latter. But given that the buffer
for write_file_buf() is generally not a string literal, the
compiler won't complain unless -Wformat-nonliteral is on,
and that creates a ton of false positives elsewhere in the
code base.
While we're there, let's also give the function a docstring,
which it never had.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache.h')
-rw-r--r-- | cache.h | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -1740,6 +1740,14 @@ static inline ssize_t write_str_in_full(int fd, const char *str) */ 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 */ |