Thread (15 messages) 15 messages, 2 authors, 2020-07-01

Re: [PATCH v4 03/13] bisect--helper: introduce new `write_in_file()` function

From: Chris Torek <hidden>
Date: 2020-07-01 14:56:47

On Wed, Jul 1, 2020 at 6:37 AM Miriam Rubio [off-list ref] wrote:
Let's refactor code adding a new `write_in_file()` function
that opens a file for writing a message and closes it and a
wrapper for writting mode.
Nit: typo, s/writting/writing/

[snippage]
quoted hunk ↗ jump to hunk
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 0466b07a43..b421056546 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -74,6 +74,38 @@ static int one_of(const char *term, ...)
        return res;
 }

+static int write_in_file(const char *path, const char *mode, const char *format, va_list args)
+{
+       FILE *fp = NULL;
+       int res = 0;
+
+       if (!strcmp(mode, "a") && !strcmp(mode, "w"))
+               return error(_("wrong writing mode '%s'"), mode);
Should this maybe just be BUG()?
+       fp = fopen(path, mode);
+       if (!fp)
+               return error_errno(_("cannot open file '%s' in mode '%s'"), path, mode);
+       res = vfprintf(fp, format, args);
+
+       if (!res) {
This isn't quite right - vfprintf() returns a negative value on
error, or the number of characters printed on success.  Zero is
technically OK (if the format and arguments ended up empty).

[rest snipped]

Chris
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help