1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}
|