fprovide.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <string.h>
  22. #include "binio.h"
  23. #include "binfile.h"
  24. #include "fprovide.h"
  25. #ifdef __SYMBIAN32__
  26. #define stricmp strcasecmp
  27. #else
  28. #ifndef _WIN32
  29. #define stricmp strcasecmp
  30. #endif
  31. #endif
  32. /***** CFileProvider *****/
  33. bool CFileProvider::extension(const std::string &filename,
  34. const std::string &extension) {
  35. const char *fname = filename.c_str(), *ext = extension.c_str();
  36. if (strlen(fname) < strlen(ext) ||
  37. stricmp(fname + strlen(fname) - strlen(ext), ext))
  38. return false;
  39. else
  40. return true;
  41. }
  42. unsigned long CFileProvider::filesize(binistream *f) {
  43. unsigned long oldpos = f->pos(), size;
  44. f->seek(0, binio::End);
  45. size = f->pos();
  46. f->seek(oldpos, binio::Set);
  47. return size;
  48. }
  49. /***** CProvider_Filesystem *****/
  50. binistream *CProvider_Filesystem::open(std::string filename) const {
  51. binifstream *f = new binifstream(filename);
  52. if (!f) return 0;
  53. if (f->error()) {
  54. delete f;
  55. return 0;
  56. }
  57. // Open all files as little endian with IEEE floats by default
  58. f->setFlag(binio::BigEndian, false);
  59. f->setFlag(binio::FloatIEEE);
  60. return f;
  61. }
  62. void CProvider_Filesystem::close(binistream *f) const {
  63. binifstream *ff = (binifstream *)f;
  64. if (f) {
  65. ff->close();
  66. delete ff;
  67. }
  68. }