/// \brief OS file-system querying and manipulation.
#if defined( WIN32 )
#define S_ISDIR( mode ) ( mode & _S_IFDIR )
#include<io.h> // access()
#define F_OK 0x00
#define W_OK 0x02
#define R_OK 0x04
#else
#include<unistd.h> // access()
#endif
#include<stdio.h> // rename(), remove()
#include<sys/stat.h> // stat()
#include<sys/types.h> // this is included by stat.h on win32
#include<cstddef>
#include<ctime>
/// \brief Attempts to move the file identified by \p from to \p to and returns true if the operation was successful.
///
/// The operation will fail unless:
/// - The path \p from identifies an existing file which is accessible for writing.
/// - The directory component of \p from identifies an existing directory which is accessible for writing.
/// - The path \p to does not identify an existing file or directory.
/// - The directory component of \p to identifies an existing directory which is accessible for writing.
inlineboolfile_move(constchar*from,constchar*to){
returnrename(from,to)==0;
}
/// \brief Attempts to remove the file identified by \p path and returns true if the operation was successful.
///
/// The operation will fail unless:
/// - The \p path identifies an existing file.
/// - The parent-directory component of \p path identifies an existing directory which is accessible for writing.
inlineboolfile_remove(constchar*path){
returnremove(path)==0;
}
namespaceFileAccess
{
enumMode
{
Read=R_OK,
Write=W_OK,
ReadWrite=Read|Write,
Exists=F_OK
};
}
/// \brief Returns true if the file or directory identified by \p path exists and/or may be accessed for reading, writing or both, depending on the value of \p mode.