xfuncs, bb_ funcs and "nofork/noexec" plans
Denis Vlasenko
vda at ilport.com.ua
Sun Mar 12 23:24:04 PST 2006
On Friday 10 March 2006 22:01, Rob Landley wrote:
> > We can even have both:
>
> If X can replace Y then you don't need both. If you need both, it's because X
> can't really replace Y, which is a defect in X.
>
> > xlookup_host(&s_in, argv[optind]); //Will die with default error msg
> >
> > lookup_host_or_die(&s_in, argv[optind], "\0x3" "Custom error message and
> > exit code"); --
>
> Having both is bigger. The error message string is generally the biggest
> part. Moving the test out of line but then supply an extra argument on the
> stack is not a big win.
Sometimes you want custom error message. patch.c:
if (fputs(line, dest_stream) == EOF) {
bb_perror_msg_and_die("Error writing to new file");
}
We cannot save here on error message.
xfputs(line, dest_stream);
can give "Write error" at most.
No "Error writing to new file" or "Error writing to '%s'", filename.
fputs_or_die(line, dest_stream, "new file");
won't save that much, but it will save something AND will provide
meaningful error message.
Why call it fputs_or_die instead of xfputs, then? I think that almost
all currently existing xfuncs have exactly the same parameters as
corresponding C lib funcs:
void* malloc(size_t sz);
void* xmalloc(size_t sz /* no extra params! */ );
And I like this. Thus:
xfputs(line, dest_stream, "new file"); /* breaks that rule */
fputs_or_die(line, dest_stream, "new file"); /* I think this is better */
--
vda
More information about the busybox
mailing list