home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / IOCTL.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  3.5 KB  |  109 lines

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