InputFile.hh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // Common routines for opening/closing named input files
  17. // C++ header
  18. #ifndef _INPUT_FILE_HH
  19. #define _INPUT_FILE_HH
  20. #include <UsageEnvironment.hh>
  21. #include <stdio.h>
  22. #if (defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_WCE))
  23. #ifndef _WIN32_WCE
  24. // Include header files that might be needed by Windows (in code that uses this header file):
  25. #include <io.h>
  26. #include <fcntl.h>
  27. #endif
  28. #define READ_FROM_FILES_SYNCHRONOUSLY 1
  29. // Because Windows is a silly toy operating system that doesn't (reliably) treat
  30. // open files as being readable sockets (which can be handled within the default
  31. // "BasicTaskScheduler" event loop, using "select()"), we implement file reading
  32. // in Windows using synchronous, rather than asynchronous, I/O. This can severely
  33. // limit the scalability of servers using this code that run on Windows.
  34. // If this is a problem for you, then either use a better operating system,
  35. // or else write your own Windows-specific event loop ("TaskScheduler" subclass)
  36. // that can handle readable data in Windows open files as an event.
  37. #endif
  38. #ifndef _WIN32_WCE
  39. #include <sys/stat.h>
  40. #endif
  41. FILE* OpenInputFile(UsageEnvironment& env, char const* fileName);
  42. void CloseInputFile(FILE* fid);
  43. #undef GetFileSize // because some platforms already define this as a macro
  44. u_int64_t GetFileSize(char const* fileName, FILE* fid);
  45. // 0 means zero-length, unbounded, or unknown
  46. int64_t SeekFile64(FILE *fid, int64_t offset, int whence);
  47. // A platform-independent routine for seeking within (possibly) large files
  48. int64_t TellFile64(FILE *fid);
  49. // A platform-independent routine for reporting the position within
  50. // (possibly) large files
  51. Boolean FileIsSeekable(FILE *fid);
  52. // Tests whether "fid" is seekable, by trying to seek within it.
  53. #endif