2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2004-04-15 00:21:29 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-04-15 00:21:29 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
#ifndef _MFILE_
|
|
|
|
#define _MFILE_
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdarg>
|
2004-04-15 00:21:29 +00:00
|
|
|
|
2005-02-01 21:11:08 +00:00
|
|
|
// MFILE provides memory-buffered output with a FILE-type interface.
|
|
|
|
// BOINC uses this in a couple of places:
|
|
|
|
// 1) in the GUI RPC system (since in Windows you can't fdopen a socket)
|
|
|
|
// 2) in the API, to support a primitive form of checkpointing:
|
|
|
|
// Write all your output (and restart file) to MFILEs.
|
|
|
|
// The output is buffered in memory.
|
|
|
|
// Then close or flush all the MFILEs;
|
|
|
|
// all the buffers will be flushed to disk, almost atomically.
|
2004-04-15 00:21:29 +00:00
|
|
|
|
|
|
|
class MFILE {
|
2005-02-01 21:11:08 +00:00
|
|
|
char* buf; // NULL-terminated
|
2004-04-15 00:21:29 +00:00
|
|
|
int len;
|
|
|
|
FILE* f;
|
|
|
|
public:
|
2004-06-12 04:45:36 +00:00
|
|
|
MFILE();
|
|
|
|
~MFILE();
|
2004-04-15 00:21:29 +00:00
|
|
|
int open(const char* path, const char* mode);
|
|
|
|
int _putchar(char);
|
|
|
|
int puts(const char*);
|
2004-06-12 04:45:36 +00:00
|
|
|
int vprintf(const char* format, va_list);
|
2004-04-15 00:21:29 +00:00
|
|
|
int printf(const char* format, ...);
|
|
|
|
size_t write(const void *, size_t size, size_t nitems);
|
|
|
|
int close();
|
|
|
|
int flush();
|
|
|
|
long tell() const;
|
2004-06-12 04:45:36 +00:00
|
|
|
void get_buf(char*&, int&);
|
2004-06-17 21:37:59 +00:00
|
|
|
// get the MFILE's internal buffer and its length.
|
|
|
|
// The caller assumes ownership of the buffer and must free() it.
|
|
|
|
// The MFILE's buffer is set to empty
|
2004-04-15 00:21:29 +00:00
|
|
|
};
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
#endif
|