X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/3b5421b4c75f5c85b48cbb61bf22642ff52a6352..e5eebd12b7d7faf31210511dbf15edbda508ffc4:/apt-pkg/contrib/fileutl.cc diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index cc0363da5..77e846117 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: fileutl.cc,v 1.9 1998/10/20 02:39:28 jgg Exp $ +// $Id: fileutl.cc,v 1.13 1998/10/26 07:11:49 jgg Exp $ /* ###################################################################### File Utilities @@ -29,7 +29,7 @@ // CopyFile - Buffered copy of a file /*{{{*/ // --------------------------------------------------------------------- /* The caller is expected to set things so that failure causes erasure */ -bool CopyFile(FileFd From,FileFd To) +bool CopyFile(FileFd &From,FileFd &To) { if (From.IsOpen() == false || To.IsOpen() == false) return false; @@ -136,8 +136,8 @@ void SetCloseExec(int Fd,bool Close) /* */ void SetNonBlock(int Fd,bool Block) { - int Flags = fcntl(Fd,F_GETFL); - if (fcntl(Fd,F_SETFL,(Block == false)?0:O_NONBLOCK) != 0) + int Flags = fcntl(Fd,F_GETFL) & (~O_NONBLOCK); + if (fcntl(Fd,F_SETFL,Flags | ((Block == false)?0:O_NONBLOCK)) != 0) { cerr << "FATAL -> Could not set non-blocking flag " << strerror(errno) << endl; exit(100); @@ -153,8 +153,10 @@ bool WaitFd(int Fd) fd_set Set; FD_ZERO(&Set); FD_SET(Fd,&Set); + if (select(Fd+1,&Set,0,0,0) <= 0) return false; + return true; } /*}}}*/ @@ -193,8 +195,10 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms) if (iFd < 0) _error->Errno("open","Could not open file %s",FileName.c_str()); else + { this->FileName = FileName; - SetCloseExec(iFd,true); + SetCloseExec(iFd,true); + } } /*}}}*/ // FileFd::~File - Closes the file /*{{{*/