echo.c and verror_msg.c have alternative implementations using writev
but the code does not compile when the flag is defined because the
non-writev code is still present so it fails due to double definition
of echo_main and bb_verror_msg.

This commit adds the appropriate #ifndef to both files to allow the
compilation to finish successfully with and without the
VERSION_WITH_WRITEV flag.

Also it includes the <sys/uio.h> that is needed to use writev.

It can be tested with the following command and then running the echo
applet:
% make EXTRA_CFLAGS="-DVERSION_WITH_WRITEV"

The code for the writev version may have been broken for 14+ years
according to the git history so deleting it is another option.

Signed-off-by: Ximo Planells Lerma <[email protected]>
---
 coreutils/echo.c   | 4 +++-
 libbb/verror_msg.c | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/coreutils/echo.c b/coreutils/echo.c
index 2a48d4a90..2fb2e1948 100644
--- a/coreutils/echo.c
+++ b/coreutils/echo.c
@@ -80,6 +80,7 @@
  * But this function is not standard.
  */
 
+#ifndef VERSION_WITH_WRITEV
 int echo_main(int argc UNUSED_PARAM, char **argv)
 {
        char **pp;
@@ -194,6 +195,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
        return err;
 }
 
+#else // #ifndef VERSION_WITH_WRITEV
 /*
  * Copyright (c) 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -233,7 +235,6 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
  *     @(#)echo.c      8.1 (Berkeley) 5/31/93
  */
 
-#ifdef VERSION_WITH_WRITEV
 /* We can't use stdio.
  * The reason for this is highly non-obvious.
  * echo_main is used from shell. Shell must correctly handle "echo foo"
@@ -245,6 +246,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
  *
  * Using writev instead, with 'direct' conversion of argv vector.
  */
+#include <sys/uio.h>
 
 int echo_main(int argc, char **argv)
 {
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
index 74b608f4c..49b87d394 100644
--- a/libbb/verror_msg.c
+++ b/libbb/verror_msg.c
@@ -11,12 +11,17 @@
 # include <syslog.h>
 #endif
 
+#ifdef VERSION_WITH_WRITEV
+# include <sys/uio.h>
+#endif
+
 #if ENABLE_FEATURE_SYSLOG
 static smallint syslog_level = LOG_ERR;
 #endif
 smallint logmode = LOGMODE_STDIO;
 const char *msg_eol = "\n";
 
+#ifndef VERSION_WITH_WRITEV
 void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
 {
        char *msg, *msg1;
@@ -97,7 +102,7 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const 
char* strerr)
                free(msg);
 }
 
-#ifdef VERSION_WITH_WRITEV
+#else // #ifdef VERSION_WITH_WRITEV
 /* Code size is approximately the same, but currently it's the only user
  * of writev in entire bbox. __libc_writev in uclibc is ~50 bytes. */
 void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
-- 
2.34.1

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to