From 818254c55ee77e570a1280509eee72bfe317936b Mon Sep 17 00:00:00 2001 From: Michael Theall Date: Fri, 22 Jan 2016 16:40:28 -0600 Subject: [PATCH] Add sdmc_getmtime --- libctru/include/3ds/sdmc.h | 3 +++ libctru/source/sdmc_dev.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/libctru/include/3ds/sdmc.h b/libctru/include/3ds/sdmc.h index e973d5a..f648708 100644 --- a/libctru/include/3ds/sdmc.h +++ b/libctru/include/3ds/sdmc.h @@ -22,3 +22,6 @@ void sdmcWriteSafe(bool enable); /// Exits the SDMC driver. Result sdmcExit(void); + +/// Get a file's mtime +Result sdmc_getmtime(const char *name, u64 *mtime); diff --git a/libctru/source/sdmc_dev.c b/libctru/source/sdmc_dev.c index cd1303e..014c791 100644 --- a/libctru/source/sdmc_dev.c +++ b/libctru/source/sdmc_dev.c @@ -1222,6 +1222,38 @@ sdmc_rmdir(struct _reent *r, return -1; } +Result +sdmc_getmtime(const char *name, + u64 *mtime) +{ + Result rc; + FS_Path fs_path; + struct _reent r; + + r._errno = 0; + + fs_path = sdmc_utf16path(&r, name); + if(r._errno != 0) + errno = r._errno; + + if(fs_path.data == NULL) + return -1; + + rc = FSUSER_ControlArchive(sdmcArchive, ARCHIVE_ACTION_GET_TIMESTAMP, + (void*)fs_path.data, fs_path.size, + mtime, sizeof(*mtime)); + if(rc == 0) + { + /* convert from milliseconds to seconds */ + *mtime /= 1000; + /* convert from 2000-based timestamp to UNIX timestamp */ + *mtime += 946684800; + } + + return rc; + +} + /*! Error map */ typedef struct {