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)*/
template<typename TString> static bool GetNowDir(
TString& ARR_CStringDir, bool AB_DoKeepPrev=false)
template<typename TString> static bool
GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false)
{
// 디렉토리명이 _MAX_DIR 을 넘을 수 있다. 그래서 넉넉하게 곱하기 4 를 한다.
@ -5692,8 +5692,8 @@ namespace ZNsMain
resize(VL_PrevSize+VL_Length, ' ' );
return true ;
}/*
template<typename TString> static bool GetNowDir(
TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */
template<typename TString> static bool
GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */
static bool ChangeDir(ZTypCPCh APC_DirName)
{
@ -5715,8 +5715,8 @@ namespace ZNsMain
}/*
static bool MakeDir(const char* APC_PathName, mode_t mode=0744)*/
template<typename TString> static bool GetNowDir(
TString& ARR_CStringDir, bool AB_DoKeepPrev=false)
template<typename TString> static bool
GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false)
{
if(false==AB_DoKeepPrev)
{
@ -5724,12 +5724,14 @@ namespace ZNsMain
ARR_CStringDir.resize(CI_BuffSize+1, ' ');
char* VP_NowDir =
::getcwd((char*)ARR_CStringDir.data(), CI_BuffSize);
char* VP_NowDir = ::getcwd
((char*)ARR_CStringDir.data(), CI_BuffSize);
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)*/
@ -5748,8 +5750,8 @@ namespace ZNsMain
resize( VL_PrevSize+ZftLength(VP_NowDir), ' ');
return true ;
}/*
template<typename TString> static bool GetNowDir(
TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */
template<typename TString> static bool
GetNowDir(TString& ARR_CStringDir, bool AB_DoKeepPrev=false) */
static bool ChangeDir(const char* APC_DirName)
{
@ -7215,8 +7217,254 @@ namespace ZNsMain
#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;
}/*
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 std */
namespace ZNsMain*/
/*///////////////////////////////////////////////////////////////////////////////////////