Skip to content

Commit

Permalink
Added file_exists_nonempty() helper function
Browse files Browse the repository at this point in the history
file_exists_nonempty() returns true if file exists
AND is nonempty.

Signed-off-by: James Yonan <[email protected]>
  • Loading branch information
jamesyonan authored and Jenkins-dev committed Dec 30, 2024
1 parent 85e7b38 commit 0571a11
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions openvpn/common/stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ inline bool file_exists(const std::string &filename)
return ::stat(filename.c_str(), &buffer) == 0;
}

/**
* Check if file exists AND is nonempty.
*
* @param filename File to check.
* @return true if file exists AND is nonempty.
*/
inline bool file_exists_nonempty(const std::string &filename)
{
if (filename.empty())
return false;
struct stat s;
if (::stat(filename.c_str(), &s) != 0)
return false;
return s.st_size > 0;
}

// Return true if dirname is a directory
inline bool is_directory(const std::string &pathname, const bool follow_symlinks = false)
{
Expand Down

0 comments on commit 0571a11

Please sign in to comment.