5 #ifndef CVMFS_UTIL_FILE_GUARD_H_
6 #define CVMFS_UTIL_FILE_GUARD_H_
15 #ifdef CVMFS_NAMESPACE_GUARD
16 namespace CVMFS_NAMESPACE_GUARD {
31 , enabled_(state == kEnabled) {}
34 inline void Set(
const std::string &path) { path_ = path; Enable(); }
37 inline void Enable() { enabled_ =
true; }
38 inline void Disable() { enabled_ =
false; }
40 const std::string&
path()
const {
return path_; }
54 explicit inline FdGuard(
const int fd) : fd_(fd) { }
55 inline ~FdGuard() {
if (fd_ >= 0) close(fd_); }
56 int fd()
const {
return fd_; }
69 explicit inline FileGuard(FILE *file) : file_(file) { }
70 inline ~FileGuard() {
if (file_ != NULL) fclose(file_); }
71 const FILE *
file()
const {
return file_; }
78 #ifdef CVMFS_NAMESPACE_GUARD
82 #endif // CVMFS_UTIL_FILE_GUARD_H_
UnlinkGuard(const std::string &path, const InitialState state=kEnabled)
const std::string & path() const
const FILE * file() const
void Set(const std::string &path)