man(1) Manual page archive

     IOCTL(2)                                                 IOCTL(2)

          ioctl, stty, gtty - miscellaneous  stream control operations

          #include <sgtty.h>

          ioctl(fildes, request, argp)
          struct sgttyb *argp;

          stty(fildes, argp)
          struct sgttyb *argp;

          gtty(fildes, argp)
          struct sgttyb *argp;

          Ioctl performs a variety of functions on special files and
          streams.  The writeups of various devices in section 4 dis-
          cuss how ioctl applies to them.

          For certain status setting and status inquiries about termi-
          nal devices, the functions stty and gtty are equivalent to

               ioctl(fildes, TIOCSETP, argp);
               ioctl(fildes, TIOCGETP, argp);

          respectively; see ttyld(4).

          The following two standard calls, however, apply to any open
          file.  The defined constant NULL has value 0.

               ioctl(fildes, FIOCLEX, NULL);
               ioctl(fildes, FIONCLEX, NULL);

          The first causes the file to be closed automatically upon a
          successful exec(2); the second causes the file to be left

          The following call applies to any stream file descriptor:

               ioctl(fildes, FIONREAD, &count);

          It returns, in the integer count, the number of characters
          available for reading from fildes.

          The following calls provide an advisory file locking facil-
          ity, and apply to any open file:

               ioctl(fildes, FIOALOCK, NULL);
               ioctl(fildes, FIOAUNLOCK, NULL);

     IOCTL(2)                                                 IOCTL(2)

               ioctl(fildes, FIOAISLOCK, NULL);

          FIOALOCK either sets an advisory lock, or indicates that
          this file is already locked by returning -1, with errno set
          to EPERM.

          FIOAUNLOCK either clears an advisory lock, or indicates that
          the file is locked by another instance of open by returning
          -1, with errno set to EPERM.

          FIOAISLOCK returns 0 for a file with no advisory lock set, 1
          for a file with an advisory lock set using another instance
          of open, or 2 for a file with an advisory lock set on the
          current instance of open. File descriptors belong to the
          same instance when they are copied by dup(2) or fork(2).
          Locks are detectable only through these calls, and have no
          effect on IO or ability to open files.

          stty(1), ttyld(4), proc(4), exec(2)

          Except where otherwise stated, 0 is returned if the call is
          successful; -1 if the file descriptor does not refer to the
          kind of file for which it was intended, or if request
          attempts to modify the state of an unwritable file.

          Strictly speaking, since ioctl may be extended in different
          ways to devices with different properties, argp should have
          an open-ended declaration like

               union { struct sgttyb ...; ...  } *argp;

          The important thing is that the size is fixed by `struct
          Ioctl requests vary among UNIX systems; undisciplined use is
          likely to compromise portability.