Browse Source

make time-handling compatible to linux

this may break stuff...
pull/26/head
Philipp Toelke 4 years ago
parent
commit
a50984551d
  1. 1
      ftpd.c
  2. 16
      vfs.c
  3. 26
      vfs.h

1
ftpd.c

@ -43,6 +43,7 @@
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "vfs.h"

16
vfs.c

@ -25,9 +25,10 @@
*/
#include "vfs.h"
#include <src/ff.h>
#include <source/ff.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
/* 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;
}

26
vfs.h

@ -27,17 +27,29 @@
#ifndef INCLUDE_VFS_H
#define INCLUDE_VFS_H
#include <src/ff.h>
#include <source/ff.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#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 */

Loading…
Cancel
Save