/*
* LogFile.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
#pragma once
#include <io.h>
#include <sol\File.h>
#include <sol\String.h>
namespace SOL {
class LogFile :public File {
private:
String fileName;
TCHAR* buffer;
size_t BUFFER_SIZE;
public:
LogFile(const TCHAR* filename, unsigned int buffSize=1024)
{
fileName = filename;
if (buffSize<= SIZE_1KB) {
buffSize = SIZE_1KB;
}
this->BUFFER_SIZE = buffSize;
buffer = new TCHAR[buffSize];
}
public:
~LogFile()
{
delete [] buffer;
}
public:
int printf(TCHAR* format,...)
{
va_list pos;
va_start(pos, format);
//vsprintf_s(this->buffer, this->BUFFER_SIZE, format, pos);
_vsnprintf(this->buffer, this->BUFFER_SIZE, format, pos);
va_end(pos);
int len = 0;
BOOL rc = create(fileName,
GENERIC_READ|GENERIC_WRITE, // access mode
FILE_SHARE_READ|FILE_SHARE_WRITE,// share mode
NULL, // security descriptor
OPEN_ALWAYS, // how to create
FILE_ATTRIBUTE_NORMAL, // file attributes
NULL); // attributes to copy
if (rc) {
// Move write-position to the end of this file.
seek(0, FILE_END);
len = write(buffer, strlen(buffer));
close();
}
return len;
}
/*
LogFile(const TCHAR* filename, unsigned int buffSize = 1024);
~LogFile();
int printf(TCHAR* format,...);
*/
};
}
|