File: pty.c

package info (click to toggle)
eclipse-cdt 9.9.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 145,456 kB
  • sloc: java: 1,114,843; xml: 64,727; javascript: 18,756; cpp: 5,269; ansic: 3,171; makefile: 1,508; asm: 814; sh: 295; f90: 22; python: 5
file content (73 lines) | stat: -rw-r--r-- 1,848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2002, 2010 QNX Software Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     QNX Software Systems - initial API and implementation
 *     Wind River Systems, Inc.
 *******************************************************************************/
#include <sys/ioctl.h>
#include "PTY.h"
#include "openpty.h"

/*
 * Class:     org_eclipse_cdt_utils_pty_PTY
 * Method:    forkpty
 * Signature: ()I
 */
JNIEXPORT jstring JNICALL
Java_org_eclipse_cdt_utils_pty_PTY_openMaster (JNIEnv *env, jobject jobj, jboolean console) {
	jfieldID fid; /* Store the field ID */
	jstring jstr = NULL;
	int master = -1;
	char line[1024];	/* FIXME: Should be enough */
	jclass cls;

	line[0] = '\0';

	master = ptym_open(line);
	if (master >= 0) {
		// turn off echo
		if (console) {
			set_noecho(master);
		}

		/* Get a reference to the obj's class */
		cls = (*env)->GetObjectClass(env, jobj);

		/* Set the master fd.  */
		fid = (*env)->GetFieldID(env, cls, "master", "I");
		if (fid == NULL) {
			return NULL;
		}
		(*env)->SetIntField(env, jobj, fid, (jint)master);

		/* Create a new String for the slave.  */
		jstr = (*env)->NewStringUTF(env, line);
	}
	return jstr;
}

JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTY_change_1window_1size
  (JNIEnv *env, jobject jobj, jint fdm, jint width, jint height)
{
#ifdef	TIOCGWINSZ
	struct winsize win;

	win.ws_col = width;
	win.ws_row = height;
	win.ws_xpixel = 0;
	win.ws_ypixel = 0;

	return ioctl(fdm, TIOCSWINSZ, &win);
#else
	return 0;
#endif
}