linux move 实现

来源:互联网 发布:三级数据库题型 编辑:程序博客网 时间:2024/06/03 13:24
/**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;}
原创粉丝点击