shithub: drawterm

Download patch

ref: c2a244ab69976103216b7ff9f3738a14b93bd546
parent: c3d7782a0cbb0aee91edae9b2850d053f27a6f0e
author: Jacob Moody <moody@posixcafe.org>
date: Tue Apr 16 17:25:42 EDT 2024

devfs-posix: fix create() on more strict POSIX systems

--- a/kern/devfs-posix.c
+++ b/kern/devfs-posix.c
@@ -231,7 +231,12 @@
 		}
 	}
 	else {
-		int m = fsomode(omode & 3) | O_CREAT | O_TRUNC;
+		int m = omode & 3;
+		/*
+		 * POSIX specifies that O_TRUNC with O_RDONLY is undefined.
+		 * OpenBSD chooses to return an error.
+		 */
+		m = fsomode(m == OREAD ? ORDWR : m) | O_CREAT | O_TRUNC;
 		if(mode & OEXCL)
 			m |= O_EXCL;
 		if((fd = open(path, m, uif->mode & perm & 0777)) < 0)