2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// 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
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
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
|