mirror of
https://github.com/janet-lang/janet
synced 2024-11-29 03:19:54 +00:00
Add os/lstat.
This commit is contained in:
parent
b0d8369534
commit
381dd1ce98
@ -911,7 +911,7 @@ static const struct OsStatGetter os_stat_getters[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static Janet os_stat(int32_t argc, Janet *argv) {
|
static Janet os_stat_or_lstat(int do_lstat, int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
const char *path = janet_getcstring(argv, 0);
|
const char *path = janet_getcstring(argv, 0);
|
||||||
JanetTable *tab = NULL;
|
JanetTable *tab = NULL;
|
||||||
@ -930,11 +930,17 @@ static Janet os_stat(int32_t argc, Janet *argv) {
|
|||||||
|
|
||||||
/* Build result */
|
/* Build result */
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
|
(void) do_lstat;
|
||||||
struct _stat st;
|
struct _stat st;
|
||||||
int res = _stat(path, &st);
|
int res = _stat(path, &st);
|
||||||
#else
|
#else
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int res = stat(path, &st);
|
int res;
|
||||||
|
if (do_lstat) {
|
||||||
|
res = lstat(path, &st);
|
||||||
|
} else {
|
||||||
|
res = stat(path, &st);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (-1 == res) {
|
if (-1 == res) {
|
||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
@ -957,6 +963,14 @@ static Janet os_stat(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Janet os_stat(int32_t argc, Janet *argv) {
|
||||||
|
return os_stat_or_lstat(0, argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Janet os_lstat(int32_t argc, Janet *argv) {
|
||||||
|
return os_stat_or_lstat(1, argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
static Janet os_chmod(int32_t argc, Janet *argv) {
|
static Janet os_chmod(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
const char *path = janet_getcstring(argv, 0);
|
const char *path = janet_getcstring(argv, 0);
|
||||||
@ -1085,6 +1099,11 @@ static const JanetReg os_cfuns[] = {
|
|||||||
"\t:changed - timestamp when file last chnaged (permissions changed)\n"
|
"\t:changed - timestamp when file last chnaged (permissions changed)\n"
|
||||||
"\t:modified - timestamp when file last modified (content changed)\n")
|
"\t:modified - timestamp when file last modified (content changed)\n")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"os/lstat", os_lstat,
|
||||||
|
JDOC("(os/lstat path &opt tab|key)\n\n"
|
||||||
|
"Like os/stat, but don't follow symlinks.\n")
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"os/chmod", os_chmod,
|
"os/chmod", os_chmod,
|
||||||
JDOC("(os/chmod path mode)\n\n"
|
JDOC("(os/chmod path mode)\n\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user