aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2021-01-23 15:16:20 -0300
committerHisham Muhammad <hisham@gobolinux.org>2021-01-23 15:49:05 -0300
commit6adf412a256181e07b4859c3703fb4dc6023007e (patch)
treeb24eb7c5b72510cc7b7c2863c779ea53e8b5b0f9
parent442fabb11a45896c32d170eac70d4f269bed7e46 (diff)
downloadluafilesystem-6adf412a256181e07b4859c3703fb4dc6023007e.tar.gz
luafilesystem-6adf412a256181e07b4859c3703fb4dc6023007e.tar.bz2
luafilesystem-6adf412a256181e07b4859c3703fb4dc6023007e.zip
return higher precision times in lfs.attributes
-rw-r--r--src/lfs.c21
-rw-r--r--tests/test.lua4
2 files changed, 20 insertions, 5 deletions
diff --git a/src/lfs.c b/src/lfs.c
index 95ab63b..1b74a31 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -876,22 +876,37 @@ static void push_st_rdev(lua_State * L, STAT_STRUCT * info)
876 lua_pushinteger(L, (lua_Integer) info->st_rdev); 876 lua_pushinteger(L, (lua_Integer) info->st_rdev);
877} 877}
878 878
879#define push_stat_timespec(field) \
880 lua_pushnumber(L, info->FIELDNAME(field).tv_sec \
881 + info->FIELDNAME(field).tv_nsec / 1000000000.0)
882
883#if _POSIX_VERSION >= 200809L
884#define FIELDNAME(field) field
885#define push_stat_time(field) push_stat_timespec(field)
886#elif __APPLE__
887#define FIELDNAME(field) field ## espec
888#define push_stat_time(field) push_stat_timespec(field)
889#else
890#define FIELDNAME(field) field ## e
891#define push_stat_time(field) lua_pushinteger(L, info->FIELDNAME(field))
892#endif
893
879/* time of last access */ 894/* time of last access */
880static void push_st_atime(lua_State * L, STAT_STRUCT * info) 895static void push_st_atime(lua_State * L, STAT_STRUCT * info)
881{ 896{
882 lua_pushinteger(L, (lua_Integer) info->st_atime); 897 push_stat_time(st_atim);
883} 898}
884 899
885/* time of last data modification */ 900/* time of last data modification */
886static void push_st_mtime(lua_State * L, STAT_STRUCT * info) 901static void push_st_mtime(lua_State * L, STAT_STRUCT * info)
887{ 902{
888 lua_pushinteger(L, (lua_Integer) info->st_mtime); 903 push_stat_time(st_mtim);
889} 904}
890 905
891/* time of last file status change */ 906/* time of last file status change */
892static void push_st_ctime(lua_State * L, STAT_STRUCT * info) 907static void push_st_ctime(lua_State * L, STAT_STRUCT * info)
893{ 908{
894 lua_pushinteger(L, (lua_Integer) info->st_ctime); 909 push_stat_time(st_ctim);
895} 910}
896 911
897/* file size, in bytes */ 912/* file size, in bytes */
diff --git a/tests/test.lua b/tests/test.lua
index ed154c0..3ace810 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -151,8 +151,8 @@ io.flush()
151-- Restore access time to current value 151-- Restore access time to current value
152assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) 152assert (lfs.touch (tmpfile, attrib.access, attrib.modification))
153new_att = assert (lfs.attributes (tmpfile)) 153new_att = assert (lfs.attributes (tmpfile))
154assert (new_att.access == attrib.access) 154assert (new_att.access - attrib.access < 1)
155assert (new_att.modification == attrib.modification) 155assert (new_att.modification - attrib.modification < 1)
156 156
157io.write(".") 157io.write(".")
158io.flush() 158io.flush()