about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/unistd/ctermid.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/unistd/ctermid.c b/src/unistd/ctermid.c
index 21b44ec8..c238905a 100644
--- a/src/unistd/ctermid.c
+++ b/src/unistd/ctermid.c
@@ -4,6 +4,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <limits.h>
+#include "syscall.h"
 
 char *ctermid(char *s)
 {
@@ -13,11 +14,11 @@ char *ctermid(char *s)
 		if (!s2) s2 = malloc(L_ctermid);
 		s = s2;
 	}
-	fd = open("/dev/tty", O_WRONLY | O_NOCTTY);
+	fd = open("/dev/tty", O_WRONLY | O_NOCTTY | O_CLOEXEC);
 	if (fd < 0)
 		return strcpy(s, "");
 	if (ttyname_r(fd, s, L_ctermid))
 		strcpy(s, "");
-	close(fd);
+	__syscall(SYS_close, fd);
 	return s;
 }