home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / IO / IOCTL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.2 KB  |  54 lines

  1. /* ioctl.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdlib.h>
  5. #include <stdarg.h>
  6. #include <sys/termio.h>
  7. #include <sys/ioctl.h>
  8. #include <errno.h>
  9.  
  10. int ioctl (int handle, int request, ...)
  11. {
  12.   va_list va;
  13.   int rc, saved_errno, arg, *int_ptr;
  14.   const struct termio *tp;
  15.  
  16.   if (handle < 0 || handle >= _nfiles)
  17.     {
  18.       errno = EBADF;
  19.       return (-1);
  20.     }
  21.   saved_errno = errno; errno = 0;
  22.   va_start (va, request);
  23.   arg = va_arg (va, int);
  24.   va_end (va);
  25.   rc = __ioctl2 (handle, request, arg);
  26.   if (rc >= 0 && errno == 0)
  27.     switch (request)
  28.       {
  29.       case TCSETAF:
  30.       case TCSETAW:
  31.       case TCSETA:
  32.         va_start (va, request);
  33.         tp = va_arg (va, const struct termio *);
  34.         va_end (va);
  35.         if (tp->c_lflag & IDEFAULT)
  36.           _files[handle] &= ~F_TERMIO;
  37.         else
  38.           _files[handle] |= F_TERMIO;
  39.         break;
  40.       case FIONREAD:
  41.         if (_lookahead[handle] >= 0)
  42.           {
  43.             va_start (va, request);
  44.             int_ptr = va_arg (va, int *);
  45.             va_end (va);
  46.             ++(*int_ptr);
  47.           }
  48.         break;
  49.       }
  50.   if (errno == 0)
  51.     errno = saved_errno;
  52.   return (rc);
  53. }
  54.