[rfc] xioctl()

Loïc Grenié loic.grenie at gmail.com
Sun Jun 24 13:27:53 UTC 2007


2007/6/24, Tito <farmatito at tiscali.it>:
> On Sunday 24 June 2007 14:59:42 walter harms wrote:
> >
> > perhaps this can be fixed using a macro like:
> >
> >
> > #define xioctl(fd,req,...)   bb_ioctl(#req,fd,req,__VA_ARGS__)
> >
> > static int bb_ioctl(const char *estr, int fd, int request, void *argp, ...)
> > ...
> >
> > xioctl(get_console_fd(), VT_DISALLOCATE, (void *)num);
> > will now call a modified
> > bb_ioctl("VT_DISALLOCATE",get_console_fd(), VT_DISALLOCATE, (void *)num);
> >
> > the define eats no space and the new bb_ioctl will allow passing a free errormsg.
> >
> >
> > beware: I did no real testing an that ...
> >
> >
> > re,
> >  wh
>
> Hi,
> you can fix it the same way also without a macro by adding one more arg to
> the function (eventually set to NULL to trigger the default behaviour):
>
> xioctl(int fd, int request, void *argp, char * emsg)
>
> but the initial idea was to supply a default error message "ioctl" and switch to
> an optional error message with printf formatting capabilities only if needed
> without increasing the number of args needed by default by the function like:
>
> xioctl(int fd, int request, void *argp,...)
>
> so that we could do:
>
> xioctl(fd, request, argp)
> or
> xioctl(fd, request, argp, "this ioctl failed %s %s", a, b)
>
> but i found no way to test fot the presence or absence
> of args in the va_list......as the behaviour seems to be
> undefined if i understand the man page correctly.

     The behaviour is indeed undefined (the args are passed without
  explicit mention of their number in quite a lot, if not all, architectures).
  You can put an explicit NULL though:

#define xioctl(fd,req)   bb_ioctl(fd,req,NULL)
#define xioctl_msg(fd,req,string,...)   bb_ioctl(fd,req,string,__VA_ARGS__)

     Loïc



More information about the busybox mailing list