1 /* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #if !defined __ASSUME_DEVPTS__
27 # include <sys/statfs.h>
29 /* Constant that identifies the `devpts' filesystem. */
30 # define DEVPTS_SUPER_MAGIC 0x1cd1
31 /* Constant that identifies the `devfs' filesystem. */
32 # define DEVFS_SUPER_MAGIC 0x1373
35 /* Path to the master pseudo terminal cloning device. */
36 #define _PATH_DEVPTMX _PATH_DEV "ptmx"
37 /* Directory containing the UNIX98 pseudo terminals. */
38 #define _PATH_DEVPTS _PATH_DEV "pts"
40 #if !defined __UNIX98PTY_ONLY__
41 /* Prototype for function that opens BSD-style master pseudo-terminals. */
42 extern int __bsd_getpt (void) attribute_hidden;
45 libc_hidden_proto(open)
46 libc_hidden_proto(close)
48 /* Open a master pseudo terminal and return its file descriptor. */
52 #if !defined __UNIX98PTY_ONLY__
53 static int have_no_dev_ptmx;
57 #if !defined __UNIX98PTY_ONLY__
58 if (!have_no_dev_ptmx)
61 fd = open (_PATH_DEVPTMX, O_RDWR);
64 #if defined __ASSUME_DEVPTS__
68 static int devpts_mounted;
70 /* Check that the /dev/pts filesystem is mounted
71 or if /dev is a devfs filesystem (this implies /dev/pts). */
73 || (statfs (_PATH_DEVPTS, &fsbuf) == 0
74 && fsbuf.f_type == DEVPTS_SUPER_MAGIC)
75 || (statfs (_PATH_DEV, &fsbuf) == 0
76 && fsbuf.f_type == DEVFS_SUPER_MAGIC))
78 /* Everything is ok. */
83 /* If /dev/pts is not mounted then the UNIX98 pseudo terminals
86 #if !defined __UNIX98PTY_ONLY__
93 #if !defined __UNIX98PTY_ONLY__
94 if (errno == ENOENT || errno == ENODEV)
102 #if !defined __UNIX98PTY_ONLY__
103 return __bsd_getpt ();
107 #if !defined __UNIX98PTY_ONLY__
108 # define PTYNAME1 "pqrstuvwxyzabcde";
109 # define PTYNAME2 "0123456789abcdef";
111 # define __getpt __bsd_getpt
112 # include "bsd_getpt.c"