Source code of Windows XP (NT5)
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.

49 lines
1.4 KiB

  1. // fiopen -- [w]filebuf::_Fiopen(const char *, ios::openmode)
  2. #include <locale>
  3. #include <fstream>
  4. _STD_BEGIN
  5. _CRTIMP2 FILE *__cdecl __Fiopen(const char *name,
  6. ios_base::openmode mode)
  7. { // open a file
  8. static const char *mods[] = {
  9. "r", "w", "w", "a", "rb", "wb", "wb", "ab",
  10. "r+", "w+", "a+", "r+b", "w+b", "a+b", 0};
  11. static const int valid[] = {
  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 atefl = mode & ios_base::ate;
  32. mode &= ~ios_base::ate;
  33. for (n = 0; valid[n] != 0 && valid[n] != mode; ++n)
  34. ;
  35. if (valid[n] == 0 || (fp = fopen(name, mods[n])) == 0)
  36. return (0);
  37. if (!atefl || fseek(fp, 0, SEEK_END) == 0)
  38. return (fp);
  39. fclose(fp); // can't position at end
  40. return (0);
  41. }
  42. _STD_END
  43. /*
  44. * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
  45. * Consult your license regarding permissions and restrictions.
  46. */