diff options
author | Ulrich Drepper <drepper@redhat.com> | 1998-09-17 19:51:33 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1998-09-17 19:51:33 +0000 |
commit | 9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd (patch) | |
tree | 77802928e3a7d3163bc63c89979295da8260112a /sysdeps/unix/sysv/linux/ptsname.c | |
parent | d8f2b9ea8cf4fb6d043f2dbbeaaca04d4fd70fc6 (diff) | |
download | glibc-9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd.tar.gz glibc-9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd.tar.xz glibc-9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd.zip |
Update.
1998-09-17 19:34 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/sysv4/bits/utsname.h: Fix typo. Patch by John Tobey <jtobey@banta-im.com>. 1998-09-17 Mark Kettenis <kettenis@phys.uva.nl> * login/pty-internal.h: Removed. Moved constants related to the `grantpt' helper program protocol to ... * login/pty-private.h: ... here. New file. * sysdeps/unix/sysv/linux/ptsname.c (ptsname): Reimplementation to make the function work with kernels >= 2.1.115. * sysdeps/unix/sysv/linux/getpt.c (getpt): Reimplement to call BSD version if using the cloning device fails. * sysdeps/unix/sysv/linux/grantpt.c: New file. * sysdeps/unix/sysv/linux/unlockpt.c: General cleanup. * sysdeps/unix/bsd/getpt.c (__getpt): Largely rewritten to allow use by Linux specific code. * sysdeps/unix/bsd/unlockpt.c: General cleanup. * sysdeps/unix/grantpt.c: Largely rewritten. (pts_name): New function. (grantpt): Use pts_name, check group and permission mode in addition to owner. Try to set the owner, group and permission mode first without invoking the helper program. * login/programs/pt_chown.c: Largely rewritten. Add argp and internationalization support. Use symbolic constants instead of hardwired numbers for permission mode. * sysdeps/unix/bsd/ptsname.c: New file. 1998-09-17 22:04 Tim Waugh <tim@cyberelk.demon.co.uk> * posix/wordexp-test.c: Undo last change. * posix/wordexp.c: Undo last change.
Diffstat (limited to 'sysdeps/unix/sysv/linux/ptsname.c')
-rw-r--r-- | sysdeps/unix/sysv/linux/ptsname.c | 141 |
1 files changed, 70 insertions, 71 deletions
diff --git a/sysdeps/unix/sysv/linux/ptsname.c b/sysdeps/unix/sysv/linux/ptsname.c index 052516c7ac..048ac96551 100644 --- a/sysdeps/unix/sysv/linux/ptsname.c +++ b/sysdeps/unix/sysv/linux/ptsname.c @@ -17,50 +17,50 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <sys/types.h> +#include <errno.h> +#include <paths.h> +#include <stdlib.h> +#include <string.h> #include <sys/ioctl.h> #include <sys/stat.h> +#include <sys/sysmacros.h> #include <termios.h> -#include <string.h> -#include <errno.h> -#include <stdlib.h> #include <unistd.h> -#include "pty-internal.h" - #include <stdio-common/_itoa.h> -#include <sys/sysmacros.h> -/* Given the file descriptor of a master pty, return the pathname - of the associated slave. */ +/* Directory where we can find the slave pty nodes. */ +#define _PATH_DEVPTS "/dev/pts/" -static char namebuf[PTYNAMELEN]; -extern const char __ptyname1[], __ptyname2[]; /* Defined in getpt.c. */ +/* The are declared in getpt.c. */ +extern const char *__libc_ptyname1; +extern const char *__libc_ptyname2; +/* Static buffer for `ptsname'. */ +static char buffer[sizeof (_PATH_DEVPTS) + 20]; + + +/* Return the pathname of the pseudo terminal slave assoicated with + the master FD is open on, or NULL on errors. + The returned storage is good until the next call to this function. */ char * -ptsname (fd) - int fd; +ptsname (int fd) { - return __ptsname_r (fd, namebuf, PTYNAMELEN) != 0 ? NULL : namebuf; + return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer; } + +/* Store at most BUFLEN characters of the pathname of the slave pseudo + terminal associated with the master FD is open on in BUF. + Return 0 on success, otherwise an error number. */ int -__ptsname_r (fd, buf, buflen) - int fd; - char *buf; - size_t buflen; +__ptsname_r (int fd, char *buf, size_t buflen) { + int save_errno = errno; struct stat st; - int save = errno; int ptyno; - char nbuf[PTYNAMELEN], idbuf[6]; - char *cp; - -#ifdef TIOCGPTN - static int tiocgptn_works = 1; -#endif - - if (!buf) + + if (buf == NULL) { __set_errno (EINVAL); return EINVAL; @@ -73,61 +73,60 @@ __ptsname_r (fd, buf, buflen) } #ifdef TIOCGPTN - if (tiocgptn_works) + if (__ioctl (fd, TIOCGPTN, &ptyno) == 0) { - if (__ioctl (fd, TIOCGPTN, &ptyno) == 0) - goto gotit; - else + /* Buffer we use to print the number in. For a maximum size for + `int' of 8 bytes we never need more than 20 digits. */ + char numbuf[21]; + const char *devpts = _PATH_DEVPTS; + const size_t devptslen = strlen (devpts); + char *p; + + numbuf[20] = '\0'; + p = _itoa_word (ptyno, &numbuf[20], 10, 0); + + if (buflen < devptslen + strlen (p) + 1) { - if(errno != EINVAL) - return errno; - else - tiocgptn_works = 0; + __set_errno (ERANGE); + return ERANGE; } - } -#endif - if (__fxstat (_STAT_VER, fd, &st) < 0) - return errno; - ptyno = minor (st.st_rdev); - if (major (st.st_rdev) == 4) - ptyno -= 128; - -#ifdef TIOCGPTN - gotit: + __stpcpy (__stpcpy (buf, devpts), p); + } + else if (errno == EINVAL) #endif - /* Two different possible naming schemes for pty slaves: - the SVr4 way. */ - - idbuf[5] = '\0'; - __stpcpy (__stpcpy (nbuf, "/dev/pts/"), - _itoa_word (ptyno, &idbuf[5], 10, 0)); - if (__xstat (_STAT_VER, nbuf, &st) < 0) { - if (errno != ENOENT) - return errno; - - /* ...and the BSD way. */ - nbuf[5] = 't'; - nbuf[7] = 'y'; - nbuf[8] = __ptyname1[ptyno / 16]; - nbuf[9] = __ptyname2[ptyno % 16]; - nbuf[10] = '\0'; + char *p; + + if (buflen < strlen (_PATH_TTY) + 3) + { + __set_errno (ERANGE); + return ERANGE; + } - if (__xstat (_STAT_VER, nbuf, &st) < 0) + if (__fstat (fd, &st) < 0) return errno; - } - if (buflen < strlen (nbuf) + 1) - { - __set_errno (ERANGE); - return ERANGE; - } + ptyno = minor (st.st_rdev); + if (major (st.st_rdev) == 4) + ptyno -= 128; - cp = __stpncpy (buf, nbuf, buflen); - cp[0] = '\0'; + if (ptyno / 16 >= strlen (__libc_ptyname1)) + { + __set_errno (ENOTTY); + return ENOTTY; + } + + p = __stpcpy (buf, _PATH_TTY); + p[0] = __libc_ptyname1[ptyno / 16]; + p[1] = __libc_ptyname2[ptyno % 16]; + p[2] = '\0'; + } + + if (__stat (buf, &st) < 0) + return errno; - __set_errno (save); + __set_errno (save_errno); return 0; } weak_alias (__ptsname_r, ptsname_r) |