home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / SETMODE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.8 KB  |  57 lines

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