Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: libsbutil/
Date: Sun, 20 Dec 2015 08:41:24
Message-Id: 1450573873.a60b397d75e121232b8066db7333b82a6f9a951c.vapier@gentoo
1 commit: a60b397d75e121232b8066db7333b82a6f9a951c
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Sun Dec 20 01:11:13 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 20 01:11:13 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=a60b397d
7
8 sb_efuncs: avoid pointless stdio indirection
9
10 We were setting up a FILE* from a file descriptor to pass to sb_fprintf
11 which is a simple macro that calls fileno(fp) to pass the fd down. We
12 can call the fd funcs directly and avoid the whole stdio business.
13
14 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
15
16 libsbutil/sb_efuncs.c | 16 ++++++++--------
17 1 file changed, 8 insertions(+), 8 deletions(-)
18
19 diff --git a/libsbutil/sb_efuncs.c b/libsbutil/sb_efuncs.c
20 index c855257..2de3116 100644
21 --- a/libsbutil/sb_efuncs.c
22 +++ b/libsbutil/sb_efuncs.c
23 @@ -35,8 +35,8 @@ static void sbio_init(void)
24 */
25 static void sb_vefunc(const char *prog, const char *color, const char *format, va_list args)
26 {
27 + bool opened;
28 int fd;
29 - FILE *fp;
30
31 if (likely(sbio_message_path))
32 fd = sbio_open(sbio_message_path, O_WRONLY|O_APPEND|O_CLOEXEC, 0);
33 @@ -44,15 +44,15 @@ static void sb_vefunc(const char *prog, const char *color, const char *format, v
34 fd = -1;
35 if (fd == -1)
36 fd = sbio_open(sbio_fallback_path, O_WRONLY|O_CLOEXEC, 0);
37 - fp = fd == -1 ? NULL : fdopen(fd, "ae");
38 - if (!fp)
39 - fp = stderr;
40 + opened = (fd != -1);
41 + if (fd == -1)
42 + fd = fileno(stderr);
43
44 - sb_fprintf(fp, " %s*%s ", color, COLOR_NORMAL);
45 - sb_vfprintf(fp, format, args);
46 + sb_fdprintf(fd, " %s*%s ", color, COLOR_NORMAL);
47 + sb_vfdprintf(fd, format, args);
48
49 - if (fp != stderr)
50 - fclose(fp);
51 + if (opened)
52 + close(fd);
53 }
54
55 void sb_einfo(const char *format, ...)