From b47693c078c256e897baf6b50f3aaf6accb5d35e Mon Sep 17 00:00:00 2001 From: Craig Small Date: Tue, 3 May 2022 20:33:44 +1000 Subject: [PATCH] library: cygwin fixes for devname Change the default name to cons%d ctty can be used by other systems not just Cygwin so create a define separate to cygwin for using the ctty function. The autoconf will need to be updated to check for these specific systems in future. Thanks to Achim of the Cygwin project for the patches. Signed-off-by: Craig Small --- proc/devname.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proc/devname.c b/proc/devname.c index 13b1b8a4..1cc6bc78 100644 --- a/proc/devname.c +++ b/proc/devname.c @@ -207,7 +207,7 @@ static int guess_name(char *restrict const buf, unsigned maj, unsigned min){ case 3: /* /dev/[pt]ty[p-za-o][0-9a-z] is 936 */ if(tmpmin > 255) return 0; // should never happen; array index protection #ifdef __CYGWIN__ - sprintf(buf, "dev/cons%d", tmpmin); + sprintf(buf, "cons%d", tmpmin); /* Skip stat call. The reason is that cons devices are local to * the processes running in that console. Calling stat from another * console or pty will return -1. */ @@ -295,7 +295,7 @@ static int link_name(char *restrict const buf, unsigned maj, unsigned min, int p return 1; } -#ifdef __CYGWIN__ +#ifdef USE_PROC_CTTY /* Cygwin keeps the name to the controlling tty in a virtual file called /proc/PID/ctty, including a trailing LF (sigh). */ static int ctty_name(char *restrict const buf, int pid) { @@ -326,7 +326,7 @@ unsigned dev_to_tty(char *restrict ret, unsigned chop, dev_t dev_t_dev, int pid, unsigned dev = dev_t_dev; unsigned i = 0; int c; -#ifdef __CYGWIN__ +#ifdef USE_PROC_CTTY if( ctty_name(tmp, pid )) goto abbrev; #endif if(dev == 0u) goto no_tty;