about summary refs log tree commit diff
path: root/sysdeps/unix/grantpt.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-11-24 18:50:32 -0800
committerUlrich Drepper <drepper@redhat.com>2009-11-24 18:50:32 -0800
commitaa9890239a2aef81e64f3f22a31c7e01b6501f69 (patch)
tree9f11b2e9d90685e5c9b15a69e7ffefd259e4777e /sysdeps/unix/grantpt.c
parent0f622686af3ae5a8f03dae886b08c260b38bda16 (diff)
downloadglibc-aa9890239a2aef81e64f3f22a31c7e01b6501f69.tar.gz
glibc-aa9890239a2aef81e64f3f22a31c7e01b6501f69.tar.xz
glibc-aa9890239a2aef81e64f3f22a31c7e01b6501f69.zip
Optimize grantpt.
grantpt was performing two consecutive calls to stat with the same
file name.  Avoid this by creating a special version of the ptsname
function which allows to pass the stat result back to the caller.
Diffstat (limited to 'sysdeps/unix/grantpt.c')
-rw-r--r--sysdeps/unix/grantpt.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c
index 2a7a963162..260e8273f8 100644
--- a/sysdeps/unix/grantpt.c
+++ b/sysdeps/unix/grantpt.c
@@ -38,7 +38,7 @@
    this buffer, a sufficiently long buffer is allocated using malloc,
    and returned in PTS.  0 is returned upon success, -1 otherwise.  */
 static int
-pts_name (int fd, char **pts, size_t buf_len)
+pts_name (int fd, char **pts, size_t buf_len, struct stat64 *stp)
 {
   int rv;
   char *buf = *pts;
@@ -49,7 +49,7 @@ pts_name (int fd, char **pts, size_t buf_len)
 
       if (buf_len)
 	{
-	  rv = __ptsname_r (fd, buf, buf_len);
+	  rv = __ptsname_internal (fd, buf, buf_len, stp);
 	  if (rv != 0)
 	    {
 	      if (rv == ENOTTY)
@@ -107,8 +107,9 @@ grantpt (int fd)
   char _buf[512];
 #endif
   char *buf = _buf;
+  struct stat64 st;
 
-  if (__builtin_expect (pts_name (fd, &buf, sizeof (_buf)), 0))
+  if (__builtin_expect (pts_name (fd, &buf, sizeof (_buf), &st), 0))
     {
       int save_errno = errno;
 
@@ -127,10 +128,6 @@ grantpt (int fd)
        return -1;
     }
 
-  struct stat64 st;
-  if (__xstat64 (_STAT_VER, buf, &st) < 0)
-    goto cleanup;
-
   /* Make sure that we own the device.  */
   uid_t uid = __getuid ();
   if (st.st_uid != uid)