aboutsummaryrefslogtreecommitdiffstats
path: root/wrapper.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-07-08 05:09:34 -0400
committerJunio C Hamano <gitster@pobox.com>2016-07-08 09:47:29 -0700
commitef22318cff51244cd0047b11ee7accfded522782 (patch)
treed25d0a8f8d0f7ddc27350cea6d0e875cd377c8db /wrapper.c
parent3d75bba28d8665ec43f1faffce38d5817c77ebe8 (diff)
downloadgit-ef22318cff51244cd0047b11ee7accfded522782.tar.gz
write_file: drop "gently" form
There are no callers left of write_file_gently(). Let's drop it, as it doesn't seem likely for new callers to be added (since its inception, the only callers who wanted the gentle form generally just died immediately themselves, and have since been converted). While we're there, let's also drop the "int" return from write_file, as it is never meaningful (in the non-gentle form, we always either die or return 0). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c54
1 files changed, 11 insertions, 43 deletions
diff --git a/wrapper.c b/wrapper.c
index 5dc4e15aa9..0349441bde 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -640,56 +640,24 @@ int xsnprintf(char *dst, size_t max, const char *fmt, ...)
return len;
}
-static int write_file_v(const char *path, int fatal,
- const char *fmt, va_list params)
+void write_file(const char *path, const char *fmt, ...)
{
+ va_list params;
struct strbuf sb = STRBUF_INIT;
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
- if (fd < 0) {
- if (fatal)
- die_errno(_("could not open %s for writing"), path);
- return -1;
- }
- strbuf_vaddf(&sb, fmt, params);
- strbuf_complete_line(&sb);
- if (write_in_full(fd, sb.buf, sb.len) != sb.len) {
- int err = errno;
- close(fd);
- strbuf_release(&sb);
- errno = err;
- if (fatal)
- die_errno(_("could not write to %s"), path);
- return -1;
- }
- strbuf_release(&sb);
- if (close(fd)) {
- if (fatal)
- die_errno(_("could not close %s"), path);
- return -1;
- }
- return 0;
-}
-
-int write_file(const char *path, const char *fmt, ...)
-{
- int status;
- va_list params;
+ if (fd < 0)
+ die_errno(_("could not open %s for writing"), path);
va_start(params, fmt);
- status = write_file_v(path, 1, fmt, params);
+ strbuf_vaddf(&sb, fmt, params);
va_end(params);
- return status;
-}
-
-int write_file_gently(const char *path, const char *fmt, ...)
-{
- int status;
- va_list params;
- va_start(params, fmt);
- status = write_file_v(path, 0, fmt, params);
- va_end(params);
- return status;
+ strbuf_complete_line(&sb);
+ if (write_in_full(fd, sb.buf, sb.len) != sb.len)
+ die_errno(_("could not write to %s"), path);
+ strbuf_release(&sb);
+ if (close(fd))
+ die_errno(_("could not close %s"), path);
}
void sleep_millisec(int millisec)