Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

  1. // fiopen -- _Fiopen(const char *, ios_base::openmode)
  2. #include <fstream>
  3. _STD_BEGIN
  4. _CRTIMP2 FILE *__cdecl _Fiopen(const char *filename, ios_base::openmode mode)
  5. { // open a file
  6. static const char *mods[] =
  7. { // fopen mode strings corresponding to valid[i]
  8. "r", "w", "w", "a", "rb", "wb", "wb", "ab",
  9. "r+", "w+", "a+", "r+b", "w+b", "a+b", 0};
  10. static const int valid[] =
  11. { // valid combinations of open flags
  12. ios_base::in,
  13. ios_base::out,
  14. ios_base::out | ios_base::trunc,
  15. ios_base::out | ios_base::app,
  16. ios_base::in | ios_base::binary,
  17. ios_base::out | ios_base::binary,
  18. ios_base::out | ios_base::trunc | ios_base::binary,
  19. ios_base::out | ios_base::app | ios_base::binary,
  20. ios_base::in | ios_base::out,
  21. ios_base::in | ios_base::out | ios_base::trunc,
  22. ios_base::in | ios_base::out | ios_base::app,
  23. ios_base::in | ios_base::out | ios_base::binary,
  24. ios_base::in | ios_base::out | ios_base::trunc
  25. | ios_base::binary,
  26. ios_base::in | ios_base::out | ios_base::app
  27. | ios_base::binary,
  28. 0};
  29. FILE *fp;
  30. int n;
  31. ios_base::openmode atendflag = mode & ios_base::ate;
  32. mode &= ~ios_base::ate;
  33. for (n = 0; valid[n] != 0 && valid[n] != mode; ++n)
  34. ; // look for a valid mode
  35. if (valid[n] == 0 || (fp = fopen(filename, mods[n])) == 0)
  36. return (0); // no valid mode or open failed
  37. if (!atendflag || fseek(fp, 0, SEEK_END) == 0)
  38. return (fp); // no need to seek to end, or seek succeeded
  39. fclose(fp); // can't position at end
  40. return (0);
  41. }
  42. _STD_END
  43. /*
  44. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  45. * Consult your license regarding permissions and restrictions.
  46. V3.10:0009 */