cleanup headers and especially #includes everywhere
[ntk/apt.git] / apt-pkg / contrib / fileutl.h
index 147535d..6fdea12 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <string>
 #include <vector>
+#include <set>
+#include <time.h>
 
 #include <zlib.h>
 
@@ -78,6 +80,7 @@ class FileFd
    bool Read(void *To,unsigned long long Size,unsigned long long *Actual = 0);
    char* ReadLine(char *To, unsigned long long const Size);
    bool Write(const void *From,unsigned long long Size);
+   bool static Write(int Fd, const void *From, unsigned long long Size);
    bool Seek(unsigned long long To);
    bool Skip(unsigned long long To);
    bool Truncate(unsigned long long To);
@@ -92,7 +95,7 @@ class FileFd
       And as the auto-conversation converts a 'unsigned long *' to a 'bool'
       instead of 'unsigned long long *' we need to provide this explicitely -
       otherwise applications magically start to fail… */
-   __deprecated bool Read(void *To,unsigned long long Size,unsigned long *Actual)
+   bool Read(void *To,unsigned long long Size,unsigned long *Actual) APT_DEPRECATED
    {
        unsigned long long R;
        bool const T = Read(To, Size, &R);
@@ -115,8 +118,8 @@ class FileFd
    
    // Simple manipulators
    inline int Fd() {return iFd;};
-   inline void Fd(int fd) {iFd = fd;};
-   __deprecated gzFile gzFd();
+   inline void Fd(int fd) { OpenDescriptor(fd, ReadWrite);};
+   gzFile gzFd() APT_DEPRECATED;
 
    inline bool IsOpen() {return iFd >= 0;};
    inline bool Failed() {return (Flags & Fail) == Fail;};
@@ -148,6 +151,10 @@ class FileFd
    private:
    FileFdPrivate* d;
    bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor);
+
+   // private helpers to set Fail flag and call _error->Error
+   bool FileFdErrno(const char* Function, const char* Description,...) APT_PRINTF(3) APT_COLD;
+   bool FileFdError(const char* Description,...) APT_PRINTF(2) APT_COLD;
 };
 
 bool RunScripts(const char *Cnf);
@@ -155,10 +162,12 @@ bool CopyFile(FileFd &From,FileFd &To);
 int GetLock(std::string File,bool Errors = true);
 bool FileExists(std::string File);
 bool RealFileExists(std::string File);
-bool DirectoryExists(std::string const &Path) __attrib_const;
+bool DirectoryExists(std::string const &Path) APT_CONST;
 bool CreateDirectory(std::string const &Parent, std::string const &Path);
 time_t GetModificationTime(std::string const &Path);
 
+std::string GetTempDir();
+
 /** \brief Ensure the existence of the given Path
  *
  *  \param Parent directory of the Path directory - a trailing
@@ -171,11 +180,14 @@ std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, std::string
                                        bool const &SortList, bool const &AllowNoExt=false);
 std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, std::vector<std::string> const &Ext,
                                        bool const &SortList);
+std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, bool SortList);
 std::string SafeGetCWD();
 void SetCloseExec(int Fd,bool Close);
 void SetNonBlock(int Fd,bool Block);
 bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
 pid_t ExecFork();
+pid_t ExecFork(std::set<int> keep_fds);
+void MergeKeepFdsFromConfiguration(std::set<int> &keep_fds);
 bool ExecWait(pid_t Pid,const char *Name,bool Reap = false);
 
 // File string manipulators
@@ -185,4 +197,7 @@ std::string flNoLink(std::string File);
 std::string flExtension(std::string File);
 std::string flCombine(std::string Dir,std::string File);
 
+// simple c++ glob
+std::vector<std::string> Glob(std::string const &pattern, int flags=0);
+
 #endif