~mrms/osum

8f5f7b8d915ce46b433a7d0f1db5c075e0b31f36 — Marek Ma┼íkarinec 3 months ago b400b6e
Sanitize trailing separators in isdir

Signed-off-by: Marek Maškarinec <marek@mrms.cz>
2 files changed, 9 insertions(+), 1 deletions(-)

M os.c
M os.um
M os.c => os.c +7 -1
@@ 181,6 181,12 @@ void
umc__isdir(UmkaStackSlot *p, UmkaStackSlot *r)
{
	char *path = p[0].ptrVal;
	for (size_t i = strlen(path) - 1; i > 0; i--) {
		if (path[i] != '/' && path[i] != '\\')
			break;
		path[i] = 0;
	}

	r->intVal = 0;

	struct stat st;


@@ 314,4 320,4 @@ umc__stat(UmkaStackSlot *p, UmkaStackSlot *r)
	buf->ctime = st.st_ctime;

	r->intVal = 0;
}
\ No newline at end of file
}

M os.um => os.um +2 -0
@@ 250,6 250,8 @@ fn main() {
	printf("isdir(\"os.um\")  = %v\n", isdir("os.um"))
	printf("isfile(\"umbox\")   = %v\n", isfile("umbox"))
	printf("isdir(\"umbox\")    = %v\n", isdir("umbox"))
	printf("isdir(\"umbox/\")    = %v\n", isdir("umbox/"))
	printf("isdir(\"umbox\\\")    = %v\n", isdir("umbox\\"))
	printf("islink(\"umbox\")   = %v\n", islink("umbox"))
	printf("islink(\"umbox/filepath/umbox/strings\") = %v\n", islink("umbox/filepath/umbox/strings"))
	printf("stat(\"os.um\") =\n%v\n", stat("os.um"))