Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: ttyname(3) no longer returns /dev prefix?



On Tue, Jun 12, 2012 at 12:32:09AM -0500, Dave Huang wrote:
> It seems that ttyname(3) no longer returns the full path to the tty
> device file in /dev; it returns only the device name. E.g., it returns
> "ttyE0" instead of "/dev/ttyE0". Is this intentional?

No, it isn't. Please try the attached patch.

Joerg
Index: gen/ttyname.c
===================================================================
RCS file: /btrfs/repo/netbsd/src/lib/libc/gen/ttyname.c,v
retrieving revision 1.25
diff -u -p -r1.25 ttyname.c
--- gen/ttyname.c       3 Jun 2012 21:42:46 -0000       1.25
+++ gen/ttyname.c       12 Jun 2012 11:15:17 -0000
@@ -45,6 +45,7 @@ __RCSID("$NetBSD: ttyname.c,v 1.25 2012/
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
+#include <paths.h>
 #include <string.h>
 #include <stdlib.h>
 #include <termios.h>
@@ -79,6 +80,10 @@ ttyname_r(int fd, char *buf, size_t len)
        if (fstat(fd, &sb))
                return errno;
 
+       if (strlcpy(buf, _PATH_DEV, len) >= len)
+               return ERANGE;
+       buf += strlen(_PATH_DEV);
+       len -= strlen(_PATH_DEV);
        return devname_r(sb.st_rdev, sb.st_mode & S_IFMT, buf, len);
 }
 


Home | Main Index | Thread Index | Old Index