[Toybox] PM: code style, was: Re: New Subscriber

Frank Bergmann toybox at tuxad.com
Sun Feb 5 14:31:03 PST 2012


er... forwarded to the list.

On Sun, Feb 05, 2012 at 11:28:39PM +0100, Frank Bergmann wrote:
> Hi Rob,
> 
> On Sun, Feb 05, 2012 at 12:07:57PM -0600, Rob Landley wrote:
> > > "uid=%u(%s) gid=%u(%s)\n", <real user ID>, <user-name>,
> > >    <real group ID>, <group-name>
> er... I remember now. :-(
> 
> > above output sequence for "id" with no arguments would be 9 separate
> > output statements without printf.  (Or 9 statements assembling a string,
> > of who knows what length, and then a tenth to write it out.)
> 
> Yes, this is a source code blow-up. But using your own calls it can also
> be easily readable. I remember such sequences of statements in the source
> of fnord (a fast and small webserver). This is an excerpt:
>       buffer_puts(buffer_1,"http://");
>       buffer_puts(buffer_1,host);
>       buffer_puts(buffer_1,"/");
>       buffer_puts(buffer_1,url);
>       buffer_puts(buffer_1,"/\r\n\r\n");
> You know what it means and you get just one syscall. Using printf() it is
> very hard to guess, how many syscalls one statement will use.
> 
> > Keep in mind that my primary design goal is _simplicity_, then size,
> > speed, and features. You have to trade these off against each other when
> 
> Yes, that was my question: Which kind of simplicity. ;-)
> 
> > And I want to let you build individual commands and have _those_ be as
> > small as possible, but in doing so I assume those will be dynamically
> > linked.  I am not optimizing for the "multiple individual executables,
> 
> Even if you replace some "evil" libcalls of stdio with your own (internal)
> lib you can still make code more small. I always test my binaries after
> big changes with different clibs and statically/dynamically and screw them
> up with strace and/or ltrace. That's not every day business but doing so
> gives you sometimes surprising results. :-)
> 
> > Never heard of either, but in general:
> > The external dependencies of BusyBox (under my tenure):
> >   libc
> > The external dependencies of toybox:
> >   libc
> 
> These libs are meant for internal usage but they are meant only as
> examples. In my tools I replaced much stdio-stuff with own "lib" routines
> and still have only libc as dependency. This lowers side effects when
> people use very different c-libs.
> 
> > if (flags & (FLAG_u|FLAG_g))
> >   printf("%d\n", (flags & FLAG_u) ? uid | gid);
> > else printf("%d %d\n", uid, gid);
> 
> What about the syscalls? ;-)
> 
> Frank
> 
> -- 
> EDV Frank Bergmann                           Tel.     05221-9249753
> LPIC-3 Linux Professional                    Fax      05221-9249754
> Pödinghauser Str. 5                          email    iservice at tuxad.com
> 32051 Herford                                USt-IdNr DE237314606

-- 
EDV Frank Bergmann                           Tel.     05221-9249753
LPIC-3 Linux Professional                    Fax      05221-9249754
Pödinghauser Str. 5                          email    iservice at tuxad.com
32051 Herford                                USt-IdNr DE237314606

 1328481063.0


More information about the Toybox mailing list