miofile.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC 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.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_MIOFILE_H
  18. #define BOINC_MIOFILE_H
  19. #ifdef _USING_FCGI_
  20. #include "boinc_fcgi.h"
  21. #endif
  22. #include <string>
  23. #include "mfile.h"
  24. // MIOFILE lets you do formatted I/O to either a FILE or a memory buffer,
  25. // depending on how you initialize it.
  26. //
  27. // output:
  28. // init_file(): output goes to the FILE* that you specify
  29. // init_mfile(): output goes to an MFILE (i.e. a memory buffer);
  30. // you can call MFILE::get_buf() to get the results
  31. // input:
  32. // init_file(): input comes from the FILE* that you specify
  33. // init_buf(): input comes from the buffer you specify.
  34. // This string is not modified.
  35. //
  36. // Why is this here? Because on Windows (9x, maybe all)
  37. // you can't do fdopen() on a socket.
  38. class MIOFILE {
  39. MFILE* mf;
  40. char* wbuf;
  41. int len;
  42. const char* buf;
  43. public:
  44. FILE* f;
  45. MIOFILE();
  46. ~MIOFILE();
  47. void init_mfile(MFILE*);
  48. #ifndef _USING_FCGI_
  49. void init_file(FILE*);
  50. #else
  51. void init_file(FCGI_FILE *);
  52. #endif
  53. void init_buf_read(const char*);
  54. void init_buf_write(char*, int len);
  55. int printf(const char* format, ...);
  56. char* fgets(char*, int);
  57. int _ungetc(int);
  58. bool eof();
  59. inline int _getc() {
  60. if (f) {
  61. return fgetc(f);
  62. }
  63. return (*buf)?(*buf++):EOF;
  64. }
  65. };
  66. extern int copy_element_contents(MIOFILE& in, const char* end_tag, char* p, int len);
  67. extern int copy_element_contents(MIOFILE& in, const char* end_tag, std::string&);
  68. #endif