home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / SETMODE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.0 KB  |  59 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - setmode.c
  3.  *
  4.  * function(s)
  5.  *        setmode - sets mode of open file
  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.  
  19. #pragma inline
  20. #include <io.h>
  21. #include <asmrules.h>
  22. #include <_io.h>
  23. #include <fcntl.h>
  24.  
  25. /*--------------------------------------------------------------------------*
  26.  
  27. Name        setmode - sets mode of open file
  28.  
  29. Usage        int setmode(int handle, int mode);
  30.  
  31. Prototype in    io.h
  32.  
  33. Description    setmode  sets the  mode of  the open  file associated  with
  34.         handle    to either  binary or  text. The  argument mode must
  35.         have a value of either O_BINARY or O_TEXT, never both.
  36.  
  37. Return value    setmode returns 0 if successful; on error it returns -1 and
  38.         sets errno to
  39.             EINVAL    Invalid argument
  40.  
  41. *---------------------------------------------------------------------------*/
  42. int setmode(int fildes, register int mode)
  43. {
  44.     register int newmode;
  45.  
  46.     if (fildes < 0 || fildes >= HANDLE_MAX || _openfd [fildes] == ~0U)
  47.                 return(__IOerror (e_badHandle));
  48.     if ((newmode = mode & (O_TEXT | O_BINARY)) == mode &&
  49.         newmode != (int)(O_TEXT | O_BINARY))
  50.     {
  51.         mode = _openfd [fildes];
  52.         _openfd [fildes] = (mode & ~(O_TEXT | O_BINARY)) | newmode;
  53.  
  54.                 return((mode & (O_TEXT | O_BINARY)));
  55.     }
  56.     else
  57.                 return((__IOerror (e_badFunction)));
  58. }
  59.