[BusyBox] [PATCH] size optimisation for fdformat.c

Glenn McGrath bug1 at iinet.net.au
Wed Jan 21 07:53:59 UTC 2004


On Tue, 20 Jan 2004 23:26:12 +0000
Tito <farmatito at tiscali.it> wrote:

> I would try to do this just for fun .....if you give me a good example
> about the bitfield you told  :

> Wouldn't an int flag do it also?
> int die    (yes/no)	
> int msg  (yes/no)
> int action  (error, perror, herror, (verror maybe is not needed)
> ,syslog).
         ^, show_usage, no_msg

Yea, but squash them all into one variable.
e.g.

bit 1, die (1 bit = 2 states)
bit 2, msg (1 bit = 2 states)
bit 3-5, action (3 bit = 8 states, only need 6 (counting verror,
show_usage))

But when dont really need three seperate groups of bits, if you have msg
== 0 (ie no msg) then action isnt used, so they should be in the same
group.

There are only two diffent things we want to control in error_msg(), the
exit status, and how it sends the error message (if at all).

bit 1, die (0 = live, 1 = die)
bit 2-4, msg_action (2 = ignore_error, 4 = error, 6 = perror, 8 =
show_usage, 0xa = herror, 0xc = verror)

Then we can do

bb_show_usage(...) { error_flag = die | show_usage; bb_error_msg(...) };
bb_error_msg_and_die(...){error_flag = die | error; bb_error_msg(...)};
bb_perror_msg(...) { error_flag = live | perror; bb_error_msg(...) };
bb_perror_msg_and_die(...) { error_flag = die | perror;
bb_error_msg(...) };

And only modify bb_error_msg to handle the different behaviours.



Glenn



More information about the busybox mailing list