mirror of https://github.com/aria2/aria2
Added printf and flush method to BufferedFile.
parent
e2d682e0c6
commit
b6b8cb005d
|
@ -35,6 +35,7 @@
|
|||
#include "BufferedFile.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <ostream>
|
||||
|
||||
#include "a2io.h"
|
||||
|
@ -44,6 +45,7 @@ namespace aria2 {
|
|||
|
||||
const std::string BufferedFile::READ = "rb";
|
||||
const std::string BufferedFile::WRITE = "wb";
|
||||
const std::string BufferedFile::APPEND = "ab";
|
||||
|
||||
BufferedFile::BufferedFile(const std::string& filename, const std::string& mode)
|
||||
{
|
||||
|
@ -51,6 +53,10 @@ BufferedFile::BufferedFile(const std::string& filename, const std::string& mode)
|
|||
open_ = fp_;
|
||||
}
|
||||
|
||||
BufferedFile::BufferedFile(FILE* fp)
|
||||
: fp_(fp), open_(true)
|
||||
{}
|
||||
|
||||
BufferedFile::~BufferedFile()
|
||||
{
|
||||
close();
|
||||
|
@ -118,4 +124,18 @@ size_t BufferedFile::transfer(std::ostream& out)
|
|||
return count;
|
||||
}
|
||||
|
||||
int BufferedFile::printf(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int r = vfprintf(fp_, format, ap);
|
||||
va_end(ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
int BufferedFile::flush()
|
||||
{
|
||||
return fflush(fp_);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -50,6 +50,7 @@ private:
|
|||
void good_state() const {}
|
||||
public:
|
||||
BufferedFile(const std::string& filename, const std::string& mode);
|
||||
BufferedFile(FILE* fp);
|
||||
~BufferedFile();
|
||||
// Returns true if file is opened and both ferror and feof returns
|
||||
// 0. Otherwise returns false.
|
||||
|
@ -69,10 +70,16 @@ public:
|
|||
// Convenient method. Read data to end of file and write them into
|
||||
// given stream. Returns written size.
|
||||
size_t transfer(std::ostream& out);
|
||||
// wrapper for fprintf
|
||||
int printf(const char* format, ...);
|
||||
// wrapper for fflush
|
||||
int flush();
|
||||
// Mode for reading
|
||||
static const std::string READ;
|
||||
// Mode for writing
|
||||
static const std::string WRITE;
|
||||
// Mode for append
|
||||
static const std::string APPEND;
|
||||
private:
|
||||
// Don't allow copying
|
||||
BufferedFile(const BufferedFile&);
|
||||
|
|
Loading…
Reference in New Issue