diff options
| author | Patrick Simianer <p@simianer.de> | 2012-03-13 09:24:47 +0100 | 
|---|---|---|
| committer | Patrick Simianer <p@simianer.de> | 2012-03-13 09:24:47 +0100 | 
| commit | ef6085e558e26c8819f1735425761103021b6470 (patch) | |
| tree | 5cf70e4c48c64d838e1326b5a505c8c4061bff4a /klm/util/file.hh | |
| parent | 10a232656a0c882b3b955d2bcfac138ce11e8a2e (diff) | |
| parent | dfbc278c1057555fda9312291c8024049e00b7d8 (diff) | |
merge with upstream
Diffstat (limited to 'klm/util/file.hh')
| -rw-r--r-- | klm/util/file.hh | 43 | 
1 files changed, 38 insertions, 5 deletions
| diff --git a/klm/util/file.hh b/klm/util/file.hh index d6cca41d..72c8ea76 100644 --- a/klm/util/file.hh +++ b/klm/util/file.hh @@ -1,8 +1,11 @@  #ifndef UTIL_FILE__  #define UTIL_FILE__ +#include <cstddef>  #include <cstdio> -#include <unistd.h> +#include <string> + +#include <stdint.h>  namespace util { @@ -52,22 +55,52 @@ class scoped_FILE {        file_ = to;      } +    std::FILE *release() { +      std::FILE *ret = file_; +      file_ = NULL; +      return ret; +    } +    private:      std::FILE *file_;  }; +// Open for read only.    int OpenReadOrThrow(const char *name); - +// Create file if it doesn't exist, truncate if it does.  Opened for write.     int CreateOrThrow(const char *name);  // Return value for SizeFile when it can't size properly.   -const off_t kBadSize = -1; -off_t SizeFile(int fd); +const uint64_t kBadSize = (uint64_t)-1; +uint64_t SizeFile(int fd); + +void ResizeOrThrow(int fd, uint64_t to);  void ReadOrThrow(int fd, void *to, std::size_t size); +std::size_t ReadOrEOF(int fd, void *to_void, std::size_t amount); +  void WriteOrThrow(int fd, const void *data_void, std::size_t size); -void RemoveOrThrow(const char *name); +void FSyncOrThrow(int fd); + +// Seeking +void SeekOrThrow(int fd, uint64_t off); +void AdvanceOrThrow(int fd, int64_t off); +void SeekEnd(int fd); + +std::FILE *FDOpenOrThrow(scoped_fd &file); + +class TempMaker { +  public: +    explicit TempMaker(const std::string &prefix); + +    int Make() const; + +    std::FILE *MakeFile() const; + +  private: +    std::string base_; +};  } // namespace util | 
