[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: AW: [PATCH 1/2] libbb: add xopen_fd() helper
From: Walter Harms <wharms () bfs ! de>
Date: 2021-03-01 17:14:50
Message-ID: 9b3b0915dd8a46a48cf9fd6ef191b3f3 () bfs ! de
[Download RAW message or body]
nice observation,
but IMHO the name is a bit misleading, i6 should be more generic like:
xopen_as()
ym2c,
re,
wh
________________________________________
Von: busybox <busybox-bounces@busybox.net> im Auftrag von Rasmus Villemoes =
<rasmus.villemoes@prevas.dk>
Gesendet: Montag, 1. M=E4rz 2021 17:03:56
An: busybox@busybox.net
Betreff: [PATCH 1/2] libbb: add xopen_fd() helper
xmove_fd(xopen(...), ...) is a common pattern. Add a helper for
that. On x86-64, this compiles to 18 bytes, so just a few call sites
need to be converted for a net win.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
include/libbb.h | 1 +
libbb/xfuncs_printf.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/include/libbb.h b/include/libbb.h
index cb6336474..ce5eaa5fb 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -608,6 +608,7 @@ int open3_or_warn(const char *pathname, int flags, int =
mode) FAST_FUNC;
int open_or_warn(const char *pathname, int flags) FAST_FUNC;
int xopen3(const char *pathname, int flags, int mode) FAST_FUNC;
int xopen(const char *pathname, int flags) FAST_FUNC;
+void xopen_fd(const char *pathname, int flags, int fd) FAST_FUNC;
int xopen_nonblocking(const char *pathname) FAST_FUNC;
int xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g) FA=
ST_FUNC;
int open_or_warn_stdin(const char *pathname) FAST_FUNC;
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 99596b9d0..f7c439c2f 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -160,6 +160,12 @@ int FAST_FUNC xopen(const char *pathname, int flags)
return xopen3(pathname, flags, 0666);
}
+// Die if we can't open a file as a given fd.
+void FAST_FUNC xopen_fd(const char *pathname, int flags, int fd)
+{
+ return xmove_fd(xopen(pathname, flags), fd);
+}
+
// Warn if we can't open a file and return a fd.
int FAST_FUNC open3_or_warn(const char *pathname, int flags, int mode)
{
--
2.29.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic