/**
author : 方福建
**/
BOOL PuOsSafeMoveFile(LPCSTR pchSrcFileName, LPCSTR pchDstFileName)
{
if(0==strcmp(pchSrcFileName,pchDstFileName))
return TRUE;
int fin,fout;
fin=open(pchSrcFileName,O_RDONLY);
if(fin<0)
return FALSE;
umask(~0777);
fout=open(pchDstFileName,O_WRONLY|O_CREAT|O_TRUNC,0777);
if(fout<0)
{
PuOsPrintf( PU_LOGLEVEL_EXCEPTION, FALSE, PU_MODULE_OSAPI,"PuOsSafeMoveFile open error\n");
close(fin);
return FALSE;
}
char aszBuf[4096]={0};
int nSize;
while((nSize=read(fin,aszBuf,4096))>0)
{
if(write(fout,aszBuf,nSize)!=nSize)
{
PuOsPrintf( PU_LOGLEVEL_EXCEPTION, FALSE, PU_MODULE_OSAPI,"PuOsSafeMoveFile write error\n");
close(fin);
close(fout);
return FALSE;
}
memset(aszBuf,0,sizeof(aszBuf));
}
if(nSize<0)
{
PuOsPrintf( PU_LOGLEVEL_EXCEPTION, FALSE, PU_MODULE_OSAPI,"PuOsSafeMoveFile read error\n");
close(fin);
close(fout);
return FALSE;
}
remove(pchSrcFileName);
close(fin);
close(fout);
return TRUE;
}
linux move 实现
最新推荐文章于 2023-04-13 10:32:58 发布