home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / fopen.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  106 lines

  1. /***
  2. *fopen.c - open a file
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines fopen() and _fsopen() - open a file as a stream and open a file
  8. *       with a specified sharing mode as a stream
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <stdio.h>
  14. #include <share.h>
  15. #include <dbgint.h>
  16. #include <internal.h>
  17. #include <mtdll.h>
  18. #include <file2.h>
  19. #include <tchar.h>
  20.  
  21. /***
  22. *FILE *_fsopen(file, mode, shflag) - open a file
  23. *
  24. *Purpose:
  25. *       Opens the file specified as a stream.  mode determines file mode:
  26. *       "r": read       "w": write      "a": append
  27. *       "r+": read/write                "w+": open empty for read/write
  28. *       "a+": read/append
  29. *       Append "t" or "b" for text and binary mode. shflag determines the
  30. *       sharing mode. Values are the same as for sopen().
  31. *
  32. *Entry:
  33. *       char *file - file name to open
  34. *       char *mode - mode of file access
  35. *
  36. *Exit:
  37. *       returns pointer to stream
  38. *       returns NULL if fails
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43.  
  44. FILE * __cdecl _tfsopen (
  45.         const _TSCHAR *file,
  46.         const _TSCHAR *mode
  47.         ,int shflag
  48.         )
  49. {
  50.         REG1 FILE *stream;
  51.         REG2 FILE *retval;
  52.  
  53.         _ASSERTE(file != NULL);
  54.         _ASSERTE(*file != _T('\0'));
  55.         _ASSERTE(mode != NULL);
  56.         _ASSERTE(*mode != _T('\0'));
  57.  
  58.         /* Get a free stream */
  59.         /* [NOTE: _getstream() returns a locked stream.] */
  60.  
  61.         if ((stream = _getstream()) == NULL)
  62.                 return(NULL);
  63.  
  64.         /* open the stream */
  65. #ifdef _UNICODE
  66.         retval = _wopenfile(file,mode,shflag,stream);
  67. #else  /* _UNICODE */
  68.         retval = _openfile(file,mode,shflag,stream);
  69. #endif  /* _UNICODE */
  70.  
  71.         /* unlock stream and return. */
  72.         _unlock_str(stream);
  73.         return(retval);
  74. }
  75.  
  76.  
  77. /***
  78. *FILE *fopen(file, mode) - open a file
  79. *
  80. *Purpose:
  81. *       Opens the file specified as a stream.  mode determines file mode:
  82. *       "r": read       "w": write      "a": append
  83. *       "r+": read/write                "w+": open empty for read/write
  84. *       "a+": read/append
  85. *       Append "t" or "b" for text and binary mode
  86. *
  87. *Entry:
  88. *       char *file - file name to open
  89. *       char *mode - mode of file access
  90. *
  91. *Exit:
  92. *       returns pointer to stream
  93. *       returns NULL if fails
  94. *
  95. *Exceptions:
  96. *
  97. *******************************************************************************/
  98.  
  99. FILE * __cdecl _tfopen (
  100.         const _TSCHAR *file,
  101.         const _TSCHAR *mode
  102.         )
  103. {
  104.         return( _tfsopen(file, mode, _SH_DENYNO) );
  105. }
  106.