New patch for grantpt
Jakub Jelinek
jakub@redhat.com
Tue Dec 18 06:00:00 GMT 2001
On Tue, Dec 18, 2001 at 02:52:45PM +0100, Thorsten Kukuk wrote:
> @@ -16,6 +16,8 @@
> Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> 02111-1307 USA. */
>
> +#include <errno.h>
> +#include <fcntl.h>
> #include <limits.h>
> #include <stdlib.h>
> #include <sys/statfs.h>
> @@ -45,8 +47,20 @@
> #endif
> char *buf = _buf;
>
> - if (pts_name (fd, &buf, sizeof (_buf)))
> + /* Check, if the file descriptor is valid. pts_name returns the
> + wrong errno number, so we cannot use that. */
> + if (__builtin_expect (__libc_fcntl (fd, F_GETFD), 0) == -1
> + && errno == EBADF)
> return -1;
> +
> + if (pts_name (fd, &buf, sizeof (_buf)))
> + {
> + /* If the filedescriptor is no TTY, grantpt has to set errno
> + to EINVAL. */
> + if (errno == ENOTTY)
> + __set_errno (EINVAL);
> + return -1;
> + }
Cannot the
> + if (__builtin_expect (__libc_fcntl (fd, F_GETFD), 0) == -1
> + && errno == EBADF)
test be done only if pts_name failed, so that apps passing correct file
descriptors are not punished?
(saving/restoring errno around it).
Jakub
More information about the Libc-hacker
mailing list