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

github.com/windirstat/premake-4.x.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/host
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2011-08-27 00:10:02 +0400
committerJason Perkins <starkos@industriousone.com>2011-08-27 00:10:02 +0400
commit3e8ee403158e2b7aeefe17ec116789a8552c017f (patch)
tree6f5ae4a9e59fb1f44191602e5ef1773748fd6dc3 /src/host
parent764400861ba77539dcb79f161d785d63423262a8 (diff)
Added new function os.stat to fetch information about a file
Diffstat (limited to 'src/host')
-rwxr-xr-xsrc/host/os_stat.c46
-rwxr-xr-xsrc/host/premake.c1
-rwxr-xr-xsrc/host/premake.h1
3 files changed, 48 insertions, 0 deletions
diff --git a/src/host/os_stat.c b/src/host/os_stat.c
new file mode 100755
index 0000000..b3554dc
--- /dev/null
+++ b/src/host/os_stat.c
@@ -0,0 +1,46 @@
+/**
+ * \file os_stat.c
+ * \brief Retrieve information about a file.
+ * \author Copyright (c) 2011 Jason Perkins and the Premake project
+ */
+
+#include "premake.h"
+#include <sys/stat.h>
+#include <errno.h>
+
+int os_stat(lua_State* L)
+{
+ struct stat s;
+
+ const char* filename = luaL_checkstring(L, 1);
+ if (stat(filename, &s) != 0)
+ {
+ lua_pushnil(L);
+ switch (errno)
+ {
+ case EACCES:
+ lua_pushfstring(L, "'%s' could not be accessed", filename);
+ break;
+ case ENOENT:
+ lua_pushfstring(L, "'%s' was not found", filename);
+ break;
+ default:
+ lua_pushfstring(L, "An unknown error %d occured while accessing '%s'", errno, filename);
+ break;
+ }
+ return 2;
+ }
+
+
+ lua_newtable(L);
+
+ lua_pushstring(L, "mtime");
+ lua_pushinteger(L, (lua_Integer)s.st_mtime);
+ lua_settable(L, -3);
+
+ lua_pushstring(L, "size");
+ lua_pushnumber(L, s.st_size);
+ lua_settable(L, -3);
+
+ return 1;
+}
diff --git a/src/host/premake.c b/src/host/premake.c
index 7548ff4..025d8c7 100755
--- a/src/host/premake.c
+++ b/src/host/premake.c
@@ -49,6 +49,7 @@ static const luaL_Reg os_functions[] = {
{ "mkdir", os_mkdir },
{ "pathsearch", os_pathsearch },
{ "rmdir", os_rmdir },
+ { "stat", os_stat },
{ "uuid", os_uuid },
{ NULL, NULL }
};
diff --git a/src/host/premake.h b/src/host/premake.h
index cd7d522..fba3ea5 100755
--- a/src/host/premake.h
+++ b/src/host/premake.h
@@ -67,6 +67,7 @@ int os_matchstart(lua_State* L);
int os_mkdir(lua_State* L);
int os_pathsearch(lua_State* L);
int os_rmdir(lua_State* L);
+int os_stat(lua_State* L);
int os_uuid(lua_State* L);
int string_endswith(lua_State* L);