commit 2025-08-30 22:39 add ZftLoadFile in ZCppMain/ZMainHeadEx.H

This commit is contained in:
2025-08-30 22:39:55 +09:00
parent 16218f91a0
commit a57179f7bb
3 changed files with 430 additions and 168 deletions

View File

@ -5652,8 +5652,8 @@ namespace ZNsMain
}/* }/*
static bool MakeDir(ZTypCPCh APC_PathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes=NULL)*/ static bool MakeDir(ZTypCPCh APC_PathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes=NULL)*/
template<typename TString> static bool GetNowDir( template<typename TString> static bool
TString& ARR_CStringDir, bool AB_DoKeepPrev=false) GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false)
{ {
// 디렉토리명이 _MAX_DIR 을 넘을 수 있다. 그래서 넉넉하게 곱하기 4 를 한다. // 디렉토리명이 _MAX_DIR 을 넘을 수 있다. 그래서 넉넉하게 곱하기 4 를 한다.
@ -5692,8 +5692,8 @@ namespace ZNsMain
resize(VL_PrevSize+VL_Length, ' ' ); resize(VL_PrevSize+VL_Length, ' ' );
return true ; return true ;
}/* }/*
template<typename TString> static bool GetNowDir( template<typename TString> static bool
TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */ GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */
static bool ChangeDir(ZTypCPCh APC_DirName) static bool ChangeDir(ZTypCPCh APC_DirName)
{ {
@ -5715,8 +5715,8 @@ namespace ZNsMain
}/* }/*
static bool MakeDir(const char* APC_PathName, mode_t mode=0744)*/ static bool MakeDir(const char* APC_PathName, mode_t mode=0744)*/
template<typename TString> static bool GetNowDir( template<typename TString> static bool
TString& ARR_CStringDir, bool AB_DoKeepPrev=false) GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false)
{ {
if(false==AB_DoKeepPrev) if(false==AB_DoKeepPrev)
{ {
@ -5724,12 +5724,14 @@ namespace ZNsMain
ARR_CStringDir.resize(CI_BuffSize+1, ' '); ARR_CStringDir.resize(CI_BuffSize+1, ' ');
char* VP_NowDir = char* VP_NowDir = ::getcwd
::getcwd((char*)ARR_CStringDir.data(), CI_BuffSize); ((char*)ARR_CStringDir.data(), CI_BuffSize);
if(VP_NowDir==0) return false; ARR_CStringDir. if(VP_NowDir==0) return false; ARR_CStringDir.
resize(ZNsMain::ZftLength(VP_NowDir), ' '); return true; resize(ZNsMain::ZftLength(VP_NowDir), ' ') ;
return true; /********************************/
}/* }/*
if(false==AB_DoKeepPrev)*/ if(false==AB_DoKeepPrev)*/
@ -5748,8 +5750,8 @@ namespace ZNsMain
resize( VL_PrevSize+ZftLength(VP_NowDir), ' '); resize( VL_PrevSize+ZftLength(VP_NowDir), ' ');
return true ; return true ;
}/* }/*
template<typename TString> static bool GetNowDir( template<typename TString> static bool
TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */ GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */
static bool ChangeDir(const char* APC_DirName) static bool ChangeDir(const char* APC_DirName)
{ {
@ -7215,8 +7217,254 @@ namespace ZNsMain
#endif //!_WIN #endif //!_WIN
/*#######################################################################################################
■ 아래 WriteFileRaw() 함수는 원래, ZtCStringBase<> 의 멤버 함수로 WriteFile() 라는 정적 멤버 함수였으나
이미 같은 이름의 비정적 멤버 함수가 있다 보니, 두 개 함수를 사용했을 때, g++ 4.4.7 에서 경고가 발생했
었다.
[sauron@localhost Donut_CPP]$ g++ -g -D_DEBUG -D_REENTRANT DonutTopCheck.cpp -o DonutTopCheck_D.exe -lpthread -I../../../my_CPP/CPP_Std/ -I../../../my_CPP/CPP_Net/ -I../../../my_CPP/CPP_Main/
DonutTopCheck.cpp: In static member function 'static void std::CSngtChecker::Exec()::HandleLine::Exec(CStringData&)':
DonutTopCheck.cpp:235: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
Donut.H:23376: note: candidate 1: static bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, const typename TTypeString::ZCTypeChars::TypeChar*, typename TTypeString::ZCTypeChars::TypeLength, bool, int) [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
Donut.H:23318: note: candidate 2: bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, bool, int) const [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
DonutTopCheck.cpp:235: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
Donut.H:23376: note: candidate 1: static bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, const typename TTypeString::ZCTypeChars::TypeChar*, typename TTypeString::ZCTypeChars::TypeLength, bool, int) [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
Donut.H:23318: note: candidate 2: bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, bool, int) const [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
그래서 WriteFileRaw() 로 이름을 바꾸고, std 의 전역 함수로 뺀 것이다. -- 2015-09-25 20:15:00
■ ZfWriteFileRaw() 로 이름을 바꾸었다. -- 2025-08-11 10:52
#######################################################################################################*/
static bool ZfWriteFileRaw /*##########################################################################*/
(
ZTypCPCh APC_FileName , ZTypCPCh APC_Content ,
ZTypLength AL_ContentLen, bool AB_DoAppend=true, int AI_RightMode=-1
)
/*#####################################################################################################*/
{
// int AI_RightMode = -1 은 리눅스에서만 쓴다.
#ifdef _WIN
HANDLE VH_File = ::CreateFileA(
APC_FileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
if(VH_File==INVALID_HANDLE_VALUE) return false;
if(AB_DoAppend==true)
::SetFilePointer(VH_File, 0, NULL, FILE_END); // 덧붙이는 경우라면 파일 포인터를 맨 끝으로 옮긴다.
else ::SetEndOfFile (VH_File ); // 덧붙이는 경우가 아니면 기존 내용을 지운다.
DWORD NumberOfBytesWritten = 0 ;
if(::WriteFile(VH_File, APC_Content, AL_ContentLen, &NumberOfBytesWritten, NULL)==FALSE)
{
::CloseHandle(VH_File); return false;
}/* }/*
namespace std */ if(::WriteFile(VH_File, APC_Content, AL_ContentLen, &NumberOfBytesWritten, NULL)==FALSE)*/
return ::CloseHandle(VH_File)==TRUE ;
#else // !defined(_WIN)
// 리눅스의 경우
using ZNsConst::ZNsLlioMode::AppendMake ;
using ZNsConst::ZNsLlioMode::WriteMakeCut;
const int CI_FileOpenErr = -1;
const int CI_FileOpenTag =
(
AI_RightMode<0 ?
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP :
AI_RightMode
) ;
//////////////////////////////////
int AH_FileDesc = CI_FileOpenErr ;
if(AB_DoAppend==true)
{
const bool CB_IsError = ////////////////////////////////////
(
(
AH_FileDesc = ::open
( APC_FileName, AppendMake, CI_FileOpenTag )
)==CI_FileOpenErr
);
////////////////////////////////////////////////////////////
if(CB_IsError) return false; ///////////////////////////////
}
else
{
const bool CB_IsError = ////////////////////////////////////
(
(
AH_FileDesc = ::open
( APC_FileName, WriteMakeCut, CI_FileOpenTag )
)==CI_FileOpenErr
);
//////////////////////////////////////////////////////////////
if(CB_IsError) return false; /////////////////////////////////
}/*
else*/
if(::write(AH_FileDesc, APC_Content, AL_ContentLen)<AL_ContentLen)
{
::close(AH_FileDesc); return false;
}/*
if(::write(AH_FileDesc, APC_Content, AL_ContentLen)<AL_ContentLen)*/
return ::close(AH_FileDesc)==0 ;
#endif //!defined(_WIN)
}/*
static bool ZfWriteFileRaw( #############################################################################
(
ZTypCPCh APC_FileName , ZTypCPCh APC_Content ,
ZTypLength AL_ContentLen, bool AB_DoAppend=true, int AI_RightMode=-1
)
/*#####################################################################################################*/
template<typename TStringData> bool ZftLoadFile /*############################*/
(
TStringData& ARR_SaveCStr , ZTypCPCChar APC_FileName ,
ZTypLength AL_LoadSize=0 , ZTypLength AL_Offset =0,
bool AB_DoAppend=true, ZTypLength AL_AddAllocSize=0
)
/*#############################################################################*/
{
// window 에서 _open() 함수는 \r\n 을 한 문자로 입력받음에 주의.
// AL_AddAllocSize 는 파일 APC_FileName 의 크기보다 더 큰 메모리가 필요할 경우에 전달한다.
if(AL_Offset<0) AL_Offset=0;
#ifndef _WIN
int AH_FileDesc = ::open
(APC_FileName, ZNsConst::ZNsLlioMode::Read);
if(AH_FileDesc == -1) return false;
// 파일 기술자를 파일의 맨 끝으로 이동시켜 파일 크기를 구한다.
off_t VL_LastPos = ::lseek
(AH_FileDesc, 0/*Offset*/, SEEK_END); // 실패시 -1
if(VL_LastPos == -1 || VL_LastPos<=AL_Offset)
{
::close(AH_FileDesc); return false;
}/*
if(VL_LastPos == -1 || VL_LastPos<=AL_Offset)*/
VL_LastPos -= AL_Offset;
if(AL_LoadSize>0 && VL_LastPos>AL_LoadSize)
{ VL_LastPos=AL_LoadSize; }
/*=======================================*/
::lseek(AH_FileDesc, AL_Offset, SEEK_SET);
ZTypLength VL_PrevSize =
(AB_DoAppend ? ARR_SaveCStr.size() : 0);
ARR_SaveCStr.resize //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(
VL_PrevSize+VL_LastPos-AL_Offset+AL_AddAllocSize, ' '
);
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// 윈도우에서 read() 함수는 \r\n 을 한 문자로 읽어들이므로 주의
ZTypLength VL_ReadSize = 0 ;
ZTypCPChar VP_CopyStart =
const_cast<ZTypPChar>(ARR_SaveCStr.c_str())+VL_PrevSize ;
if((VL_ReadSize = read(AH_FileDesc, VP_CopyStart, VL_LastPos))<0)
{
ARR_SaveCStr.resize(VL_PrevSize, ' '); ::close(AH_FileDesc); return true;
}
/*/////////////////////////////////////////////////////////////*/
ARR_SaveCStr.resize(VL_PrevSize+VL_ReadSize, ' ');
::close(AH_FileDesc); return true; /*:::::::::::*/
#else //defined(_WIN)
ZTypLength VL_PrevSize = (AB_DoAppend ? ARR_SaveCStr.size() : 0) ;
HANDLE VH_File = ::CreateFileA /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
(
APC_FileName ,
GENERIC_READ ,
FILE_SHARE_READ , // 공유모드: 이미 열려 있는 파일을 열 수 있게 한다.
NULL ,
OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL, // 반드시 단독으로 사용되는 플래그
NULL
);
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
if(INVALID_HANDLE_VALUE==VH_File) return false;
DWORD dwRead2 = 0 ;
DWORD dwRead =
::SetFilePointer(VH_File, 0, NULL, FILE_END);
dwRead -= AL_Offset;
if(AL_LoadSize>0 && dwRead>AL_LoadSize)
{ dwRead=AL_LoadSize; }
ARR_SaveCStr.resize //>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(
VL_PrevSize + dwRead, ' '
);
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
::SetFilePointer(VH_File, AL_Offset, NULL, FILE_BEGIN);
ZTypCPChar VP_CopyStart =
const_cast<ZTypPChar>(ARR_SaveCStr.c_str())+VL_PrevSize ;
if(::ReadFile(VH_File, (LPVOID)VP_CopyStart, dwRead, &dwRead2, NULL)==FALSE)
{
ARR_SaveCStr.resize(VL_PrevSize+dwRead2, ' ');
CloseHandle(VH_File); return false;
}
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
::CloseHandle(VH_File);
if(dwRead2>0)
ARR_SaveCStr.resize(VL_PrevSize+dwRead2, ' ');
else ARR_SaveCStr.resize(VL_PrevSize , ' ');
return true;
#endif //defined(_WIN)
}/*
template<typename TStringData> bool ZftLoadFile ################################
(
TStringData& ARR_SaveCStr , ZTypCPCChar APC_FileName ,
ZTypLength AL_LoadSize=0 , ZTypLength AL_Offset =0,
bool AB_DoAppend=true, ZTypLength AL_AddAllocSize=0
)
###############################################################################*/
}/*
namespace ZNsMain*/
/*/////////////////////////////////////////////////////////////////////////////////////// /*///////////////////////////////////////////////////////////////////////////////////////

View File

@ -22,116 +22,6 @@ using namespace ZNsMain;
namespace ZNsMain namespace ZNsMain
{ {
/*#######################################################################################################
■ 아래 WriteFileRaw() 함수는 원래, ZtCStringBase<> 의 멤버 함수로 WriteFile() 라는 정적 멤버 함수였으나
이미 같은 이름의 비정적 멤버 함수가 있다 보니, 두 개 함수를 사용했을 때, g++ 4.4.7 에서 경고가 발생했
었다.
[sauron@localhost Donut_CPP]$ g++ -g -D_DEBUG -D_REENTRANT DonutTopCheck.cpp -o DonutTopCheck_D.exe -lpthread -I../../../my_CPP/CPP_Std/ -I../../../my_CPP/CPP_Net/ -I../../../my_CPP/CPP_Main/
DonutTopCheck.cpp: In static member function 'static void std::CSngtChecker::Exec()::HandleLine::Exec(CStringData&)':
DonutTopCheck.cpp:235: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
Donut.H:23376: note: candidate 1: static bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, const typename TTypeString::ZCTypeChars::TypeChar*, typename TTypeString::ZCTypeChars::TypeLength, bool, int) [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
Donut.H:23318: note: candidate 2: bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, bool, int) const [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
DonutTopCheck.cpp:235: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
Donut.H:23376: note: candidate 1: static bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, const typename TTypeString::ZCTypeChars::TypeChar*, typename TTypeString::ZCTypeChars::TypeLength, bool, int) [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
Donut.H:23318: note: candidate 2: bool std::ZtCStringBase<TTypCh, TAlloc, TAllocSize, TTypeString>::WriteFile(const TTypCh*, bool, int) const [with TTypCh = char, TAlloc = std::ZtCAllocClass<char>, TAllocSize = std::ZtCAllocMemSize<char>, TTypeString = std::ZNsType::ZtCTypeStringBase<char, std::ZtCAllocClass<char>, std::ZtCAllocMemSize<char>, long int>]
그래서 WriteFileRaw() 로 이름을 바꾸고, std 의 전역 함수로 뺀 것이다. -- 2015-09-25 20:15:00
■ ZfWriteFileRaw() 로 이름을 바꾸었다. -- 2025-08-11 10:52
#######################################################################################################*/
static bool ZfWriteFileRaw /*##########################################################################*/
(
ZTypCPCh APC_FileName , ZTypCPCh APC_Content ,
ZTypLength AL_ContentLen, bool AB_DoAppend=true, int AI_RightMode=-1
)
/*#####################################################################################################*/
{
// int AI_RightMode = -1 은 리눅스에서만 쓴다.
#ifdef _WIN
HANDLE VH_File = ::CreateFileA(
APC_FileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
if(VH_File==INVALID_HANDLE_VALUE) return false;
if(AB_DoAppend==true)
::SetFilePointer(VH_File, 0, NULL, FILE_END); // 덧붙이는 경우라면 파일 포인터를 맨 끝으로 옮긴다.
else ::SetEndOfFile (VH_File ); // 덧붙이는 경우가 아니면 기존 내용을 지운다.
DWORD NumberOfBytesWritten = 0 ;
if(::WriteFile(VH_File, APC_Content, AL_ContentLen, &NumberOfBytesWritten, NULL)==FALSE)
{
::CloseHandle(VH_File); return false;
}/*
if(::WriteFile(VH_File, APC_Content, AL_ContentLen, &NumberOfBytesWritten, NULL)==FALSE)*/
return ::CloseHandle(VH_File)==TRUE ;
#else // !defined(_WIN)
// 리눅스의 경우
using ZNsConst::ZNsLlioMode::AppendMake ;
using ZNsConst::ZNsLlioMode::WriteMakeCut;
const int CI_FileOpenTag=(AI_RightMode<0 ? S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP : AI_RightMode ) ;
const int CI_FileOpenErr=-1;
int AH_FileDesc = CI_FileOpenErr ;
if(AB_DoAppend==true)
{
const bool CB_IsError = ////////////////////////////////////
(
(
AH_FileDesc = ::open
( APC_FileName, AppendMake, CI_FileOpenTag )
)==CI_FileOpenErr
);
////////////////////////////////////////////////////////////
if(CB_IsError) return false; ///////////////////////////////
}
else
{
const bool CB_IsError = ////////////////////////////////////
(
(
AH_FileDesc = ::open
( APC_FileName, WriteMakeCut, CI_FileOpenTag )
)==CI_FileOpenErr
);
//////////////////////////////////////////////////////////////
if(CB_IsError) return false; /////////////////////////////////
}/*
else*/
if(::write(AH_FileDesc, APC_Content, AL_ContentLen)<AL_ContentLen)
{
::close(AH_FileDesc); return false;
}/*
if(::write(AH_FileDesc, APC_Content, AL_ContentLen)<AL_ContentLen)*/
return ::close(AH_FileDesc)==0 ;
#endif //!defined(_WIN)
}/*
static bool ZfWriteFileRaw( #############################################################################
(
ZTypCPCh APC_FileName , ZTypCPCh APC_Content ,
ZTypLength AL_ContentLen, bool AB_DoAppend=true, int AI_RightMode=-1
)
/*#####################################################################################################*/
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
■ 문자열을 편하게 다루기 위해서 ZtCStringBase 클래스 템플릿을 설계하였는데 ■ 문자열을 편하게 다루기 위해서 ZtCStringBase 클래스 템플릿을 설계하였는데
@ -5383,6 +5273,14 @@ namespace ZNsMain
// window 에서 _open() 함수는 \r\n 을 한 문자로 입력받음에 주의. // window 에서 _open() 함수는 \r\n 을 한 문자로 입력받음에 주의.
// AL_AddAllocSize 는 파일 APC_FileName 의 크기보다 더 큰 메모리가 필요할 경우에 전달한다. // AL_AddAllocSize 는 파일 APC_FileName 의 크기보다 더 큰 메모리가 필요할 경우에 전달한다.
if(sizeof(TypeChar) > 1 )
{
// not supported
return false;
}/*
if(sizeof(TypeChar) > 1 )*/
#ifndef _WIN #ifndef _WIN
int AH_FileDesc = ::open int AH_FileDesc = ::open
@ -5392,17 +5290,17 @@ namespace ZNsMain
// 파일 기술자를 파일의 맨 끝으로 이동시켜 파일크기를 구한다. // 파일 기술자를 파일의 맨 끝으로 이동시켜 파일크기를 구한다.
off_t VL_Offset = ::lseek off_t VL_LastPos = ::lseek
(AH_FileDesc, 0/*Offset*/, SEEK_END); // 실패시 -1 (AH_FileDesc, 0/*Offset*/, SEEK_END); // 실패시 -1
if(VL_Offset== -1) if(VL_LastPos== -1)
{ {
::close(AH_FileDesc); return false; ::close(AH_FileDesc); return false;
}/* }/*
if(VL_Offset== -1)*/ if(VL_LastPos== -1)*/
if(AL_LoadSize>0 && VL_Offset>AL_LoadSize) if(AL_LoadSize>0 && VL_LastPos>AL_LoadSize)
{ VL_Offset=AL_LoadSize; } { VL_LastPos=AL_LoadSize; }
// 파일 기술자를 다시 처음으로 옮긴다. // 파일 기술자를 다시 처음으로 옮긴다.
::lseek(AH_FileDesc, 0/*Offset*/, SEEK_SET); ::lseek(AH_FileDesc, 0/*Offset*/, SEEK_SET);
@ -5412,7 +5310,7 @@ namespace ZNsMain
ReAlloc //>>>>>>>>>>>>>>>>>>>>>>>> ReAlloc //>>>>>>>>>>>>>>>>>>>>>>>>
( (
VL_PrevSize+VL_Offset+AL_AddAllocSize, VL_PrevSize+VL_LastPos+AL_AddAllocSize,
AB_DoAppend AB_DoAppend
); );
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -5421,7 +5319,7 @@ namespace ZNsMain
TypeLength VL_ReadSize=0; TypeLength VL_ReadSize=0;
if((VL_ReadSize = read(AH_FileDesc, mpc_Data+VL_PrevSize, VL_Offset))<0) if((VL_ReadSize = read(AH_FileDesc, mpc_Data+VL_PrevSize, VL_LastPos))<0)
{ {
mpc_Data[ml_UseLen=VL_PrevSize]=0; ::close(AH_FileDesc); return false; mpc_Data[ml_UseLen=VL_PrevSize]=0; ::close(AH_FileDesc); return false;
}/* }/*
@ -5434,9 +5332,8 @@ namespace ZNsMain
#else //defined(_WIN) #else //defined(_WIN)
TypeLength VL_PrevSize=AB_DoAppend ? ml_UseLen : 0 ; TypeLength VL_PrevSize = (AB_DoAppend ? ml_UseLen : 0) ;
HANDLE VH_File = ::CreateFile /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
HANDLE VH_File = ::CreateFile /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
( (
APC_FileName , APC_FileName ,
GENERIC_READ , GENERIC_READ ,
@ -5446,7 +5343,7 @@ namespace ZNsMain
FILE_ATTRIBUTE_NORMAL, // 반드시 단독으로 사용되는 플래그 FILE_ATTRIBUTE_NORMAL, // 반드시 단독으로 사용되는 플래그
NULL NULL
); );
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
if(INVALID_HANDLE_VALUE==VH_File) return false; if(INVALID_HANDLE_VALUE==VH_File) return false;
@ -5461,19 +5358,17 @@ namespace ZNsMain
::SetFilePointer(VH_File, 0, NULL, FILE_BEGIN); ::SetFilePointer(VH_File, 0, NULL, FILE_BEGIN);
if(::ReadFile(VH_File, mpc_Data+VL_PrevSize, dwRead, &dwRead2, NULL)==FALSE) if(::ReadFile(VH_File, (LPVOID)(mpc_Data+VL_PrevSize), dwRead, &dwRead2, NULL)==FALSE)
{ {
Invalidate(); CloseHandle(VH_File); return false; Invalidate(VL_PrevSize); CloseHandle(VH_File); return false;
}/* }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
::CloseHandle(VH_File); ::CloseHandle(VH_File);
if(dwRead2>0) if(dwRead2>0)
mpc_Data[ml_UseLen=VL_PrevSize+dwRead2]=0; mpc_Data[ml_UseLen=VL_PrevSize+dwRead2]=0;
else else mpc_Data[ml_UseLen=VL_PrevSize ]=0;
Invalidate();
/*else*/
return true; return true;
@ -5519,6 +5414,12 @@ namespace ZNsMain
///////////////////////////////////////////////////////////////////////////////////////////////////////*/ ///////////////////////////////////////////////////////////////////////////////////////////////////////*/
if(sizeof(TypeChar) > 1 )
{
return 0; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
const int CI_SearchNo = -1 ; // 찾지 못한 상태. const int CI_SearchNo = -1 ; // 찾지 못한 상태.
if(AL_SearchLen<1 || AL_WantSearchCnt<1) return CI_SearchNo; if(AL_SearchLen<1 || AL_WantSearchCnt<1) return CI_SearchNo;
@ -5530,7 +5431,8 @@ namespace ZNsMain
TypeLength VL_Offset = ::lseek(AH_FileDesc, 0, SEEK_CUR); TypeLength VL_Offset = ::lseek(AH_FileDesc, 0, SEEK_CUR);
TypeLength VL_InnerOffset= 0; TypeLength VL_InnerOffset= 0;
ZCStringBase VO_CStringBuff; VO_CStringBuff.ReAlloc(VL_LoadLen+AL_SearchLen-1); ZCStringBase VO_CStringBuff; VO_CStringBuff.
ReAlloc( VL_LoadLen+AL_SearchLen-1 ) ;
while /*#######################################################*/ while /*#######################################################*/
( (
@ -5610,6 +5512,12 @@ namespace ZNsMain
LPOVERLAPPED lpOverlapped =NULL LPOVERLAPPED lpOverlapped =NULL
/*/////////*/ ) ///////////////////////////////////////////////*/ /*/////////*/ ) ///////////////////////////////////////////////*/
{ {
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(AL_SearchLen<1 || AL_WantSearchCnt<1) return -1; if(AL_SearchLen<1 || AL_WantSearchCnt<1) return -1;
DWORD VL_ReadCnt =0; DWORD VL_ReadCnt =0;
@ -5620,7 +5528,8 @@ namespace ZNsMain
TypeLength VL_PrevOffset =VL_Offset; TypeLength VL_PrevOffset =VL_Offset;
TypeLength VL_InnerOffset=0; TypeLength VL_InnerOffset=0;
ZCStringBase VO_CStringBuff; VO_CStringBuff.ReAlloc(VL_LoadLen+AL_SearchLen-1); ZCStringBase VO_CStringBuff; VO_CStringBuff.
ReAlloc(VL_LoadLen+AL_SearchLen-1) ;
while(true) while(true)
{ {
@ -5701,6 +5610,12 @@ namespace ZNsMain
LPOVERLAPPED lpOverlapped =NULL LPOVERLAPPED lpOverlapped =NULL
/*/////////*/ ) ///////////////////////////////////////////////*/ /*/////////*/ ) ///////////////////////////////////////////////*/
{ {
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
HANDLE VH_File = ::CreateFile( HANDLE VH_File = ::CreateFile(
APC_FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); APC_FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
@ -5730,6 +5645,12 @@ namespace ZNsMain
) )
////////////////////////////////// //////////////////////////////////
{ {
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
int AH_FileDesc = ::open(APC_FileName,O_RDONLY); int AH_FileDesc = ::open(APC_FileName,O_RDONLY);
if(AH_FileDesc<0) return -1; if(AH_FileDesc<0) return -1;
@ -5756,6 +5677,13 @@ namespace ZNsMain
) )
/*#############################################################################*/ /*#############################################################################*/
{ {
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
// SearchFileOffset() 함수와 역할은 비슷하나 뒤에서 앞으로 접근한다. // SearchFileOffset() 함수와 역할은 비슷하나 뒤에서 앞으로 접근한다.
if(AL_SearchLen<1 || AL_WantSearchCnt<1) return -1; if(AL_SearchLen<1 || AL_WantSearchCnt<1) return -1;
@ -5851,6 +5779,12 @@ namespace ZNsMain
{ {
// SearchFileOffset() 함수와 역할은 비슷하나 뒤에서 앞으로 접근한다. // SearchFileOffset() 함수와 역할은 비슷하나 뒤에서 앞으로 접근한다.
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(AL_SearchLen<1 || AL_WantSearchCnt<1) return -1; if(AL_SearchLen<1 || AL_WantSearchCnt<1) return -1;
TypeLength VL_LoadLen =(((AL_SearchLen-1)/BUFSIZ)+1)*BUFSIZ; TypeLength VL_LoadLen =(((AL_SearchLen-1)/BUFSIZ)+1)*BUFSIZ;
@ -5936,6 +5870,12 @@ namespace ZNsMain
bool LoadFilePart( bool LoadFilePart(
TypeCharC* APC_FileName, TypeLength AL_LoadSize, TypeLength AL_Offset=0) TypeCharC* APC_FileName, TypeLength AL_LoadSize, TypeLength AL_Offset=0)
{ {
if(sizeof(TypeChar) > 1 )
{
return false; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
#ifndef _WIN #ifndef _WIN
int AH_FileDesc = ::open int AH_FileDesc = ::open
@ -5982,6 +5922,12 @@ namespace ZNsMain
TypeLength ReadFile(int AH_FileDesc, TypeLength AL_ReadByte) TypeLength ReadFile(int AH_FileDesc, TypeLength AL_ReadByte)
{ {
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
TypeLength VL_PrevLen = ml_UseLen ; TypeLength VL_PrevLen = ml_UseLen ;
TypeLength VL_ReadCnt = 0 ; TypeLength VL_ReadCnt = 0 ;
@ -6001,6 +5947,12 @@ namespace ZNsMain
TypeLength ReadFile(FILE* AP_HFile, TypeLength AL_ReadByte) TypeLength ReadFile(FILE* AP_HFile, TypeLength AL_ReadByte)
{ {
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
TypeLength VL_PrevLen = ml_UseLen ; TypeLength VL_PrevLen = ml_UseLen ;
TypeLength VL_ReadCnt = 0 ; TypeLength VL_ReadCnt = 0 ;
@ -6028,6 +5980,12 @@ namespace ZNsMain
) )
/*####################################################*/ /*####################################################*/
{ {
if(sizeof(TypeChar) > 1 )
{
return 0; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(AL_SearchLen<1 || AL_SearchCnt<1) return 0; if(AL_SearchLen<1 || AL_SearchCnt<1) return 0;
TypeLength VL_ReadSize ; TypeLength VL_ReadSize ;
@ -6082,6 +6040,12 @@ namespace ZNsMain
) )
/*####################################################*/ /*####################################################*/
{ {
if(sizeof(TypeChar) > 1 )
{
return 0; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(AL_SearchLen<1 || AL_SearchCnt<1) return 0; if(AL_SearchLen<1 || AL_SearchCnt<1) return 0;
TypeLength VL_ReadSize ; TypeLength VL_ReadSize ;
@ -6138,6 +6102,12 @@ namespace ZNsMain
) )
/*#####################*/ /*#####################*/
{ {
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
#ifdef _WIN #ifdef _WIN
#define MyCloseFleHandle CloseHandle #define MyCloseFleHandle CloseHandle
@ -6195,6 +6165,12 @@ namespace ZNsMain
//////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////*/
if(sizeof(TypeChar) > 1 )
{
return -1; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
TypeLength VL_PrevLen=ml_UseLen; TypeLength VL_PrevLen=ml_UseLen;
DWORD VL_ReadCnt=0 ; DWORD VL_ReadCnt=0 ;
@ -6233,6 +6209,12 @@ namespace ZNsMain
) )
/*#############################################################################*/ /*#############################################################################*/
{ {
if(sizeof(TypeChar) > 1 )
{
return 0; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(AL_SearchLen<1 || AL_SearchCnt<1) return 0; if(AL_SearchLen<1 || AL_SearchCnt<1) return 0;
DWORD VL_ReadSize ; DWORD VL_ReadSize ;
@ -6297,6 +6279,12 @@ namespace ZNsMain
bool WriteFile(HANDLE AH_FileHandle) const bool WriteFile(HANDLE AH_FileHandle) const
{ {
if(sizeof(TypeChar) > 1 )
{
return false; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(ml_UseLen<1) return true; if(ml_UseLen<1) return true;
/*////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////
@ -6327,6 +6315,12 @@ namespace ZNsMain
bool WriteFile(int AH_FileDesc) const bool WriteFile(int AH_FileDesc) const
{ {
if(sizeof(TypeChar) > 1 )
{
return false; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(ml_UseLen<1) return true; TypeLength VUL_AllSize=ml_UseLen; if(ml_UseLen<1) return true; TypeLength VUL_AllSize=ml_UseLen;
return ::write( return ::write(
@ -6336,6 +6330,12 @@ namespace ZNsMain
bool WriteFile(FILE* AP_HFile) const bool WriteFile(FILE* AP_HFile) const
{ {
if(sizeof(TypeChar) > 1 )
{
return false; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
if(ml_UseLen<1) return true; TypeLength VUL_AllSize=ml_UseLen; if(ml_UseLen<1) return true; TypeLength VUL_AllSize=ml_UseLen;
return ::fwrite( return ::fwrite(
@ -6347,14 +6347,20 @@ namespace ZNsMain
{ {
// int AI_RightMode 은 리눅스에서만 쓴다. // int AI_RightMode 은 리눅스에서만 쓴다.
if(sizeof(TypeChar) > 1 )
{
return false; // not supported
}/*
if(sizeof(TypeChar) > 1 )*/
#ifdef _WIN #ifdef _WIN
HANDLE VH_File=::CreateFile HANDLE VH_File = ::CreateFileA
( (
APC_FileName, GENERIC_WRITE, FILE_SHARE_WRITE , APC_FileName, GENERIC_WRITE, FILE_SHARE_WRITE ,
NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL, NULL NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL, NULL
); );
/////////////////////////// //////////////////////////////
if(VH_File==INVALID_HANDLE_VALUE) return false; if(VH_File==INVALID_HANDLE_VALUE) return false;
@ -6387,8 +6393,11 @@ namespace ZNsMain
int AH_FileDesc ; int AH_FileDesc ;
const int CI_FileOpenErr = -1 ; const int CI_FileOpenErr = -1 ;
const int CI_FileOpenTag = const int CI_FileOpenTag =
(AI_RightMode<0 ? S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP : AI_RightMode ) ; (
AI_RightMode<0 ?
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP :
AI_RightMode
) ; ///////////////////////
if(AB_DoAppend==true) if(AB_DoAppend==true)
{ {
if((AH_FileDesc = ::open( APC_FileName, ZNsConst::ZNsLlioMode::AppendMake , CI_FileOpenTag))==CI_FileOpenErr) if((AH_FileDesc = ::open( APC_FileName, ZNsConst::ZNsLlioMode::AppendMake , CI_FileOpenTag))==CI_FileOpenErr)
@ -6717,10 +6726,8 @@ namespace ZNsMain
{ {
TypeLength VL_MatchLen=0; return FindPosType ////// TypeLength VL_MatchLen=0; return FindPosType //////
( (
APC_Origin APC_Origin , AR_SearchList,
, AR_SearchList GetLength(APC_Origin), RR(VL_MatchLen)
, GetLength(APC_Origin)
, RR(VL_MatchLen)
); );
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
}/* }/*
@ -6765,8 +6772,7 @@ namespace ZNsMain
{ {
if(++VL_SearchOffset==AL_SearchLen) if(++VL_SearchOffset==AL_SearchLen)
{++VL_SearchCount; VL_SearchOffset=0;} {++VL_SearchCount; VL_SearchOffset=0;}
} }else {/***************/ VL_SearchOffset=0;}
else {VL_SearchOffset=0;}
}/* }/*
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
@ -6798,13 +6804,21 @@ namespace ZNsMain
TypeLength GetFindCnt(const ZCStringBase& rhs)*/ TypeLength GetFindCnt(const ZCStringBase& rhs)*/
static bool DoHave( static bool DoHave ////////////////////////////////////////////////////////////////
TypeCharC* APC_Origin, TypeCharC* APC_FindChars, TypeLength AL_OriginLen, TypeLength AL_FindLen, TypeLength AL_StartPos=0) (
TypeCharC* APC_Origin , TypeCharC* APC_FindChars,
TypeLength AL_OriginLen, TypeLength AL_FindLen , TypeLength AL_StartPos=0
)
///////////////////////////////////////////////////////////////////////////////////
{ {
return FindPos(APC_Origin, APC_FindChars, AL_OriginLen, AL_FindLen, AL_StartPos)>=0; return FindPos(APC_Origin, APC_FindChars, AL_OriginLen, AL_FindLen, AL_StartPos)>=0;
}/* }/*
static bool DoHave( static bool DoHave ////////////////////////////////////////////////////////////////
TypeCharC* APC_Origin, TypeCharC* APC_FindChars, TypeLength AL_OriginLen, TypeLength AL_FindLen, TypeLength AL_StartPos=0)*/ (
TypeCharC* APC_Origin , TypeCharC* APC_FindChars,
TypeLength AL_OriginLen, TypeLength AL_FindLen , TypeLength AL_StartPos=0
)
/////////////////////////////////////////////////////////////////////////////////*/
static bool DoHave(TypeCharC* APC_Origin, TypeCharC* APC_FindChars, TypeLength AL_StartPos=0) static bool DoHave(TypeCharC* APC_Origin, TypeCharC* APC_FindChars, TypeLength AL_StartPos=0)
{ {