2 +++ b/src/jdk.internal.le/solaris/classes/jdk/internal/org/jline/terminal/impl/jna/JDKNativePty.java 2023-06-02 10:45:50.331153527 +0100
5 + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 + * This code is free software; you can redistribute it and/or modify it
9 + * under the terms of the GNU General Public License version 2 only, as
10 + * published by the Free Software Foundation. Oracle designates this
11 + * particular file as subject to the "Classpath" exception as provided
12 + * by Oracle in the LICENSE file that accompanied this code.
14 + * This code is distributed in the hope that it will be useful, but WITHOUT
15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 + * version 2 for more details (a copy is included in the LICENSE file that
18 + * accompanied this code).
20 + * You should have received a copy of the GNU General Public License version
21 + * 2 along with this work; if not, write to the Free Software Foundation,
22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25 + * or visit www.oracle.com if you need additional information or have any
28 +package jdk.internal.org.jline.terminal.impl.jna;
30 +import java.io.IOException;
31 +import jdk.internal.org.jline.terminal.Attributes;
32 +import jdk.internal.org.jline.terminal.Size;
33 +import jdk.internal.org.jline.terminal.impl.jna.solaris.SolarisNativePty;
34 +import jdk.internal.org.jline.terminal.spi.TerminalProvider;
38 + static JnaNativePty current(TerminalProvider.Stream console) throws IOException {
39 + return SolarisNativePty.current(console);
42 + static JnaNativePty open(Attributes attr, Size size) throws IOException {
43 + return SolarisNativePty.open(attr, size);
46 + static int isatty(int fd) {
47 + return SolarisNativePty.isatty(fd);
50 + static String ttyname(int fd) {
51 + return SolarisNativePty.ttyname(fd);
56 +++ b/src/jdk.internal.le/solaris/classes/jdk/internal/org/jline/terminal/impl/jna/solaris/CLibrary.java 2023-06-02 10:47:56.181885176 +0100
59 + * Copyright (c) 2002-2020, the original author(s).
61 + * This software is distributable under the BSD license. See the terms of the
62 + * BSD license in the documentation provided with this software.
64 + * https://opensource.org/licenses/BSD-3-Clause
66 +package jdk.internal.org.jline.terminal.impl.jna.solaris;
68 +import java.util.Arrays;
69 +import java.util.EnumMap;
70 +import java.util.EnumSet;
71 +import java.util.List;
73 +//import com.sun.jna.LastErrorException;
74 +//import com.sun.jna.Structure;
75 +import jdk.internal.org.jline.terminal.Attributes;
76 +import jdk.internal.org.jline.terminal.Attributes.ControlChar;
77 +import jdk.internal.org.jline.terminal.Attributes.ControlFlag;
78 +import jdk.internal.org.jline.terminal.Attributes.InputFlag;
79 +import jdk.internal.org.jline.terminal.Attributes.LocalFlag;
80 +import jdk.internal.org.jline.terminal.Attributes.OutputFlag;
81 +import jdk.internal.org.jline.terminal.Size;
82 +import jdk.internal.org.jline.terminal.impl.jna.LastErrorException;
84 +public interface CLibrary {//extends com.sun.jna.Library {
86 + void tcgetattr(int fd, termios termios) throws LastErrorException;
88 + void tcsetattr(int fd, int cmd, termios termios) throws LastErrorException;
90 + void ioctl(int fd, long cmd, winsize data) throws LastErrorException;
94 + void ttyname_r(int fd, byte[] buf, int len) throws LastErrorException;
96 + void openpty(int[] master, int[] slave, byte[] name, termios t, winsize s) throws LastErrorException;
98 + class winsize { //extends Structure {
99 + public short ws_row;
100 + public short ws_col;
101 + public short ws_xpixel;
102 + public short ws_ypixel;
107 + public winsize(Size ws) {
108 + ws_row = (short) ws.getRows();
109 + ws_col = (short) ws.getColumns();
112 + public Size toSize() {
113 + return new Size(ws_col, ws_row);
117 +// protected List<String> getFieldOrder() {
118 +// return Arrays.asList( //
127 + class termios {//extends Structure {
129 + public int c_iflag;
130 + public int c_oflag;
131 + public int c_cflag;
132 + public int c_lflag;
133 + public byte[] c_cc = new byte[32];
136 +// protected List<String> getFieldOrder() {
137 +// return Arrays.asList( //
149 + public termios(Attributes t) {
151 + c_iflag = setFlag(t.getInputFlag(InputFlag.IGNBRK), IGNBRK, c_iflag);
152 + c_iflag = setFlag(t.getInputFlag(InputFlag.BRKINT), BRKINT, c_iflag);
153 + c_iflag = setFlag(t.getInputFlag(InputFlag.IGNPAR), IGNPAR, c_iflag);
154 + c_iflag = setFlag(t.getInputFlag(InputFlag.PARMRK), PARMRK, c_iflag);
155 + c_iflag = setFlag(t.getInputFlag(InputFlag.INPCK), INPCK, c_iflag);
156 + c_iflag = setFlag(t.getInputFlag(InputFlag.ISTRIP), ISTRIP, c_iflag);
157 + c_iflag = setFlag(t.getInputFlag(InputFlag.INLCR), INLCR, c_iflag);
158 + c_iflag = setFlag(t.getInputFlag(InputFlag.IGNCR), IGNCR, c_iflag);
159 + c_iflag = setFlag(t.getInputFlag(InputFlag.ICRNL), ICRNL, c_iflag);
160 + c_iflag = setFlag(t.getInputFlag(InputFlag.IXON), IXON, c_iflag);
161 + c_iflag = setFlag(t.getInputFlag(InputFlag.IXOFF), IXOFF, c_iflag);
162 + c_iflag = setFlag(t.getInputFlag(InputFlag.IXANY), IXANY, c_iflag);
163 + c_iflag = setFlag(t.getInputFlag(InputFlag.IMAXBEL), IMAXBEL, c_iflag);
164 + c_iflag = setFlag(t.getInputFlag(InputFlag.IUTF8), IUTF8, c_iflag);
166 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.OPOST), OPOST, c_oflag);
167 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.ONLCR), ONLCR, c_oflag);
168 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.OCRNL), OCRNL, c_oflag);
169 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.ONOCR), ONOCR, c_oflag);
170 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.ONLRET), ONLRET, c_oflag);
171 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.OFILL), OFILL, c_oflag);
172 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.NLDLY), NLDLY, c_oflag);
173 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.TABDLY), TABDLY, c_oflag);
174 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.CRDLY), CRDLY, c_oflag);
175 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.FFDLY), FFDLY, c_oflag);
176 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.BSDLY), BSDLY, c_oflag);
177 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.VTDLY), VTDLY, c_oflag);
178 + c_oflag = setFlag(t.getOutputFlag(OutputFlag.OFDEL), OFDEL, c_oflag);
180 + c_cflag = setFlag(t.getControlFlag(ControlFlag.CS5), CS5, c_cflag);
181 + c_cflag = setFlag(t.getControlFlag(ControlFlag.CS6), CS6, c_cflag);
182 + c_cflag = setFlag(t.getControlFlag(ControlFlag.CS7), CS7, c_cflag);
183 + c_cflag = setFlag(t.getControlFlag(ControlFlag.CS8), CS8, c_cflag);
184 + c_cflag = setFlag(t.getControlFlag(ControlFlag.CSTOPB), CSTOPB, c_cflag);
185 + c_cflag = setFlag(t.getControlFlag(ControlFlag.CREAD), CREAD, c_cflag);
186 + c_cflag = setFlag(t.getControlFlag(ControlFlag.PARENB), PARENB, c_cflag);
187 + c_cflag = setFlag(t.getControlFlag(ControlFlag.PARODD), PARODD, c_cflag);
188 + c_cflag = setFlag(t.getControlFlag(ControlFlag.HUPCL), HUPCL, c_cflag);
189 + c_cflag = setFlag(t.getControlFlag(ControlFlag.CLOCAL), CLOCAL, c_cflag);
191 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ECHOKE), ECHOKE, c_lflag);
192 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ECHOE), ECHOE, c_lflag);
193 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ECHOK), ECHOK, c_lflag);
194 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ECHO), ECHO, c_lflag);
195 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ECHONL), ECHONL, c_lflag);
196 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ECHOPRT), ECHOPRT, c_lflag);
197 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ECHOCTL), ECHOCTL, c_lflag);
198 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ISIG), ISIG, c_lflag);
199 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.ICANON), ICANON, c_lflag);
200 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.IEXTEN), IEXTEN, c_lflag);
201 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.EXTPROC), EXTPROC, c_lflag);
202 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.TOSTOP), TOSTOP, c_lflag);
203 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.FLUSHO), FLUSHO, c_lflag);
204 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.PENDIN), PENDIN, c_lflag);
205 + c_lflag = setFlag(t.getLocalFlag(LocalFlag.NOFLSH), NOFLSH, c_lflag);
207 + c_cc[VEOF] = (byte) t.getControlChar(ControlChar.VEOF);
208 + c_cc[VEOL] = (byte) t.getControlChar(ControlChar.VEOL);
209 + c_cc[VEOL2] = (byte) t.getControlChar(ControlChar.VEOL2);
210 + c_cc[VERASE] = (byte) t.getControlChar(ControlChar.VERASE);
211 + c_cc[VWERASE] = (byte) t.getControlChar(ControlChar.VWERASE);
212 + c_cc[VKILL] = (byte) t.getControlChar(ControlChar.VKILL);
213 + c_cc[VREPRINT] = (byte) t.getControlChar(ControlChar.VREPRINT);
214 + c_cc[VINTR] = (byte) t.getControlChar(ControlChar.VINTR);
215 + c_cc[VQUIT] = (byte) t.getControlChar(ControlChar.VQUIT);
216 + c_cc[VSUSP] = (byte) t.getControlChar(ControlChar.VSUSP);
217 + c_cc[VSTART] = (byte) t.getControlChar(ControlChar.VSTART);
218 + c_cc[VSTOP] = (byte) t.getControlChar(ControlChar.VSTOP);
219 + c_cc[VLNEXT] = (byte) t.getControlChar(ControlChar.VLNEXT);
220 + c_cc[VDISCARD] = (byte) t.getControlChar(ControlChar.VDISCARD);
221 + c_cc[VMIN] = (byte) t.getControlChar(ControlChar.VMIN);
222 + c_cc[VTIME] = (byte) t.getControlChar(ControlChar.VTIME);
225 + private int setFlag(boolean flag, int value, int org) {
226 + return flag ? (org | value) : org;
229 + public Attributes toAttributes() {
230 + Attributes attr = new Attributes();
232 + EnumSet<InputFlag> iflag = attr.getInputFlags();
233 + addFlag(c_iflag, iflag, InputFlag.IGNBRK, IGNBRK);
234 + addFlag(c_iflag, iflag, InputFlag.IGNBRK, IGNBRK);
235 + addFlag(c_iflag, iflag, InputFlag.BRKINT, BRKINT);
236 + addFlag(c_iflag, iflag, InputFlag.IGNPAR, IGNPAR);
237 + addFlag(c_iflag, iflag, InputFlag.PARMRK, PARMRK);
238 + addFlag(c_iflag, iflag, InputFlag.INPCK, INPCK);
239 + addFlag(c_iflag, iflag, InputFlag.ISTRIP, ISTRIP);
240 + addFlag(c_iflag, iflag, InputFlag.INLCR, INLCR);
241 + addFlag(c_iflag, iflag, InputFlag.IGNCR, IGNCR);
242 + addFlag(c_iflag, iflag, InputFlag.ICRNL, ICRNL);
243 + addFlag(c_iflag, iflag, InputFlag.IXON, IXON);
244 + addFlag(c_iflag, iflag, InputFlag.IXOFF, IXOFF);
245 + addFlag(c_iflag, iflag, InputFlag.IXANY, IXANY);
246 + addFlag(c_iflag, iflag, InputFlag.IMAXBEL, IMAXBEL);
247 + addFlag(c_iflag, iflag, InputFlag.IUTF8, IUTF8);
249 + EnumSet<OutputFlag> oflag = attr.getOutputFlags();
250 + addFlag(c_oflag, oflag, OutputFlag.OPOST, OPOST);
251 + addFlag(c_oflag, oflag, OutputFlag.ONLCR, ONLCR);
252 + addFlag(c_oflag, oflag, OutputFlag.OCRNL, OCRNL);
253 + addFlag(c_oflag, oflag, OutputFlag.ONOCR, ONOCR);
254 + addFlag(c_oflag, oflag, OutputFlag.ONLRET, ONLRET);
255 + addFlag(c_oflag, oflag, OutputFlag.OFILL, OFILL);
256 + addFlag(c_oflag, oflag, OutputFlag.NLDLY, NLDLY);
257 + addFlag(c_oflag, oflag, OutputFlag.TABDLY, TABDLY);
258 + addFlag(c_oflag, oflag, OutputFlag.CRDLY, CRDLY);
259 + addFlag(c_oflag, oflag, OutputFlag.FFDLY, FFDLY);
260 + addFlag(c_oflag, oflag, OutputFlag.BSDLY, BSDLY);
261 + addFlag(c_oflag, oflag, OutputFlag.VTDLY, VTDLY);
262 + addFlag(c_oflag, oflag, OutputFlag.OFDEL, OFDEL);
264 + EnumSet<ControlFlag> cflag = attr.getControlFlags();
265 + addFlag(c_cflag, cflag, ControlFlag.CS5, CS5);
266 + addFlag(c_cflag, cflag, ControlFlag.CS6, CS6);
267 + addFlag(c_cflag, cflag, ControlFlag.CS7, CS7);
268 + addFlag(c_cflag, cflag, ControlFlag.CS8, CS8);
269 + addFlag(c_cflag, cflag, ControlFlag.CSTOPB, CSTOPB);
270 + addFlag(c_cflag, cflag, ControlFlag.CREAD, CREAD);
271 + addFlag(c_cflag, cflag, ControlFlag.PARENB, PARENB);
272 + addFlag(c_cflag, cflag, ControlFlag.PARODD, PARODD);
273 + addFlag(c_cflag, cflag, ControlFlag.HUPCL, HUPCL);
274 + addFlag(c_cflag, cflag, ControlFlag.CLOCAL, CLOCAL);
276 + EnumSet<LocalFlag> lflag = attr.getLocalFlags();
277 + addFlag(c_lflag, lflag, LocalFlag.ECHOKE, ECHOKE);
278 + addFlag(c_lflag, lflag, LocalFlag.ECHOE, ECHOE);
279 + addFlag(c_lflag, lflag, LocalFlag.ECHOK, ECHOK);
280 + addFlag(c_lflag, lflag, LocalFlag.ECHO, ECHO);
281 + addFlag(c_lflag, lflag, LocalFlag.ECHONL, ECHONL);
282 + addFlag(c_lflag, lflag, LocalFlag.ECHOPRT, ECHOPRT);
283 + addFlag(c_lflag, lflag, LocalFlag.ECHOCTL, ECHOCTL);
284 + addFlag(c_lflag, lflag, LocalFlag.ISIG, ISIG);
285 + addFlag(c_lflag, lflag, LocalFlag.ICANON, ICANON);
286 + addFlag(c_lflag, lflag, LocalFlag.IEXTEN, IEXTEN);
287 + addFlag(c_lflag, lflag, LocalFlag.EXTPROC, EXTPROC);
288 + addFlag(c_lflag, lflag, LocalFlag.TOSTOP, TOSTOP);
289 + addFlag(c_lflag, lflag, LocalFlag.FLUSHO, FLUSHO);
290 + addFlag(c_lflag, lflag, LocalFlag.PENDIN, PENDIN);
291 + addFlag(c_lflag, lflag, LocalFlag.NOFLSH, NOFLSH);
293 + EnumMap<ControlChar, Integer> cc = attr.getControlChars();
294 + cc.put(ControlChar.VEOF, (int) c_cc[VEOF]);
295 + cc.put(ControlChar.VEOL, (int) c_cc[VEOL]);
296 + cc.put(ControlChar.VEOL2, (int) c_cc[VEOL2]);
297 + cc.put(ControlChar.VERASE, (int) c_cc[VERASE]);
298 + cc.put(ControlChar.VWERASE, (int) c_cc[VWERASE]);
299 + cc.put(ControlChar.VKILL, (int) c_cc[VKILL]);
300 + cc.put(ControlChar.VREPRINT, (int) c_cc[VREPRINT]);
301 + cc.put(ControlChar.VINTR, (int) c_cc[VINTR]);
302 + cc.put(ControlChar.VQUIT, (int) c_cc[VQUIT]);
303 + cc.put(ControlChar.VSUSP, (int) c_cc[VSUSP]);
304 + cc.put(ControlChar.VSTART, (int) c_cc[VSTART]);
305 + cc.put(ControlChar.VSTOP, (int) c_cc[VSTOP]);
306 + cc.put(ControlChar.VLNEXT, (int) c_cc[VLNEXT]);
307 + cc.put(ControlChar.VDISCARD, (int) c_cc[VDISCARD]);
308 + cc.put(ControlChar.VMIN, (int) c_cc[VMIN]);
309 + cc.put(ControlChar.VTIME, (int) c_cc[VTIME]);
314 + private <T extends Enum<T>> void addFlag(int value, EnumSet<T> flags, T flag, int v) {
315 + if ((value & v) != 0) {
323 + int _TIOC = ('T' << 8);
324 + int TIOCGWINSZ = (_TIOC | 104);
325 + int TIOCSWINSZ = (_TIOC | 103);
345 + int IGNBRK = 0x0000001;
346 + int BRKINT = 0x0000002;
347 + int IGNPAR = 0x0000004;
348 + int PARMRK = 0x0000010;
349 + int INPCK = 0x0000020;
350 + int ISTRIP = 0x0000040;
351 + int INLCR = 0x0000100;
352 + int IGNCR = 0x0000200;
353 + int ICRNL = 0x0000400;
354 + int IUCLC = 0x0001000;
355 + int IXON = 0x0002000;
356 + int IXANY = 0x0004000;
357 + int IXOFF = 0x0010000;
358 + int IMAXBEL = 0x0020000;
359 + int IUTF8 = 0x0040000;
361 + int OPOST = 0x0000001;
362 + int OLCUC = 0x0000002;
363 + int ONLCR = 0x0000004;
364 + int OCRNL = 0x0000010;
365 + int ONOCR = 0x0000020;
366 + int ONLRET = 0x0000040;
367 + int OFILL = 0x0000100;
368 + int OFDEL = 0x0000200;
369 + int NLDLY = 0x0000400;
370 + int NL0 = 0x0000000;
371 + int NL1 = 0x0000400;
372 + int CRDLY = 0x0003000;
373 + int CR0 = 0x0000000;
374 + int CR1 = 0x0001000;
375 + int CR2 = 0x0002000;
376 + int CR3 = 0x0003000;
377 + int TABDLY = 0x0014000;
378 + int TAB0 = 0x0000000;
379 + int TAB1 = 0x0004000;
380 + int TAB2 = 0x0010000;
381 + int TAB3 = 0x0014000;
382 + int XTABS = 0x0014000;
383 + int BSDLY = 0x0020000;
384 + int BS0 = 0x0000000;
385 + int BS1 = 0x0020000;
386 + int VTDLY = 0x0040000;
387 + int VT0 = 0x0000000;
388 + int VT1 = 0x0040000;
389 + int FFDLY = 0x0100000;
390 + int FF0 = 0x0000000;
391 + int FF1 = 0x0100000;
393 + int CBAUD = 0x0010017;
394 + int B0 = 0x0000000;
395 + int B50 = 0x0000001;
396 + int B75 = 0x0000002;
397 + int B110 = 0x0000003;
398 + int B134 = 0x0000004;
399 + int B150 = 0x0000005;
400 + int B200 = 0x0000006;
401 + int B300 = 0x0000007;
402 + int B600 = 0x0000010;
403 + int B1200 = 0x0000011;
404 + int B1800 = 0x0000012;
405 + int B2400 = 0x0000013;
406 + int B4800 = 0x0000014;
407 + int B9600 = 0x0000015;
408 + int B19200 = 0x0000016;
409 + int B38400 = 0x0000017;
410 + int EXTA = 0xB19200;
411 + int EXTB = 0xB38400;
412 + int CSIZE = 0x0000060;
413 + int CS5 = 0x0000000;
414 + int CS6 = 0x0000020;
415 + int CS7 = 0x0000040;
416 + int CS8 = 0x0000060;
417 + int CSTOPB = 0x0000100;
418 + int CREAD = 0x0000200;
419 + int PARENB = 0x0000400;
420 + int PARODD = 0x0001000;
421 + int HUPCL = 0x0002000;
422 + int CLOCAL = 0x0004000;
424 + int ISIG = 0x0000001;
425 + int ICANON = 0x0000002;
426 + int XCASE = 0x0000004;
427 + int ECHO = 0x0000010;
428 + int ECHOE = 0x0000020;
429 + int ECHOK = 0x0000040;
430 + int ECHONL = 0x0000100;
431 + int NOFLSH = 0x0000200;
432 + int TOSTOP = 0x0000400;
433 + int ECHOCTL = 0x0001000;
434 + int ECHOPRT = 0x0002000;
435 + int ECHOKE = 0x0004000;
436 + int FLUSHO = 0x0010000;
437 + int PENDIN = 0x0040000;
438 + int IEXTEN = 0x0100000;
439 + int EXTPROC = 0x0200000;
442 + int TCSADRAIN = 0x1;
443 + int TCSAFLUSH = 0x2;
446 +++ b/src/jdk.internal.le/solaris/classes/jdk/internal/org/jline/terminal/impl/jna/solaris/CLibraryImpl.java 2023-06-02 10:52:24.003243641 +0100
449 + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
450 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
452 + * This code is free software; you can redistribute it and/or modify it
453 + * under the terms of the GNU General Public License version 2 only, as
454 + * published by the Free Software Foundation. Oracle designates this
455 + * particular file as subject to the "Classpath" exception as provided
456 + * by Oracle in the LICENSE file that accompanied this code.
458 + * This code is distributed in the hope that it will be useful, but WITHOUT
459 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
460 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
461 + * version 2 for more details (a copy is included in the LICENSE file that
462 + * accompanied this code).
464 + * You should have received a copy of the GNU General Public License version
465 + * 2 along with this work; if not, write to the Free Software Foundation,
466 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
468 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
469 + * or visit www.oracle.com if you need additional information or have any
472 +package jdk.internal.org.jline.terminal.impl.jna.solaris;
474 +import jdk.internal.org.jline.terminal.impl.jna.LastErrorException;
476 +public final class CLibraryImpl implements CLibrary {
479 + System.loadLibrary("le");
483 + private static native void initIDs();
486 + public native void tcgetattr(int fd, termios termios) throws LastErrorException;
489 + public native void tcsetattr(int fd, int cmd, termios termios) throws LastErrorException;
492 + public void ioctl(int fd, long cmd, winsize data) throws LastErrorException {
493 + if (cmd == CLibrary.TIOCGWINSZ || cmd == CLibrary.TIOCSWINSZ) {
494 + ioctl0(fd, cmd, data);
496 + throw new UnsupportedOperationException("Command: " + cmd + ", not supported.");
500 + private native void ioctl0(int fd, long cmd, winsize data) throws LastErrorException;
503 + public native int isatty(int fd);
506 + public native void ttyname_r(int fd, byte[] buf, int len) throws LastErrorException;
509 + public void openpty(int[] master, int[] slave, byte[] name, CLibrary.termios t, CLibrary.winsize s) throws LastErrorException {
510 + throw new UnsupportedOperationException();
515 +++ b/src/jdk.internal.le/solaris/classes/jdk/internal/org/jline/terminal/impl/jna/solaris/SolarisNativePty.java 2023-06-02 10:25:31.059689102 +0100
518 + * Copyright (c) 2002-2020, the original author(s).
520 + * This software is distributable under the BSD license. See the terms of the
521 + * BSD license in the documentation provided with this software.
523 + * https://opensource.org/licenses/BSD-3-Clause
525 +package jdk.internal.org.jline.terminal.impl.jna.solaris;
527 +import java.io.FileDescriptor;
528 +import java.io.IOException;
530 +import jdk.internal.org.jline.terminal.Attributes;
531 +import jdk.internal.org.jline.terminal.Size;
532 +import jdk.internal.org.jline.terminal.impl.jna.JnaNativePty;
533 +import jdk.internal.org.jline.terminal.spi.TerminalProvider;
535 +//import com.sun.jna.Native;
536 +//import com.sun.jna.Platform;
538 +import static jdk.internal.org.jline.terminal.impl.jna.solaris.CLibrary.TCSANOW;
539 +import static jdk.internal.org.jline.terminal.impl.jna.solaris.CLibrary.TIOCGWINSZ;
540 +import static jdk.internal.org.jline.terminal.impl.jna.solaris.CLibrary.TIOCSWINSZ;
541 +import static jdk.internal.org.jline.terminal.impl.jna.solaris.CLibrary.termios;
542 +import static jdk.internal.org.jline.terminal.impl.jna.solaris.CLibrary.winsize;
544 +public class SolarisNativePty extends JnaNativePty {
546 +// private static final CLibrary C_LIBRARY = Native.load(Platform.C_LIBRARY_NAME, CLibrary.class);
547 + private static final CLibrary C_LIBRARY = new CLibraryImpl();
549 + public static SolarisNativePty current(TerminalProvider.Stream consoleStream) throws IOException {
550 + switch (consoleStream) {
552 + return new SolarisNativePty(-1, null, 0, FileDescriptor.in, 1, FileDescriptor.out, ttyname(0));
554 + return new SolarisNativePty(-1, null, 0, FileDescriptor.in, 2, FileDescriptor.err, ttyname(0));
556 + throw new IllegalArgumentException("Unsupport stream for console: " + consoleStream);
560 + public static SolarisNativePty open(Attributes attr, Size size) throws IOException {
561 + int[] master = new int[1];
562 + int[] slave = new int[1];
563 + byte[] buf = new byte[64];
564 + C_LIBRARY.openpty(master, slave, buf,
565 + attr != null ? new termios(attr) : null,
566 + size != null ? new winsize(size) : null);
568 + while (buf[len] != 0) {
571 + String name = new String(buf, 0, len);
572 + return new SolarisNativePty(master[0], newDescriptor(master[0]), slave[0], newDescriptor(slave[0]), name);
575 + public SolarisNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, String name) {
576 + super(master, masterFD, slave, slaveFD, name);
579 + public SolarisNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
580 + super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
584 + public Attributes getAttr() throws IOException {
585 + termios termios = new termios();
586 + C_LIBRARY.tcgetattr(getSlave(), termios);
587 + return termios.toAttributes();
591 + protected void doSetAttr(Attributes attr) throws IOException {
592 + termios termios = new termios(attr);
593 + C_LIBRARY.tcsetattr(getSlave(), TCSANOW, termios);
597 + public Size getSize() throws IOException {
598 + winsize sz = new winsize();
599 + C_LIBRARY.ioctl(getSlave(), TIOCGWINSZ, sz);
600 + return sz.toSize();
604 + public void setSize(Size size) throws IOException {
605 + winsize sz = new winsize(size);
606 + C_LIBRARY.ioctl(getSlave(), TIOCSWINSZ, sz);
609 + public static int isatty(int fd) {
610 + return C_LIBRARY.isatty(fd);
613 + public static String ttyname(int slave) {
614 + byte[] buf = new byte[64];
615 + C_LIBRARY.ttyname_r(slave, buf, buf.length);
617 + while (buf[len] != 0) {
620 + return new String(buf, 0, len);
625 +++ b/src/jdk.internal.le/solaris/native/lible/CLibrary.cpp 2023-06-02 11:05:11.905773520 +0100
628 + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
629 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
631 + * This code is free software; you can redistribute it and/or modify it
632 + * under the terms of the GNU General Public License version 2 only, as
633 + * published by the Free Software Foundation. Oracle designates this
634 + * particular file as subject to the "Classpath" exception as provided
635 + * by Oracle in the LICENSE file that accompanied this code.
637 + * This code is distributed in the hope that it will be useful, but WITHOUT
638 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
639 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
640 + * version 2 for more details (a copy is included in the LICENSE file that
641 + * accompanied this code).
643 + * You should have received a copy of the GNU General Public License version
644 + * 2 along with this work; if not, write to the Free Software Foundation,
645 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
647 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
648 + * or visit www.oracle.com if you need additional information or have any
653 +#include "jni_util.h"
655 +#include "jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl.h"
659 +#include <termios.h>
661 +#include <sys/ioctl.h>
663 +static jclass lastErrorExceptionClass;
664 +static jmethodID lastErrorExceptionConstructor;
666 +static jclass termios_j;
667 +static jfieldID c_iflag;
668 +static jfieldID c_oflag;
669 +static jfieldID c_cflag;
670 +static jfieldID c_lflag;
671 +static jfieldID c_cc;
673 +static jclass winsize_j;
674 +static jfieldID ws_row;
675 +static jfieldID ws_col;
676 +static jfieldID ws_xpixel;
677 +static jfieldID ws_ypixel;
679 +static void throw_errno(JNIEnv *env);
681 +JNIEXPORT void JNICALL Java_jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl_initIDs
682 + (JNIEnv *env, jclass unused) {
684 + cls = env->FindClass("jdk/internal/org/jline/terminal/impl/jna/LastErrorException");
686 + lastErrorExceptionClass = (jclass) env->NewGlobalRef(cls);
687 + lastErrorExceptionConstructor = env->GetMethodID(lastErrorExceptionClass, "<init>", "(J)V");
688 + CHECK_NULL(lastErrorExceptionConstructor);
690 + cls = env->FindClass("jdk/internal/org/jline/terminal/impl/jna/solaris/CLibrary$termios");
692 + termios_j = (jclass) env->NewGlobalRef(cls);
693 + c_iflag = env->GetFieldID(termios_j, "c_iflag", "I");
694 + CHECK_NULL(c_iflag);
695 + c_oflag = env->GetFieldID(termios_j, "c_oflag", "I");
696 + CHECK_NULL(c_oflag);
697 + c_cflag = env->GetFieldID(termios_j, "c_cflag", "I");
698 + CHECK_NULL(c_cflag);
699 + c_lflag = env->GetFieldID(termios_j, "c_lflag", "I");
700 + CHECK_NULL(c_lflag);
701 + c_cc = env->GetFieldID(termios_j, "c_cc", "[B");
704 + cls = env->FindClass("jdk/internal/org/jline/terminal/impl/jna/solaris/CLibrary$winsize");
706 + winsize_j = (jclass) env->NewGlobalRef(cls);
707 + ws_row = env->GetFieldID(winsize_j, "ws_row", "S");
708 + CHECK_NULL(ws_row);
709 + ws_col = env->GetFieldID(winsize_j, "ws_col", "S");
710 + CHECK_NULL(ws_col);
711 + ws_xpixel= env->GetFieldID(winsize_j, "ws_xpixel", "S");
712 + CHECK_NULL(ws_xpixel);
713 + ws_ypixel= env->GetFieldID(winsize_j, "ws_ypixel", "S");
714 + CHECK_NULL(ws_ypixel);
717 +JNIEXPORT void JNICALL Java_jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl_tcgetattr
718 + (JNIEnv *env, jobject, jint fd, jobject result) {
721 + if (tcgetattr(fd, &data) != 0) {
726 + env->SetIntField(result, c_iflag, data.c_iflag);
727 + env->SetIntField(result, c_oflag, data.c_oflag);
728 + env->SetIntField(result, c_cflag, data.c_cflag);
729 + env->SetIntField(result, c_lflag, data.c_lflag);
730 + jbyteArray c_ccValue = (jbyteArray) env->GetObjectField(result, c_cc);
731 + env->SetByteArrayRegion(c_ccValue, 0, NCCS, (signed char *) data.c_cc);//TODO: cast?
735 + * Class: jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl
736 + * Method: tcsetattr
737 + * Signature: (IILjdk/internal/org/jline/terminal/impl/jna/solaris/CLibrary/termios;)V
739 +JNIEXPORT void JNICALL Java_jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl_tcsetattr
740 + (JNIEnv *env, jobject, jint fd, jint cmd, jobject input) {
743 + data.c_iflag = env->GetIntField(input, c_iflag);
744 + data.c_oflag = env->GetIntField(input, c_oflag);
745 + data.c_cflag = env->GetIntField(input, c_cflag);
746 + data.c_lflag = env->GetIntField(input, c_lflag);
747 + jbyteArray c_ccValue = (jbyteArray) env->GetObjectField(input, c_cc);
748 + env->GetByteArrayRegion(c_ccValue, 0, NCCS, (jbyte *) data.c_cc);
750 + if (tcsetattr(fd, cmd, &data) != 0) {
756 + * Class: jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl
758 + * Signature: (IILjdk/internal/org/jline/terminal/impl/jna/solaris/CLibrary/winsize;)V
760 +JNIEXPORT void JNICALL Java_jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl_ioctl0
761 + (JNIEnv *env, jobject, jint fd, jlong cmd, jobject data) {
764 + ws.ws_row = env->GetIntField(data, ws_row);
765 + ws.ws_col = env->GetIntField(data, ws_col);
766 + ws.ws_xpixel = env->GetIntField(data, ws_xpixel);
767 + ws.ws_ypixel = env->GetIntField(data, ws_ypixel);
769 + if (ioctl(fd, cmd, &ws) != 0) {
774 + env->SetIntField(data, ws_row, ws.ws_row);
775 + env->SetIntField(data, ws_col, ws.ws_col);
776 + env->SetIntField(data, ws_xpixel, ws.ws_xpixel);
777 + env->SetIntField(data, ws_ypixel, ws.ws_ypixel);
781 + * Class: jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl
785 +JNIEXPORT jint JNICALL Java_jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl_isatty
786 + (JNIEnv *, jobject, jint fd) {
791 + * Class: jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl
792 + * Method: ttyname_r
793 + * Signature: (I[BI)V
795 +JNIEXPORT void JNICALL Java_jdk_internal_org_jline_terminal_impl_jna_solaris_CLibraryImpl_ttyname_1r
796 + (JNIEnv *env, jobject, jint fd, jbyteArray buf, jint len) {
797 + char *data = new char[len];
798 + int error = ttyname_r(fd, data, len);
805 + env->SetByteArrayRegion(buf, 0, len, (jbyte *) data);
810 + * Throws LastErrorException based on the errno:
812 +static void throw_errno(JNIEnv *env) {
813 + jobject exc = env->NewObject(lastErrorExceptionClass,
814 + lastErrorExceptionConstructor,
816 + env->Throw((jthrowable) exc);
818 --- a/make/modules/jdk.internal.le/Lib.gmk Tue May 23 22:32:28 2023
819 +++ b/make/modules/jdk.internal.le/Lib.gmk Fri Jun 2 11:33:06 2023
822 ################################################################################
824 -ifeq ($(call isTargetOs, linux macosx windows), true)
825 +ifeq ($(call isTargetOs, linux macosx solaris windows), true)
827 $(eval $(call SetupJdkLibrary, BUILD_LIBLE, \