On Tue, May 31, 2011 at 08:42:50AM -0400, Rich Felker wrote:
> On Mon, May 30, 2011 at 11:14:35PM -0700, Dan Fandrich wrote:
> Sadly it looks like ttyname might also be missing. It's easily
> implemented via readlink on /proc/self/fd/%d though, or some ioctl or
> fstat to get the device/tty number.

If it's just a stub, and newer versions of Android also provide a
ttyname_r stub, then I'll just drop that part of the patch.

> > 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.
> 
> If it's a constant, it's supposed to be defined there. If not, it
> should not be defined anywhere. Unfortunately some bloatware fans are
> into this whole "large pages" movement and want it considered
> variable...

It does look like Walter Harms' suggestion of using sysconf() is the most
portable way of getting this value. The attached patch makes that change.

> > 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.
> 
> I suspect so. That would be nice...

I'll remove that as well and see if anyone complains. There are a number
of other files that conditionally include net/ethernet.h (and usually
netpacket/packet.h) only on newer glibc versions, so I'll switch
those to using a macro in platform.h as well.  I'll test that a bit more
and send an updated Android patch later.

>>> Dan
From 0471da04c0b8d358545b610528ff2d5b08c806d2 Mon Sep 17 00:00:00 2001
From: Dan Fandrich <[email protected]>
Date: Wed, 1 Jun 2011 00:17:36 -0700
Subject: [PATCH] Use sysconf(_SC_PAGESIZE) to determine PAGE_SIZE

This seems to be the most portable way to determine page size,
and the only portable way on systems where it is dynamic.

Signed-off-by: Dan Fandrich <[email protected]>
---
 libbb/appletlib.c |   17 ++++-------------
 1 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 0dac0ba..955f680 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -34,17 +34,8 @@
 # include <malloc.h> /* for mallopt */
 #endif
 
-/* Try to pull in PAGE_SIZE */
-#ifdef __linux__
-# include <sys/user.h>
-#endif
-#ifdef __GNU__ /* Hurd */
-# include <mach/vm_param.h>
-#endif
-#ifndef PAGE_SIZE
-# define PAGE_SIZE (4*1024) /* guess */
-#endif
-
+/* Use 4096 if page size can't be otherwise determined */
+#define CURRENT_PAGE_SIZE ({long ps = sysconf(_SC_PAGESIZE); ps > 0 ? ps : 4*1024;})
 
 /* Declare <applet>_main() */
 #define PROTOTYPES
@@ -788,13 +779,13 @@ int main(int argc UNUSED_PARAM, char **argv)
 	 * to keep before releasing to the OS
 	 * Default is way too big: 256k
 	 */
-	mallopt(M_TRIM_THRESHOLD, 2 * PAGE_SIZE);
+	mallopt(M_TRIM_THRESHOLD, 2 * CURRENT_PAGE_SIZE);
 #endif
 #ifdef M_MMAP_THRESHOLD
 	/* M_MMAP_THRESHOLD is the request size threshold for using mmap()
 	 * Default is too big: 256k
 	 */
-	mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256);
+	mallopt(M_MMAP_THRESHOLD, 8 * CURRENT_PAGE_SIZE - 256);
 #endif
 
 #if !BB_MMU
-- 
1.5.3.2

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

Reply via email to