Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Reference: https://lore.kernel.org/patchwork/patch/258361/

How is this useful

Knowing that no error occurred but the ioctl() command was not recognized is a useful piece of information.  Suppose, for example, I have nfds open character drivers in an array fd[].  Then I could do something like this:

int do_command(FAR int *fd, int nfds, int cmd)
{
  int ret;
  int i;

  /* Try all file descriptors */

  for (i = 0; i < nfds; i++)
    {
      ret = ioctl(fd[i], cmd, 0);  /* No argument in this example */
      if (ret < 0)
        {
          int errcode = errno;

          /* Try the next file descriptor if this one return ENOTTY */

          if (errcode != ENOTTY)
            {
              return -errcode
            }
        }
      else if (ret >= 0)
        {

          return OK;
        }
    }

  return -ENOENT;
}