Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access(2) constants to the constants table #655

Merged
merged 1 commit into from
May 30, 2023

Conversation

rpigott
Copy link
Contributor

@rpigott rpigott commented May 30, 2023

fs_access is equivalent to access(2), but this function is useless without the corresponsing access mode constants F_OK, R_OK, W_OK, and X_OK. Let's add these constants to the table.

fs_access is equivalent to access(2), but this function is useless
without the corresponsing access mode constants F_OK, R_OK, W_OK, and
X_OK. Let's add these constants to the table.
Copy link
Member

@squeek502 squeek502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to add these, but note that the mode can be specified as a string:

luv/docs.md

Lines 2844 to 2846 in 16bbffd

Equivalent to `access(2)` on Unix. Windows uses `GetFileAttributesW()`. Access
`mode` can be an integer or a string containing `"R"` or `"W"` or `"X"`.
Returns `true` or `false` indicating access permission.

which is usually how it's used, e.g. here

Implementation is here for reference:

luv/src/fs.c

Lines 179 to 207 in 16bbffd

static int luv_check_amode(lua_State* L, int index) {
size_t i;
int mode;
const char* string;
if (lua_isnumber(L, index)) {
return lua_tointeger(L, index);
}
else if (!lua_isstring(L, index)) {
return luaL_argerror(L, index, "Expected string or integer for file access mode check");
}
string = lua_tostring(L, index);
mode = 0;
for (i = 0; i < strlen(string); ++i) {
switch (string[i]) {
case 'r': case 'R':
mode |= R_OK;
break;
case 'w': case 'W':
mode |= W_OK;
break;
case 'x': case 'X':
mode |= X_OK;
break;
default:
return luaL_argerror(L, index, "Unknown character in access mode string");
}
}
return mode;
}

@squeek502 squeek502 merged commit 71d6dd7 into luvit:master May 30, 2023
13 checks passed
@squeek502
Copy link
Member

Thanks!

@rpigott rpigott deleted the access-consts branch May 30, 2023 07:33
@rpigott
Copy link
Contributor Author

rpigott commented May 30, 2023

mode can be specified as a string

I didn't know that! TYVM for the info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants