AP_Filesystem: implement stat() call for lua
This commit is contained in:
parent
9f08e5d317
commit
9beea49c3c
@ -333,6 +333,30 @@ AP_Filesystem_Backend::FormatStatus AP_Filesystem::get_format_status(void) const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
stat wrapper for scripting
|
||||||
|
*/
|
||||||
|
bool AP_Filesystem::stat(const char *pathname, stat_t &stbuf)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (fs.stat(pathname, &st) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stbuf.size = st.st_size;
|
||||||
|
stbuf.mode = st.st_mode;
|
||||||
|
// these wrap in 2038
|
||||||
|
stbuf.atime = st.st_atime;
|
||||||
|
stbuf.ctime = st.st_ctime;
|
||||||
|
stbuf.mtime = st.st_mtime;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get_singleton for scripting
|
||||||
|
AP_Filesystem *AP_Filesystem::get_singleton(void)
|
||||||
|
{
|
||||||
|
return &fs;
|
||||||
|
}
|
||||||
|
|
||||||
namespace AP
|
namespace AP
|
||||||
{
|
{
|
||||||
AP_Filesystem &FS()
|
AP_Filesystem &FS()
|
||||||
|
@ -82,6 +82,20 @@ public:
|
|||||||
int fsync(int fd);
|
int fsync(int fd);
|
||||||
int32_t lseek(int fd, int32_t offset, int whence);
|
int32_t lseek(int fd, int32_t offset, int whence);
|
||||||
int stat(const char *pathname, struct stat *stbuf);
|
int stat(const char *pathname, struct stat *stbuf);
|
||||||
|
|
||||||
|
// stat variant for scripting
|
||||||
|
typedef struct {
|
||||||
|
uint32_t size;
|
||||||
|
int32_t mode;
|
||||||
|
uint32_t mtime;
|
||||||
|
uint32_t atime;
|
||||||
|
uint32_t ctime;
|
||||||
|
bool is_directory(void) const {
|
||||||
|
return (mode & S_IFMT) == S_IFDIR;
|
||||||
|
}
|
||||||
|
} stat_t;
|
||||||
|
bool stat(const char *pathname, stat_t &stbuf);
|
||||||
|
|
||||||
int unlink(const char *pathname);
|
int unlink(const char *pathname);
|
||||||
int mkdir(const char *pathname);
|
int mkdir(const char *pathname);
|
||||||
int rename(const char *oldpath, const char *newpath);
|
int rename(const char *oldpath, const char *newpath);
|
||||||
@ -121,7 +135,10 @@ public:
|
|||||||
load a full file. Use delete to free the data
|
load a full file. Use delete to free the data
|
||||||
*/
|
*/
|
||||||
FileData *load_file(const char *filename);
|
FileData *load_file(const char *filename);
|
||||||
|
|
||||||
|
// get_singleton for scripting
|
||||||
|
static AP_Filesystem *get_singleton(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Backend {
|
struct Backend {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
|
Loading…
Reference in New Issue
Block a user