[PATCH 1/2] libbb: add xopen_fd() helper
Xabier Oneca -- xOneca
xoneca at gmail.com
Tue Mar 2 22:49:17 UTC 2021
+1 on the rename to xopen_as().
El lun., 1 mar. 2021 18:15, Walter Harms <wharms at bfs.de> escribió:
> 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 at busybox.net> im Auftrag von Rasmus
> Villemoes <rasmus.villemoes at prevas.dk>
> Gesendet: Montag, 1. März 2021 17:03:56
> An: busybox at 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 at 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)
> FAST_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 at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210302/8f1646d5/attachment.html>
More information about the busybox
mailing list