home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLIBSRC3.ZIP / IOCTL.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  3.9 KB  |  115 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - ioctl.cas
  3.  *
  4.  * function(s)
  5.  *    ioctl - control I/O device
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18.  
  19. #define __IN_IOCTL
  20.  
  21. #include <asmrules.h>
  22. #include <io.h>
  23. #include <_io.h>
  24. #include <errno.h>
  25.  
  26. extern int _protected;  // Needed until _protected is in a header file.
  27.  
  28. /*-----------------------------------------------------------------------*
  29.  
  30. Name            ioctl - controls I/O device
  31.  
  32. Usage           int ioctl(int handle, int cmd [, void *argdx, int argcx]);
  33.  
  34. Prototype in    io.h
  35.  
  36. Description     This is a direct interface to the MS-DOS call 0x44
  37.                 (IOCTL).
  38.                 The exact function depends on the value of cmd as follows:
  39.  
  40.                     0   Get device information
  41.                     1   Set device information (in argdx)
  42.                     2   Read argcx bytes into the address pointed to by
  43.                         argdx
  44.                     3   Write argcx bytes from the address pointed to
  45.                         by argdx
  46.                     4   Same as 2, except handle is treated as a drive number
  47.                         (0 = default, 1 = A, etc.)
  48.                     5   Same as 3, except handle is a drive number
  49.                         (0 = default, 1 = A, etc.)
  50.                     6   Get input status
  51.                     7   Get output status
  52.                     8   Test removability; DOS 3.x only
  53.                     11  Set sharing conflict retry count; DOS 3.x only
  54.  
  55.                 ioctl can be used to get information about device channels.
  56.                 Regular files can also be used, but only cmd values 0, 6, and
  57.                 7 are defined for them. All other calls return an EINVAL error
  58.                 for files.
  59.  
  60.                 See the documentation for system call 0x44 in the MS-DOS
  61.                 Programmer's Reference Manual for detailed information on
  62.                 argument or return values.
  63.  
  64.                 The arguments argdx and argcx are optional.
  65.  
  66.                 ioctl provides a direct interface to DOS 2.0 device drivers for
  67.                 special functions. As a result, the exact behavior of this
  68.                 function will vary across different vendors' hardware and in
  69.                 different devices. Also, several vendors do not follow the
  70.                 interfaces described here. Refer to the vendor BIOS
  71.                 documentation for exact use of ioctl.
  72.  
  73. Return value    For cmd 0 or 1, the return value is the device
  74.                 information (DX of the IOCTL call).
  75.  
  76.                 For cmd values of 2 through 5, the return value is the
  77.                 number of bytes actually transferred.
  78.  
  79.                 For cmd values of 6 or 7, the return value is the device
  80.                 status.
  81.  
  82.                 In any event, if an error is detected, a value of -1 is
  83.                 returned, and errno is set to one of the following:
  84.  
  85.                     EINVAL  Invalid argument
  86.                     EBADF   Bad file number
  87.                     EINVDAT Invalid data
  88.  
  89. NOTE:           ioctl has old style definition since prototype has ... ;
  90.                 argdx and argcx are optional
  91. *------------------------------------------------------------------------*/
  92. int ioctl (fd, func, argdx, argcx)
  93.     int fd; int func; void *argdx; int argcx;
  94. {
  95.     pushDS_
  96.     asm LDS_ dx, argdx
  97.  
  98.  
  99.     asm mov ah,44h
  100.     asm mov al,func
  101.     asm mov bx,fd
  102.     asm mov cx,argcx
  103.     asm int 21h
  104.  
  105.     popDS_
  106.  
  107.     asm jc  ioctlFailed
  108.     if (func == 0)
  109.         return(_DX);        // Dev info is in dx
  110.     return(_AX);
  111.  
  112. ioctlFailed:
  113.     return  __IOerror (_AX);
  114. }
  115.