blob: 90ceb46623f8585bc408468aef8ff9aa889c637f (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
* This file is part of Granger.
* Copyright (c) 2016 Jeff Kent <jeff@jkent.net>
*
* Granger is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Granger is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Granger. If not, see <http://www.gnu.org/licenses/>.
*/
#include "premake.h"
#if defined(PLATFORM_WINDOWS)
#include <io.h>
#define access _access
#define X_OK 1
#define W_OK 2
#define R_OK 4
#endif
int os_access(lua_State *L)
{
const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
int nmode = 0;
int result;
while (*mode) {
switch (*mode) {
case 'x':
nmode |= X_OK;
break;
case 'w':
nmode |= W_OK;
break;
case 'r':
nmode |= R_OK;
break;
default:
lua_pushboolean(L, 0);
return 1;
}
mode++;
}
result = access(filename, nmode);
lua_pushboolean(L, result == 0);
return 1;
}
|