diff options
author | starkos <none@none> | 2008-10-31 21:38:05 +0300 |
---|---|---|
committer | starkos <none@none> | 2008-10-31 21:38:05 +0300 |
commit | c257e9c746f096ca4294168a8a2c26de538eb36c (patch) | |
tree | 8cf84989823ea063e60f805b8dedb619730bd5bc /src/host/os_isdir.c | |
parent | b2f4cfdc24ae7a45049ada7dd2afd91cb52053d1 (diff) |
First integration of new Lua-based architecture
Diffstat (limited to 'src/host/os_isdir.c')
-rw-r--r-- | src/host/os_isdir.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/host/os_isdir.c b/src/host/os_isdir.c new file mode 100644 index 0000000..fb5e8bb --- /dev/null +++ b/src/host/os_isdir.c @@ -0,0 +1,34 @@ +/** + * \file os_isdir.c + * \brief Returns true if the specified directory exists. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ + +#include <string.h> +#include <sys/stat.h> +#include "premake.h" + + +int os_isdir(lua_State* L) +{ + struct stat buf; + const char* path = luaL_checkstring(L, 1); + + /* empty path is equivalent to ".", must be true */ + if (strlen(path) == 0) + { + lua_pushboolean(L, 1); + } + else if (stat(path, &buf) == 0) + { + lua_pushboolean(L, buf.st_mode & S_IFDIR); + } + else + { + lua_pushboolean(L, 0); + } + + return 1; +} + + |