fprovide.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Adplug - Replayer for many OPL2/OPL3 audio file formats.
  3. * Copyright (C) 1999 - 2002 Simon Peter, <dn.tlp@gmx.net>, et al.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * fprovide.cpp - File provider class framework, by Simon Peter <dn.tlp@gmx.net>
  20. */
  21. #include "common.h"
  22. #include <string.h>
  23. #include "binio.h"
  24. #include "binfile.h"
  25. #include "fprovide.h"
  26. #ifdef __SYMBIAN32__
  27. #define stricmp strcasecmp
  28. #else
  29. #ifndef _WIN32
  30. #define stricmp strcasecmp
  31. #endif
  32. #endif
  33. /***** CFileProvider *****/
  34. bool CFileProvider::extension(const std::string &filename,
  35. const std::string &extension) {
  36. const char *fname = filename.c_str(), *ext = extension.c_str();
  37. if (strlen(fname) < strlen(ext) ||
  38. stricmp(fname + strlen(fname) - strlen(ext), ext))
  39. return false;
  40. else
  41. return true;
  42. }
  43. unsigned long CFileProvider::filesize(binistream *f) {
  44. unsigned long oldpos = f->pos(), size;
  45. f->seek(0, binio::End);
  46. size = f->pos();
  47. f->seek(oldpos, binio::Set);
  48. return size;
  49. }
  50. /***** CProvider_Filesystem *****/
  51. binistream *CProvider_Filesystem::open(std::string filename) const {
  52. binifstream *f = new binifstream(filename);
  53. if (!f) return 0;
  54. if (f->error()) {
  55. delete f;
  56. return 0;
  57. }
  58. // Open all files as little endian with IEEE floats by default
  59. f->setFlag(binio::BigEndian, false);
  60. f->setFlag(binio::FloatIEEE);
  61. return f;
  62. }
  63. void CProvider_Filesystem::close(binistream *f) const {
  64. binifstream *ff = (binifstream *)f;
  65. if (f) {
  66. ff->close();
  67. delete ff;
  68. }
  69. }