Move everything to negative errno return types (#1499)
Some checks failed
CodeQL / Analyze (push) Has been cancelled
mkdocs / deploy (push) Has been cancelled

This commit is contained in:
trapexit 2025-07-25 17:53:48 -05:00 • committed by GitHub
parent 2b500f194a
commit e8cd74cab0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 5952 additions and 5843 deletions

View file

@ -16,6 +16,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "fs_statvfs_cache.hpp"
#include "fs_statvfs.hpp"
#include "statvfs_util.hpp"
@ -42,104 +44,98 @@ static uint64_t g_timeout = 0;
static statvfs_cache g_cache;
static pthread_mutex_t g_cache_lock = PTHREAD_MUTEX_INITIALIZER;
namespace l
static
uint64_t
_get_time(void)
{
static
uint64_t
get_time(void)
{
uint64_t rv;
uint64_t rv;
rv = ::time(NULL);
rv = ::time(NULL);
return rv;
}
return rv;
}
namespace fs
uint64_t
fs::statvfs_cache_timeout(void)
{
uint64_t
statvfs_cache_timeout(void)
{
return g_timeout;
}
void
statvfs_cache_timeout(const uint64_t timeout_)
{
g_timeout = timeout_;
}
int
statvfs_cache(const char *path_,
struct statvfs *st_)
{
int rv;
Element *e;
uint64_t now;
if(g_timeout == 0)
return fs::statvfs(path_,st_);
rv = 0;
now = l::get_time();
mutex_lock(&g_cache_lock);
e = &g_cache[path_];
if((now - e->time) > g_timeout)
{
e->time = now;
rv = fs::statvfs(path_,&e->st);
}
*st_ = e->st;
mutex_unlock(&g_cache_lock);
return rv;
}
int
statvfs_cache_readonly(const std::string &path_,
bool *readonly_)
{
int rv;
struct statvfs st;
rv = fs::statvfs_cache(path_.c_str(),&st);
if(rv == 0)
*readonly_ = StatVFS::readonly(st);
return rv;
}
int
statvfs_cache_spaceavail(const std::string &path_,
uint64_t *spaceavail_)
{
int rv;
struct statvfs st;
rv = fs::statvfs_cache(path_.c_str(),&st);
if(rv == 0)
*spaceavail_ = StatVFS::spaceavail(st);
return rv;
}
int
statvfs_cache_spaceused(const std::string &path_,
uint64_t *spaceused_)
{
int rv;
struct statvfs st;
rv = fs::statvfs_cache(path_.c_str(),&st);
if(rv == 0)
*spaceused_ = StatVFS::spaceused(st);
return rv;
}
return g_timeout;
}
void
fs::statvfs_cache_timeout(const uint64_t timeout_)
{
g_timeout = timeout_;
}
int
fs::statvfs_cache(const char *path_,
struct statvfs *st_)
{
int rv;
Element *e;
uint64_t now;
if(g_timeout == 0)
return fs::statvfs(path_,st_);
rv = 0;
now = ::_get_time();
mutex_lock(&g_cache_lock);
e = &g_cache[path_];
if((now - e->time) > g_timeout)
{
e->time = now;
rv = fs::statvfs(path_,&e->st);
}
*st_ = e->st;
mutex_unlock(&g_cache_lock);
return rv;
}
int
fs::statvfs_cache_readonly(const std::string &path_,
bool *readonly_)
{
int rv;
struct statvfs st;
rv = fs::statvfs_cache(path_.c_str(),&st);
if(rv == 0)
*readonly_ = StatVFS::readonly(st);
return rv;
}
int
fs::statvfs_cache_spaceavail(const std::string &path_,
uint64_t *spaceavail_)
{
int rv;
struct statvfs st;
rv = fs::statvfs_cache(path_.c_str(),&st);
if(rv == 0)
*spaceavail_ = StatVFS::spaceavail(st);
return rv;
}
int
fs::statvfs_cache_spaceused(const std::string &path_,
uint64_t *spaceused_)
{
int rv;
struct statvfs st;
rv = fs::statvfs_cache(path_.c_str(),&st);
if(rv == 0)
*spaceused_ = StatVFS::spaceused(st);
return rv;
}