general code cleanup

This commit is contained in:
Antonio SJ Musumeci 2019-01-25 07:03:46 -05:00
parent 5a1a60742e
commit 9d9ee7b71d
178 changed files with 5100 additions and 5255 deletions

View file

@ -18,15 +18,15 @@
#pragma once
#include "fs_base_futimesat.hpp"
#include "fs_base_stat.hpp"
#include <string>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "fs_base_futimesat.hpp"
#include "fs_base_stat.hpp"
#ifndef UTIME_NOW
# define UTIME_NOW ((1l << 30) - 1l)
#endif
@ -38,54 +38,54 @@
static
inline
bool
_can_call_lutimes(const int dirfd,
const std::string &path,
const int flags)
_can_call_lutimes(const int dirfd_,
const std::string &path_,
const int flags_)
{
return ((flags == AT_SYMLINK_NOFOLLOW) &&
((dirfd == AT_FDCWD) ||
(path[0] == '/')));
return ((flags_ == AT_SYMLINK_NOFOLLOW) &&
((dirfd_ == AT_FDCWD) ||
(path_[0] == '/')));
}
static
inline
bool
_should_ignore(const struct timespec ts[2])
_should_ignore(const struct timespec ts_[2])
{
return ((ts != NULL) &&
(ts[0].tv_nsec == UTIME_OMIT) &&
(ts[1].tv_nsec == UTIME_OMIT));
return ((ts_ != NULL) &&
(ts_[0].tv_nsec == UTIME_OMIT) &&
(ts_[1].tv_nsec == UTIME_OMIT));
}
static
inline
bool
_should_be_set_to_now(const struct timespec ts[2])
_should_be_set_to_now(const struct timespec ts_[2])
{
return ((ts == NULL) ||
((ts[0].tv_nsec == UTIME_NOW) &&
(ts[1].tv_nsec == UTIME_NOW)));
return ((ts_ == NULL) ||
((ts_[0].tv_nsec == UTIME_NOW) &&
(ts_[1].tv_nsec == UTIME_NOW)));
}
static
inline
bool
_timespec_invalid(const struct timespec &ts)
_timespec_invalid(const struct timespec &ts_)
{
return (((ts.tv_nsec < 0) ||
(ts.tv_nsec > 999999999)) &&
((ts.tv_nsec != UTIME_NOW) &&
(ts.tv_nsec != UTIME_OMIT)));
return (((ts_.tv_nsec < 0) ||
(ts_.tv_nsec > 999999999)) &&
((ts_.tv_nsec != UTIME_NOW) &&
(ts_.tv_nsec != UTIME_OMIT)));
}
static
inline
bool
_timespec_invalid(const struct timespec ts[2])
_timespec_invalid(const struct timespec ts_[2])
{
return ((ts != NULL) &&
(_timespec_invalid(ts[0]) ||
_timespec_invalid(ts[1])));
return ((ts_ != NULL) &&
(_timespec_invalid(ts_[0]) ||
_timespec_invalid(ts_[1])));
}
static
@ -99,19 +99,19 @@ _flags_invalid(const int flags)
static
inline
bool
_any_timespec_is_utime_omit(const struct timespec ts[2])
_any_timespec_is_utime_omit(const struct timespec ts_[2])
{
return ((ts[0].tv_nsec == UTIME_OMIT) ||
(ts[1].tv_nsec == UTIME_OMIT));
return ((ts_[0].tv_nsec == UTIME_OMIT) ||
(ts_[1].tv_nsec == UTIME_OMIT));
}
static
inline
bool
_any_timespec_is_utime_now(const struct timespec ts[2])
_any_timespec_is_utime_now(const struct timespec ts_[2])
{
return ((ts[0].tv_nsec == UTIME_NOW) ||
(ts[1].tv_nsec == UTIME_NOW));
return ((ts_[0].tv_nsec == UTIME_NOW) ||
(ts_[1].tv_nsec == UTIME_NOW));
}
static
@ -119,7 +119,7 @@ inline
int
_set_utime_omit_to_current_value(const int dirfd,
const std::string &path,
const struct timespec ts[2],
const struct timespec ts_[2],
struct timeval tv[2],
const int flags)
{
@ -128,7 +128,7 @@ _set_utime_omit_to_current_value(const int dirfd,
timespec *atime;
timespec *mtime;
if(!_any_timespec_is_utime_omit(ts))
if(!_any_timespec_is_utime_omit(ts_))
return 0;
rv = ::fstatat(dirfd,path.c_str(),&st,flags);
@ -138,9 +138,9 @@ _set_utime_omit_to_current_value(const int dirfd,
atime = fs::stat_atime(st);
mtime = fs::stat_mtime(st);
if(ts[0].tv_nsec == UTIME_OMIT)
if(ts_[0].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[0],atime);
if(ts[1].tv_nsec == UTIME_OMIT)
if(ts_[1].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[1],mtime);
return 0;
@ -150,7 +150,7 @@ static
inline
int
_set_utime_omit_to_current_value(const int fd,
const struct timespec ts[2],
const struct timespec ts_[2],
struct timeval tv[2])
{
int rv;
@ -158,7 +158,7 @@ _set_utime_omit_to_current_value(const int fd,
timespec *atime;
timespec *mtime;
if(!_any_timespec_is_utime_omit(ts))
if(!_any_timespec_is_utime_omit(ts_))
return 0;
rv = ::fstat(fd,&st);
@ -168,9 +168,9 @@ _set_utime_omit_to_current_value(const int fd,
atime = fs::stat_atime(st);
mtime = fs::stat_mtime(st);
if(ts[0].tv_nsec == UTIME_OMIT)
if(ts_[0].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[0],atime);
if(ts[1].tv_nsec == UTIME_OMIT)
if(ts_[1].tv_nsec == UTIME_OMIT)
TIMESPEC_TO_TIMEVAL(&tv[1],mtime);
return 0;
@ -179,22 +179,22 @@ _set_utime_omit_to_current_value(const int fd,
static
inline
int
_set_utime_now_to_now(const struct timespec ts[2],
_set_utime_now_to_now(const struct timespec ts_[2],
struct timeval tv[2])
{
int rv;
struct timeval now;
if(_any_timespec_is_utime_now(ts))
if(_any_timespec_is_utime_now(ts_))
return 0;
rv = ::gettimeofday(&now,NULL);
if(rv == -1)
return -1;
if(ts[0].tv_nsec == UTIME_NOW)
if(ts_[0].tv_nsec == UTIME_NOW)
tv[0] = now;
if(ts[1].tv_nsec == UTIME_NOW)
if(ts_[1].tv_nsec == UTIME_NOW)
tv[1] = now;
return 0;
@ -205,24 +205,24 @@ inline
int
_convert_timespec_to_timeval(const int dirfd,
const std::string &path,
const struct timespec ts[2],
const struct timespec ts_[2],
struct timeval tv[2],
struct timeval *&tvp,
const int flags)
{
int rv;
if(_should_be_set_to_now(ts))
if(_should_be_set_to_now(ts_))
return (tvp=NULL,0);
TIMESPEC_TO_TIMEVAL(&tv[0],&ts[0]);
TIMESPEC_TO_TIMEVAL(&tv[1],&ts[1]);
TIMESPEC_TO_TIMEVAL(&tv[0],&ts_[0]);
TIMESPEC_TO_TIMEVAL(&tv[1],&ts_[1]);
rv = _set_utime_omit_to_current_value(dirfd,path,ts,tv,flags);
rv = _set_utime_omit_to_current_value(dirfd,path,ts_,tv,flags);
if(rv == -1)
return -1;
rv = _set_utime_now_to_now(ts,tv);
rv = _set_utime_now_to_now(ts_,tv);
if(rv == -1)
return -1;
@ -233,23 +233,23 @@ static
inline
int
_convert_timespec_to_timeval(const int fd,
const struct timespec ts[2],
const struct timespec ts_[2],
struct timeval tv[2],
struct timeval *&tvp)
{
int rv;
if(_should_be_set_to_now(ts))
if(_should_be_set_to_now(ts_))
return (tvp=NULL,0);
TIMESPEC_TO_TIMEVAL(&tv[0],&ts[0]);
TIMESPEC_TO_TIMEVAL(&tv[1],&ts[1]);
TIMESPEC_TO_TIMEVAL(&tv[0],&ts_[0]);
TIMESPEC_TO_TIMEVAL(&tv[1],&ts_[1]);
rv = _set_utime_omit_to_current_value(fd,ts,tv);
rv = _set_utime_omit_to_current_value(fd,ts_,tv);
if(rv == -1)
return -1;
rv = _set_utime_now_to_now(ts,tv);
rv = _set_utime_now_to_now(ts_,tv);
if(rv == -1)
return -1;
@ -263,7 +263,7 @@ namespace fs
int
utime(const int dirfd,
const std::string &path,
const struct timespec ts[2],
const struct timespec ts_[2],
const int flags)
{
int rv;
@ -272,12 +272,12 @@ namespace fs
if(_flags_invalid(flags))
return (errno=EINVAL,-1);
if(_timespec_invalid(ts))
if(_timespec_invalid(ts_))
return (errno=EINVAL,-1);
if(_should_ignore(ts))
if(_should_ignore(ts_))
return 0;
rv = _convert_timespec_to_timeval(dirfd,path,ts,tv,tvp,flags);
rv = _convert_timespec_to_timeval(dirfd,path,ts_,tv,tvp,flags);
if(rv == -1)
return -1;
@ -292,22 +292,22 @@ namespace fs
static
inline
int
utime(const int fd,
const struct timespec ts[2])
utime(const int fd_,
const struct timespec ts_[2])
{
int rv;
struct timeval tv[2];
struct timeval *tvp;
if(_timespec_invalid(ts))
if(_timespec_invalid(ts_))
return (errno=EINVAL,-1);
if(_should_ignore(ts))
if(_should_ignore(ts_))
return 0;
rv = _convert_timespec_to_timeval(fd,ts,tv,tvp);
rv = _convert_timespec_to_timeval(fd_,ts_,tv,tvp);
if(rv == -1)
return -1;
return ::futimes(fd,tvp);
return ::futimes(fd_,tvp);
}
}