First impressions of the "getopt.h forrest"
Denis Vlasenko
vda.linux at googlemail.com
Tue Mar 27 21:26:28 UTC 2007
Hi,
On Tuesday 27 March 2007 13:54, Mats Erik Andersson wrote:
> Find and remove unnecessary references to GNU-getopt
> in order that getopt-susv3 be a viable choice for
> at least minimal configurations of Busybox.
If the only difference is long options, then just disable
CONFIG_GETOPT_LONG and magically all long options switch off.
After this busybox should compile and link against libc with
getopt-susv3, no?
(Well, except these three applets which use getopt_long
*not* thru getopt32)
run_parts.c
dumpleases.c
getopt.c
> In particular, this means identifying places where getopt_long
> ought to be avoided or forced to be explicitly invoked in a
> configuration by the system builder. For this posting I must
> disregard anything that depends on getopt32, a speciality of
> Busybox, to get starting at all.
You do not need to disregard 90% of applets. Internally
getopt32() uses getopt() (or getopt_long() if CONFIG_GETOPT_LONG=y).
> Using 'grep' I constructed a list of all source files in
> Busybox 1.4.0 which call upon getopt.h without using getopt32,
> and I did a quick crosscheck against busybox-20070327 to be safe.
> This test is done against 1.4.0 since I run two minimal, but different,
> systems based on that Busybox edition, and thus can test quickly. The
> hits are as follows. I comment individually on them afterwards.
>
> coreutils/od.c
> debianutils/run_parts.c
> e2fsprogs/old_e2fsprogs/blkid/dev.c
> e2fsprogs/old_e2fsprogs/blkid/tag.c
> e2fsprogs/old_e2fsprogs/e2fsck.h
> e2fsprogs/old_e2fsprogs/mke2fs.c
> e2fsprogs/old_e2fsprogs/tune2fs.c
> networking/udhcp/dumpleases.c
> shell/hush.c
> util-linux/getopt.c
> util-linux/hexdump.c
>
> a) od.c and hexdump.c are very similar. They do not use
> long options only standard getopt(argc,argv,opts).
> Therefore I tested an alteration to hexdump.c:
>
> #include "busybox.h"
> /* #include <getopt.h> Declaration is already in
> busybox.h->libbb.h->unistd.h */
> #include "dump.h"
>
> Of course I gained nothing except a functional busybox
> binary of the same size, but it compiles without errors
> and I know (believe?) that getopt-susv3 suffices for od/hexdump.
> d) hush.c is clearly coded with short options, yet uses the full
> include/getopt.h. I se no reason it should not respond well to
> an alteration
>
> /* #include <getopt.h> */
> #include <unistd.h>
To me it looks like bbox with CONFIG_GETOPT_LONG=n and without
run_parts, dumpleases, getopt is already can be compiled with
susv3 getopt.
Make these three applets dependent on CONFIG_GETOPT_LONG=y
(or #ifdef out "long options" parts of them (example: dhcpc.c))
and you will have just one option controlling whether you
can compile busybox against getopt-sysv3.
BTW, what is the size difference?
--
vda
More information about the busybox
mailing list