[rfc] xioctl()
Denis Vlasenko
vda.linux at googlemail.com
Sat Jun 23 22:11:01 UTC 2007
On Saturday 23 June 2007 22:11, Tito wrote:
> On Saturday 23 June 2007 20:10:39 Bernhard Fischer wrote:
> > On Sat, Jun 23, 2007 at 01:31:19PM -0400, Mike Frysinger wrote:
> > >On Saturday 23 June 2007, Mike Frysinger wrote:
> > >> +int xioctl(int fd, int request, unsigned long arg)
> > >> +{
> > >> + int ret = ioctl(fd, request, arg);
> > >> + if (ret != 0)
> > >> + bb_perror_msg_and_die("ioctl");
> > >> + return ret;
> > >> +}
> > >
> > >actually now that i think about it, considering the usage here (people usually
> > >only care if it fails, they dont want to read the return value), we probably
> > >can do:
> > >void xioctl(...)
> >
> > Sounds ok to me. I had a patch which did this but did not apply it (and
> > forgot to ask..) since i though that discarding the information about
> > which ioctl it was that failed would not be well received, back then.
> >
> > Let's hear what vda says, i'd say fore! :)
I'm all for it, but please provide some means for passing custom
error message. "ioctl failed" is almost useless. WHICH ioctl?
Think about poor souls who will see the error message. It's
a wrong place to save a few bytes IMO.
> Hi,
> in hdparm.c we already have:
>
> /* Busybox messages and functions */
> static int bb_ioctl(int fd, int request, void *argp, const char *string)
> {
> int e = ioctl(fd, request, argp);
> if (e && string)
> bb_perror_msg(" %s", string);
> return e;
> }
>
> so that we can pass also an error message if needed, maybe this could be also
>
> static int bb_ioctl(int fd, int request, void *argp, ...)
> {
> va_list p;
> char *string;
> va_start(p, request);
> string = va_arg(va_list p, (char *));
>
> int e = ioctl(fd, request, argp);
> if (e && string)
> bb_perror_msg(" %s", string);
Use
bb_vperror_msg((string ? string : "ioctl"), p);
xfunc_die();
- this way you can have full printf-like format string and optional
params.
> va_end(p);
> return e;
> }
Bernhart is also right, do va_XXX only if if() is executed.
--
vda
More information about the busybox
mailing list