More compatibility!

Denys Vlasenko vda.linux at googlemail.com
Sat Dec 4 18:52:32 UTC 2010


On Thursday 02 December 2010 22:32, Chris Rees wrote:
> On 1 December 2010 21:06, Chris Rees <utisoft at gmail.com> wrote:
> > On 1 December 2010 20:42, Paul Smith <paul at mad-scientist.net> wrote:
> >> On Wed, 2010-12-01 at 19:09 +0000, Chris Rees wrote:
> >>> Hi,
> >>>
> >>> The use of malloc.h is a SYSVism, and the attached patch fixes for
> >>> FreeBSD at least!
> >>>
> >>> http://www.bayofrum.net/~chris/patch-appletlib-c
> >>>
> >>> If it needs reworking I'll do it; I'm likely to be sending a few soon
> >>> and I want them to be minimal effort for you.
> >>
> >> Is there some reason we don't just use stdlib.h everywhere?  That was
> >> defined back in ANSI C 1989--surely we can assume it's available now.
> >
> > I had considered that first, but I didn't want to be too radical as a
> > new arrival.
> >
> > Chris
> 
> Right, forget the moderate, here's the radical (but trivial) patch....
> 
> http://www.bayofrum.net/~chris/patch-appletlib-c_malloc_to_stdlib
> 
> Would that be OK?

Not really.

--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -28,7 +28,7 @@
  */
 #include "busybox.h"
 #include <assert.h>
-#include <malloc.h>
+#include <stdlib.h>

(1) as a result, M_TRIM_THRESHOLD is no longer visible even on systems
which do have it.
(2) stdlib.h is included by busybox.h, no need to include it again.


--- a/shell/hush.c
+++ b/shell/hush.c
@@ -82,7 +82,11 @@
  *              aaa
  */
 #include "busybox.h"  /* for APPLET_IS_NOFORK/NOEXEC */
-#include <malloc.h>   /* for malloc_trim */
+#ifdef M_TRIM_THRESHOLD
+# include <malloc.h>   /* for malloc_trim */
+#else
+# include <stdlib.h>
+#endif

as a result, M_TRIM_THRESHOLD is no longer visible even on systems
which do have it.

I think a better patch would be to frame #include <malloc.h>
in #ifndef <system which is known to not have malloc.h>

-- 
vda


More information about the busybox mailing list