aboutsummaryrefslogtreecommitdiff
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
parent8b85d257a6c6ed3cbe1c80240ab168b5f3117cc3 (diff)
downloadluafilesystem-8f167ef1de6ecbe1a6b4b375c92c370b995c6874.tar.gz
luafilesystem-8f167ef1de6ecbe1a6b4b375c92c370b995c6874.tar.bz2
luafilesystem-8f167ef1de6ecbe1a6b4b375c92c370b995c6874.zip
Return errno from lfs.touch on error
-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) {
646 646
647 647
648/* 648/*
649** Set access time and modification values for file 649** Set access time and modification values for a file.
650** @param #1 File path.
651** @param #2 Access time in seconds, current time is used if missing.
652** @param #3 Modification time in seconds, access time is used if missing.
650*/ 653*/
651static int file_utime (lua_State *L) { 654static int file_utime (lua_State *L) {
652 const char *file = luaL_checkstring (L, 1); 655 const char *file = luaL_checkstring(L, 1);
653 struct utimbuf utb, *buf; 656 struct utimbuf utb, *buf;
654 657
655 if (lua_gettop (L) == 1) /* set to current date/time */ 658 if (lua_gettop (L) == 1) /* set to current date/time */
656 buf = NULL; 659 buf = NULL;
657 else { 660 else {
658 utb.actime = (time_t)luaL_optnumber (L, 2, 0); 661 utb.actime = (time_t) luaL_optnumber(L, 2, 0);
659 utb.modtime = (time_t) luaL_optinteger (L, 3, utb.actime); 662 utb.modtime = (time_t) luaL_optinteger(L, 3, utb.actime);
660 buf = &utb; 663 buf = &utb;
661 } 664 }
662 if (utime (file, buf)) { 665
663 lua_pushnil (L); 666 return pushresult(L, utime(file, buf), NULL);
664 lua_pushfstring (L, "%s", strerror (errno));
665 return 2;
666 }
667 lua_pushboolean (L, 1);
668 return 1;
669} 667}
670 668
671 669