extmod/vfs: Add option to use 1970 as Epoch.

By setting MICROPY_EPOCH_IS_1970 a port can opt to use 1970/1/1 as the
Epoch for timestamps returned by stat().  And this setting is enabled on
the unix and windows ports because that's what they use.

Signed-off-by: Damien George <damien@micropython.org>
pull/6390/head
Damien George 2020-08-31 14:55:54 +10:00
rodzic 0385b21597
commit 2a72e90ab8
4 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -319,6 +319,9 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
(fno.ftime >> 5) & 0x3f,
2 * (fno.ftime & 0x1f)
);
#if MICROPY_EPOCH_IS_1970
seconds += TIMEUTILS_SECONDS_1970_TO_2000;
#endif
t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode
t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev

Wyświetl plik

@ -366,6 +366,9 @@ STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) {
ns = ns << 8 | mtime_buf[i - 1];
}
mtime = timeutils_seconds_since_2000_from_nanoseconds_since_1970(ns);
#if MICROPY_EPOCH_IS_1970
mtime += TIMEUTILS_SECONDS_1970_TO_2000;
#endif
}
#endif

Wyświetl plik

@ -176,6 +176,9 @@
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
// VFS stat functions should return time values relative to 1970/1/1
#define MICROPY_EPOCH_IS_1970 (1)
extern const struct _mp_print_t mp_stderr_print;
#if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__))

Wyświetl plik

@ -123,6 +123,9 @@
#define MICROPY_WARNINGS (1)
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
// VFS stat functions should return time values relative to 1970/1/1
#define MICROPY_EPOCH_IS_1970 (1)
extern const struct _mp_print_t mp_stderr_print;
#ifdef _MSC_VER