On Mon, May 30, 2011 at 07:48:05PM -0400, Rich Felker wrote:
> Plain ttyname could be used, I think. The only reason ttyname_r is
> used is to avoid enlarging bss for the nasty static buffer; it's not
> for reentrancy. This could also be done via HAVE_TTYNAME_R in
> platform.h rather than #ifndef ANDROID (see below)...
Ok, if reentrancy isn't an issue, I'll do that.
> > /* Try to pull in PAGE_SIZE */
> > #ifdef __linux__
> > -# include <sys/user.h>
> > +# ifdef ANDROID
> > +# include <sys/mman.h>
> > +# else
> > +# include <sys/user.h>
> > +# endif
>
> Why not get it from the correct place, limits.h? In case broken libs
> (glibc?) are missing it, you could do something like:
Is PAGE_SIZE mandated somewhere to be defined in limits.h? I tried
glibc, uclibc, libc5 and OpenWatcom (all on Linux) and none of them
defines it in limits.h.
> #include <limits.h>
> #ifndef PAGE_SIZE
> #include <sys/user.h>
> #endif
I changed it to basically follow this suggestion, and it's a bit harder to
follow now. But, it should stand up better with time.
> > --- a/libbb/obscure.c
> > +++ b/libbb/obscure.c
> > @@ -109,10 +109,12 @@ static const char *obscure_msg(const char *old_p,
> > const char *new_p, const struc
> > if (string_checker(new_p, pw->pw_name)) {
> > return "similar to username";
> > }
> > +#ifndef ANDROID
> > /* no gecos as-is, as sub-string, reversed, capitalized, doubled */
> > if (pw->pw_gecos[0] && string_checker(new_p, pw->pw_gecos)) {
> > return "similar to gecos";
> > }
> > +#endif
>
> This is a really ugly legacy approach to "portability" and leads to
> spaghetti #ifdefs. Instead you should add HAVE_PW_GECOS or something
> and #undef it in platform.h for ANDROID. Basically, #ifdef SYSNAME or
> #ifndef SYSNAME should *never* appear outside of platform.h. Currently
> it does in many places, but this should be treated as a bug to be
> fixed, not a practice to be followed.
That ends up being more lines of code now, but it does make sense as
Busybox is now being ported to new platforms.
The conditional in networking/interface.c isn't as obvious. I tried removing
the UCLIBC clause altogether and it still compiled fine in uClibc 0.6.29,
so perhaps it dates from an earlier version and could just be removed now.
An updated patch is attached.
>>> Dan
From 9620d384456b0d8b65211b937c40f74185084191 Mon Sep 17 00:00:00 2001
From: Dan Fandrich <[email protected]>
Date: Mon, 30 May 2011 14:05:07 -0700
Subject: [PATCH] Added support for compiling against Android bionic
It's not easy compiling something against bionic using the
Android compiler outside the Android build system, but it can
at least now happen.
Signed-off-by: Dan Fandrich <[email protected]>
---
include/platform.h | 16 +++++++++++++---
libbb/appletlib.c | 22 ++++++++++++++--------
libbb/obscure.c | 2 ++
libbb/xfuncs_printf.c | 5 +++++
networking/interface.c | 2 +-
5 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/include/platform.h b/include/platform.h
index 2b84447..1b03f46 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -332,8 +332,8 @@ typedef unsigned smalluint;
/* ---- Who misses what? ------------------------------------ */
-/* Assume all these functions exist by default. Platforms where it is not
- * true will #undef them below.
+/* Assume all these functions and header files exist by default.
+ * Platforms where it is not true will #undef them below.
*/
#define HAVE_CLEARENV 1
#define HAVE_FDATASYNC 1
@@ -341,6 +341,7 @@ typedef unsigned smalluint;
#define HAVE_MEMRCHR 1
#define HAVE_MKDTEMP 1
#define HAVE_PTSNAME_R 1
+#define HAVE_PW_GECOS 1
#define HAVE_SETBIT 1
#define HAVE_SIGHANDLER_T 1
#define HAVE_STPCPY 1
@@ -348,10 +349,11 @@ typedef unsigned smalluint;
#define HAVE_STRCHRNUL 1
#define HAVE_STRSEP 1
#define HAVE_STRSIGNAL 1
+#define HAVE_TTYNAME_R 1
#define HAVE_VASPRINTF 1
+#define HAVE_XTABS 1
#define HAVE_MNTENT_H 1
#define HAVE_SYS_STATFS_H 1
-#define HAVE_XTABS 1
#if defined(__dietlibc__)
# undef HAVE_STRCHRNUL
@@ -391,6 +393,14 @@ typedef unsigned smalluint;
# undef HAVE_STPCPY
#endif
+#if defined(ANDROID)
+# undef HAVE_DPRINTF
+# undef HAVE_PW_GECOS
+# undef HAVE_STPCPY
+# undef HAVE_STRCHRNUL
+# undef HAVE_TTYNAME_R
+#endif
+
/*
* Now, define prototypes for all the functions defined in platform.c
* These must come after all the HAVE_* macros are defined (or not)
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 0dac0ba..87c1fa4 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -35,15 +35,21 @@
#endif
/* Try to pull in PAGE_SIZE */
-#ifdef __linux__
-# include <sys/user.h>
-#endif
-#ifdef __GNU__ /* Hurd */
-# include <mach/vm_param.h>
-#endif
+#include <limits.h>
#ifndef PAGE_SIZE
-# define PAGE_SIZE (4*1024) /* guess */
-#endif
+# ifdef __linux__
+# include <sys/mman.h>
+# ifndef PAGE_SIZE
+# include <sys/user.h>
+# endif
+# endif /* __linux */
+# ifdef __GNU__ /* Hurd */
+# include <mach/vm_param.h>
+# endif
+# ifndef PAGE_SIZE
+# define PAGE_SIZE (4*1024) /* guess */
+# endif
+#endif /* PAGE_SIZE */
/* Declare <applet>_main() */
diff --git a/libbb/obscure.c b/libbb/obscure.c
index dd8cd31..4b19244 100644
--- a/libbb/obscure.c
+++ b/libbb/obscure.c
@@ -109,10 +109,12 @@ static const char *obscure_msg(const char *old_p, const char *new_p, const struc
if (string_checker(new_p, pw->pw_name)) {
return "similar to username";
}
+#ifdef HAVE_PW_GECOS
/* no gecos as-is, as sub-string, reversed, capitalized, doubled */
if (pw->pw_gecos[0] && string_checker(new_p, pw->pw_gecos)) {
return "similar to gecos";
}
+#endif
/* hostname as-is, as sub-string, reversed, capitalized, doubled */
hostname = safe_gethostname();
i = string_checker(new_p, hostname);
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 56ee459..45b4028 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -540,12 +540,17 @@ int FAST_FUNC bb_xioctl(int fd, unsigned request, void *argp)
char* FAST_FUNC xmalloc_ttyname(int fd)
{
+#ifdef HAVE_TTYNAME_R
char *buf = xzalloc(128);
int r = ttyname_r(fd, buf, 127);
if (r) {
free(buf);
buf = NULL;
}
+#else
+ char *name = ttyname(fd);
+ char *buf = xstrdup(name);
+#endif
return buf;
}
diff --git a/networking/interface.c b/networking/interface.c
index bea54c1..21f4006 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -32,7 +32,7 @@
*/
#include <net/if.h>
#include <net/if_arp.h>
-#ifndef __UCLIBC__
+#if !defined(__UCLIBC__) && !defined(ANDROID)
# include <net/ethernet.h>
#else
# include <linux/if_ether.h>
--
1.5.3.2
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox