shithub: sl

Download patch

ref: 9043ca380867b9b6e943cdc848082cb2c4fe8f60
parent: c9676d0d99397fa98cdc312e5d83cf6c90ffbc46
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Jan 5 16:54:59 EST 2025

path-cwd: throw an io error if getcwd failed

--- a/builtins.c
+++ b/builtins.c
@@ -366,11 +366,12 @@
 		argcount(nargs, 1);
 	if(nargs == 0){
 		char buf[1024];
-		getcwd(buf, sizeof(buf));
+		if(getcwd(buf, sizeof(buf)) == nil)
+			lerrorf(FL_IOError, "could not get current dir");
 		return string_from_cstr(buf);
 	}
 	char *ptr = tostring(args[0]);
-	if(chdir(ptr))
+	if(chdir(ptr) != 0)
 		lerrorf(FL_IOError, "could not cd to %s", ptr);
 	return FL_void;
 }