Added os.islink() — does path point to a symbolic link or reparse point?
This commit is contained in:
parent
b0103e76ca
commit
8fe9c55a15
35
src/host/os_islink.c
Normal file
35
src/host/os_islink.c
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* \file os_islink.c
|
||||
* \brief Returns true if the given path is a symbolic link or reparse point.
|
||||
* \author Copyright (c) 2014 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "premake.h"
|
||||
|
||||
|
||||
int os_islink(lua_State* L)
|
||||
{
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
{
|
||||
DWORD attr = GetFileAttributes(path);
|
||||
if (attr != INVALID_FILE_ATTRIBUTES) {
|
||||
lua_pushboolean(L, (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
struct stat buf;
|
||||
if (lstat(path, &buf) == 0) {
|
||||
lua_pushboolean(L, S_ISLNK(buf.st_mode));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
@ -66,6 +66,7 @@ static const luaL_Reg os_functions[] = {
|
||||
{ "getcwd", os_getcwd },
|
||||
{ "getversion", os_getversion },
|
||||
{ "isfile", os_isfile },
|
||||
{ "islink", os_islink },
|
||||
{ "matchdone", os_matchdone },
|
||||
{ "matchisfile", os_matchisfile },
|
||||
{ "matchname", os_matchname },
|
||||
|
@ -89,6 +89,7 @@ int os_getversion(lua_State* L);
|
||||
int os_is64bit(lua_State* L);
|
||||
int os_isdir(lua_State* L);
|
||||
int os_isfile(lua_State* L);
|
||||
int os_islink(lua_State* L);
|
||||
int os_matchdone(lua_State* L);
|
||||
int os_matchisfile(lua_State* L);
|
||||
int os_matchname(lua_State* L);
|
||||
|
Loading…
Reference in New Issue
Block a user