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.

FileInStream.cxx 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2013 D. R. Commander. All Rights Reserved.
  3. * Copyright 2015 Pierre Ossman for Cendio AB
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This software 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
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this software; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23. #include <errno.h>
  24. #include <rdr/Exception.h>
  25. #include <rdr/FileInStream.h>
  26. using namespace rdr;
  27. FileInStream::FileInStream(const char *fileName)
  28. {
  29. file = fopen(fileName, "rb");
  30. if (!file)
  31. throw SystemException("fopen", errno);
  32. }
  33. FileInStream::~FileInStream(void) {
  34. if (file) {
  35. fclose(file);
  36. file = NULL;
  37. }
  38. }
  39. bool FileInStream::fillBuffer(size_t maxSize)
  40. {
  41. size_t n = fread((U8 *)end, 1, maxSize, file);
  42. if (n == 0) {
  43. if (ferror(file))
  44. throw SystemException("fread", errno);
  45. if (feof(file))
  46. throw EndOfStream();
  47. return false;
  48. }
  49. end += n;
  50. return true;
  51. }