4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 #include <sys/mkdev.h>
38 #include <sys/fcntl.h>
39 #include <sys/stropts.h>
40 #include <sys/stream.h>
42 #include <sys/syscall.h>
45 static int xpg4_fixup(int fd
);
46 static void push_module(int fd
);
47 static int isptsfd(int fd
);
48 static void itoa(int i
, char *ptr
);
51 __openat(int dfd
, const char *path
, int oflag
, mode_t mode
)
53 int fd
= syscall(SYS_openat
, dfd
, path
, oflag
, mode
);
54 return (xpg4_fixup(fd
));
58 __open(const char *path
, int oflag
, mode_t mode
)
60 return (__openat(AT_FDCWD
, path
, oflag
, mode
));
66 __openat64(int dfd
, const char *path
, int oflag
, mode_t mode
)
68 int fd
= syscall(SYS_openat64
, dfd
, path
, oflag
, mode
);
69 return (xpg4_fixup(fd
));
73 __open64(const char *path
, int oflag
, mode_t mode
)
75 return (__openat64(AT_FDCWD
, path
, oflag
, mode
));
81 * XPG4v2 requires that open of a slave pseudo terminal device
82 * provides the process with an interface that is identical to
83 * the terminal interface. For a more detailed discussion,
89 if (libc__xpg4
!= 0 && fd
>= 0 && isptsfd(fd
))
95 * Check if the file matches an entry in the /dev/pts directory.
96 * Be careful to preserve errno.
101 char buf
[TTYNAME_MAX
];
103 const char *str2
= "/dev/pts/";
104 struct stat64 fsb
, stb
;
108 if (fstat64(fd
, &fsb
) == 0 && S_ISCHR(fsb
.st_mode
)) {
110 * Do this without strcpy() or strlen(),
111 * to avoid invoking the dynamic linker.
113 while (*str2
!= '\0')
116 * Inline version of minor(dev), to avoid the dynamic linker.
118 itoa(fsb
.st_rdev
& MAXMIN
, str1
);
119 if (stat64(buf
, &stb
) == 0)
120 rval
= (stb
.st_rdev
== fsb
.st_rdev
);
127 * Converts a number to a string (null terminated).
130 itoa(int i
, char *ptr
)
144 *(--ptr
) = i
% 10 + '0';
150 * Push modules to provide tty semantics
155 struct strioctl istr
;
158 istr
.ic_cmd
= PTSSTTY
;
162 if (ioctl(fd
, I_STR
, &istr
) != -1) {
163 (void) ioctl(fd
, __I_PUSH_NOCTTY
, "ptem");
164 (void) ioctl(fd
, __I_PUSH_NOCTTY
, "ldterm");
165 (void) ioctl(fd
, __I_PUSH_NOCTTY
, "ttcompat");
166 istr
.ic_cmd
= PTSSTTY
;
170 (void) ioctl(fd
, I_STR
, &istr
);