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

  1. /* sys/fcntl.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <fcntl.h>
  5. #include <errno.h>
  6. #include <os2emx.h>
  7. #include "syscalls.h"
  8.  
  9. int __fcntl (int handle, int request, int arg)
  10. {
  11.   ULONG rc;
  12.   ULONG state, new_state;
  13.  
  14.   switch (request)
  15.     {
  16.     case F_SETFL:
  17.       return (0);
  18.     case F_GETFD:
  19.       rc = DosQueryFHState (handle, &state);
  20.       if (rc != 0)
  21.         {
  22.           _sys_set_errno (rc);
  23.           return (-1);
  24.         }
  25.       return ((state & OPEN_FLAGS_NOINHERIT) ? 1 : 0);
  26.     case F_SETFD:
  27.       rc = DosQueryFHState (handle, &state);
  28.       if (rc != 0)
  29.         {
  30.           _sys_set_errno (rc);
  31.           return (-1);
  32.         }
  33.       if (arg & 1)
  34.         new_state = state | OPEN_FLAGS_NOINHERIT;
  35.       else
  36.         new_state = state & ~OPEN_FLAGS_NOINHERIT;
  37.       if (new_state != state)
  38.         {
  39.           new_state &= 0x7f88;
  40.           rc = DosSetFHState (handle, new_state);
  41.           if (rc != 0)
  42.             {
  43.               _sys_set_errno (rc);
  44.               return (-1);
  45.             }
  46.         }
  47.       return (0);
  48.     default:
  49.       errno = EINVAL;
  50.       return (-1);
  51.     }
  52. }
  53.