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

  1. /* sys/ioctl2.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <sys/ioctl.h>
  5. #include <errno.h>
  6. #include <os2emx.h>
  7. #include "syscalls.h"
  8.  
  9. int __ioctl2 (int handle, int request, int arg)
  10. {
  11.   ULONG rc;
  12.   ULONG type, flags;
  13.   int *int_ptr;
  14.  
  15.   switch (request)
  16.     {
  17.     case FGETHTYPE:
  18.       int_ptr = (int *)arg;
  19.       rc = DosQueryHType (handle, &type, &flags);
  20.       if (rc != 0)
  21.         {
  22.           _sys_set_errno (rc);
  23.           return (-1);
  24.         }
  25.       switch (type & 0xff)
  26.         {
  27.         case 0:                 /* File */
  28.           *int_ptr = HT_FILE;
  29.           break;
  30.         case 1:                 /* Character device */
  31.           if (flags & 3)
  32.             *int_ptr = HT_DEV_CON;
  33.           else if (flags & 4)
  34.             *int_ptr = HT_DEV_NUL;
  35.           else if (flags & 8)
  36.             *int_ptr = HT_DEV_CLK;
  37.           else
  38.             *int_ptr = HT_DEV_OTHER;
  39.           break;
  40.         case 2:                 /* Pipe */
  41.           rc = DosQueryNPHState (handle, &flags);
  42.           if (rc == 0 || rc == ERROR_PIPE_NOT_CONNECTED)
  43.             *int_ptr = HT_NPIPE;
  44.           else
  45.             *int_ptr = HT_UPIPE;
  46.           break;
  47.         default:
  48.           errno = EINVAL;
  49.           return (-1);
  50.         }
  51.       return (0);
  52.     default:
  53.       errno = EINVAL;
  54.       return (-1);
  55.     }
  56.  
  57. }
  58.