diff --git a/ftpd.c b/ftpd.c index 970207a..80871a4 100644 --- a/ftpd.c +++ b/ftpd.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "vfs.h" diff --git a/vfs.c b/vfs.c index d94016a..75c4ca7 100644 --- a/vfs.c +++ b/vfs.c @@ -25,9 +25,10 @@ */ #include "vfs.h" -#include +#include #include #include +#include /* dirent that will be given to callers; * note: both APIs assume that only one dirent ever exists @@ -65,8 +66,15 @@ int vfs_stat(vfs_t* vfs, const char* filename, vfs_stat_t* st) { } st->st_size = f.fsize; st->st_mode = f.fattrib; - st->st_mtime.date = f.fdate; - st->st_mtime.time = f.ftime; + struct tm tm = { + .tm_sec = 2*(f.ftime & 0x1f), + .tm_min = (f.ftime >> 5) & 0x3f, + .tm_hour = (f.ftime >> 11) & 0x1f, + .tm_mday = f.fdate & 0x1f, + .tm_mon = (f.fdate >> 5) & 0xf, + .tm_year = 80 + (f.fdate >> 9) & 0x7f, + }; + st->st_mtime = mktime(&tm); return 0; } @@ -136,6 +144,6 @@ struct tm dummy = { .tm_hour = 0, .tm_min = 0 }; -struct tm* gmtime(time_t* c_t) { +struct tm* gmtime(const time_t* c_t) { return &dummy; } diff --git a/vfs.h b/vfs.h index 68f7548..5e7c552 100644 --- a/vfs.h +++ b/vfs.h @@ -27,17 +27,29 @@ #ifndef INCLUDE_VFS_H #define INCLUDE_VFS_H -#include +#include #include +#include +#include #define vfs_load_plugin(x) #define bcopy(src, dest, len) memmove(dest, src, len) - +#ifndef __time_t_defined typedef struct { short date; short time; } time_t; + +struct tm { + int tm_year; + int tm_mon; + int tm_mday; + int tm_hour; + int tm_min; + int tm_sec; +}; +#endif // __time_t_defined typedef DIR vfs_dir_t; typedef FIL vfs_file_t; typedef struct { @@ -50,14 +62,6 @@ typedef struct { } vfs_dirent_t; typedef FIL vfs_t; -struct tm { - int tm_year; - int tm_mon; - int tm_mday; - int tm_hour; - int tm_min; -}; - #define time(x) #define vfs_eof f_eof #define VFS_ISDIR(st_mode) ((st_mode) & AM_DIR) @@ -80,6 +84,6 @@ void vfs_close(vfs_t* vfs); int vfs_stat(vfs_t* vfs, const char* filename, vfs_stat_t* st); void vfs_closedir(vfs_dir_t* dir); vfs_dir_t* vfs_opendir(vfs_t* vfs, const char* path); -struct tm* gmtime(time_t *c_t); +struct tm* gmtime(const time_t *c_t); #endif /* INCLUDE_VFS_H */