Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keplerproject/luafilesystem.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-05-04 15:17:21 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-05-05 12:39:17 +0300
commit8f167ef1de6ecbe1a6b4b375c92c370b995c6874 (patch)
treef2cb8743d248171262520d734b8dd468c4997388 /src
parent8b85d257a6c6ed3cbe1c80240ab168b5f3117cc3 (diff)
Return errno from lfs.touch on error
Diffstat (limited to 'src')
-rw-r--r--src/lfs.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/lfs.c b/src/lfs.c
index 2ead179..d9b21e6 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -646,26 +646,24 @@ static const char *mode2string (mode_t mode) {
/*
-** Set access time and modification values for file
+** Set access time and modification values for a file.
+** @param #1 File path.
+** @param #2 Access time in seconds, current time is used if missing.
+** @param #3 Modification time in seconds, access time is used if missing.
*/
static int file_utime (lua_State *L) {
- const char *file = luaL_checkstring (L, 1);
- struct utimbuf utb, *buf;
-
- if (lua_gettop (L) == 1) /* set to current date/time */
- buf = NULL;
- else {
- utb.actime = (time_t)luaL_optnumber (L, 2, 0);
- utb.modtime = (time_t) luaL_optinteger (L, 3, utb.actime);
- buf = &utb;
- }
- if (utime (file, buf)) {
- lua_pushnil (L);
- lua_pushfstring (L, "%s", strerror (errno));
- return 2;
- }
- lua_pushboolean (L, 1);
- return 1;
+ const char *file = luaL_checkstring(L, 1);
+ struct utimbuf utb, *buf;
+
+ if (lua_gettop (L) == 1) /* set to current date/time */
+ buf = NULL;
+ else {
+ utb.actime = (time_t) luaL_optnumber(L, 2, 0);
+ utb.modtime = (time_t) luaL_optinteger(L, 3, utb.actime);
+ buf = &utb;
+ }
+
+ return pushresult(L, utime(file, buf), NULL);
}