diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2021-01-23 15:16:20 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2021-01-23 15:49:05 -0300 |
commit | 6adf412a256181e07b4859c3703fb4dc6023007e (patch) | |
tree | b24eb7c5b72510cc7b7c2863c779ea53e8b5b0f9 | |
parent | 442fabb11a45896c32d170eac70d4f269bed7e46 (diff) | |
download | luafilesystem-6adf412a256181e07b4859c3703fb4dc6023007e.tar.gz luafilesystem-6adf412a256181e07b4859c3703fb4dc6023007e.tar.bz2 luafilesystem-6adf412a256181e07b4859c3703fb4dc6023007e.zip |
return higher precision times in lfs.attributes
-rw-r--r-- | src/lfs.c | 21 | ||||
-rw-r--r-- | tests/test.lua | 4 |
2 files changed, 20 insertions, 5 deletions
@@ -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 */ |
880 | static void push_st_atime(lua_State * L, STAT_STRUCT * info) | 895 | static 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 */ |
886 | static void push_st_mtime(lua_State * L, STAT_STRUCT * info) | 901 | static 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 */ |
892 | static void push_st_ctime(lua_State * L, STAT_STRUCT * info) | 907 | static 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 |
152 | assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) | 152 | assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) |
153 | new_att = assert (lfs.attributes (tmpfile)) | 153 | new_att = assert (lfs.attributes (tmpfile)) |
154 | assert (new_att.access == attrib.access) | 154 | assert (new_att.access - attrib.access < 1) |
155 | assert (new_att.modification == attrib.modification) | 155 | assert (new_att.modification - attrib.modification < 1) |
156 | 156 | ||
157 | io.write(".") | 157 | io.write(".") |
158 | io.flush() | 158 | io.flush() |