]> Chaos Git - corbenik/ctrulib.git/commitdiff
Add sdmc_getmtime
authorMichael Theall <pigman46@gmail.com>
Fri, 22 Jan 2016 22:40:28 +0000 (16:40 -0600)
committerMichael Theall <pigman46@gmail.com>
Fri, 22 Jan 2016 22:40:28 +0000 (16:40 -0600)
libctru/include/3ds/sdmc.h
libctru/source/sdmc_dev.c

index e973d5a8ffc4047a9dca12469c1c75df84451cdf..f648708c43a332db05a5c0d20a0a139d53f343b0 100644 (file)
@@ -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);
index cd1303e495d5ce9f1deb8d5da9a30e5b109b6301..014c79164bdcb23a8f24179e173664d42b6aab26 100644 (file)
@@ -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
 {