From aa9890239a2aef81e64f3f22a31c7e01b6501f69 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 24 Nov 2009 18:50:32 -0800 Subject: 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. --- sysdeps/unix/grantpt.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'sysdeps/unix/grantpt.c') 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) -- cgit 1.4.1