diff options
Diffstat (limited to 'core/org.eclipse.cdt.core.qnx')
-rw-r--r-- | core/org.eclipse.cdt.core.qnx/ChangeLog | 6 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.qnx/library/pty/openpty.c | 103 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.qnx/library/pty/pty.c | 35 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.qnx/library/pty/ptyio.c | 103 |
4 files changed, 247 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.qnx/ChangeLog b/core/org.eclipse.cdt.core.qnx/ChangeLog index 9c78af3a5e1..3d0cc250ab0 100644 --- a/core/org.eclipse.cdt.core.qnx/ChangeLog +++ b/core/org.eclipse.cdt.core.qnx/ChangeLog @@ -1,3 +1,9 @@ +2002-11-04 Alain Magloire + + * library/pty/pty.c: New file. + * library/pty/ptyio.c: New file. + * library/pty/openpty.c: New file. + 2002-10-17 Alain Magloire * os/qnx/x86/libspawner.so: Regenarated. diff --git a/core/org.eclipse.cdt.core.qnx/library/pty/openpty.c b/core/org.eclipse.cdt.core.qnx/library/pty/openpty.c new file mode 100644 index 00000000000..a946423199b --- /dev/null +++ b/core/org.eclipse.cdt.core.qnx/library/pty/openpty.c @@ -0,0 +1,103 @@ +/* + * (c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <termios.h> +#include <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <grp.h> + +#include <stdlib.h> + +/** + * This is taken from R. W. Stevens book. + * Alain Magloire. + */ + +int ptym_open (char *pts_name); +int ptys_open (int fdm, char * pts_name); + +int +openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp) +{ + char line[20]; + line[0]=0; + *amaster = ptym_open(line); + if (*amaster < 0) + return -1; + *aslave = ptys_open(*amaster, line); + if (*aslave < 0) { + close(*amaster); + return -1; + } + if (name) + strcpy(name, line); +#ifndef TCSAFLUSH +#define TCSAFLUSH TCSETAF +#endif + if (termp) + (void) tcsetattr(*aslave, TCSAFLUSH, termp); +#ifdef TIOCSWINSZ + if (winp) + (void) ioctl(*aslave, TIOCSWINSZ, (char *)winp); +#endif + return 0; +} + +int +ptym_open(char * pts_name) +{ + char *ptr1, *ptr2; + + strcpy(pts_name, "/dev/ptyXY"); + /* array index: 012345689 (for references in following code) */ + for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) { + pts_name[8] = *ptr1; + for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) { + pts_name[9] = *ptr2; + /* try to open master */ + fdm = open(pts_name, O_RDWR); + if (fdm < 0) { + if (errno == ENOENT) {/* different from EIO */ + return -1; /* out of pty devices */ + } else { + continue; /* try next pty device */ + } + } + pts_name[5] = 't'; /* chage "pty" to "tty" */ + return fdm; /* got it, return fd of master */ + } + } + return -1; /* out of pty devices */ +} + +int +ptys_open(int fdm, char * pts_name) +{ + int gid; + struct group *grptr; + + grptr = getgrnam("tty"); + if (grptr != NULL) { + gid = grptr->gr_gid; + } else { + gid = -1; /* group tty is not in the group file */ + } + + /* following two functions don't work unless we're root */ + chown(pts_name, getuid(), gid); + chmod(pts_name, S_IRUSR | S_IWUSR | S_IWGRP); + fds = open(pts_name, O_RDWR); + if (fds < 0) { + close(fdm); + return -1; + } + return fds; +} diff --git a/core/org.eclipse.cdt.core.qnx/library/pty/pty.c b/core/org.eclipse.cdt.core.qnx/library/pty/pty.c new file mode 100644 index 00000000000..4b9e682c3ee --- /dev/null +++ b/core/org.eclipse.cdt.core.qnx/library/pty/pty.c @@ -0,0 +1,35 @@ +#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_forkpty (JNIEnv *env, jobject jobj) { + 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) { + /* 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; +} diff --git a/core/org.eclipse.cdt.core.qnx/library/pty/ptyio.c b/core/org.eclipse.cdt.core.qnx/library/pty/ptyio.c new file mode 100644 index 00000000000..0024cf0a1b3 --- /dev/null +++ b/core/org.eclipse.cdt.core.qnx/library/pty/ptyio.c @@ -0,0 +1,103 @@ +#include <jni.h> +#include <stdio.h> +#include <PTYInputStream.h> +#include <PTYOutputStream.h> +#include <unistd.h> + +/* Header for class _org_eclipse_cdt_utils_pty_PTYInputStream */ +/* Header for class _org_eclipse_cdt_utils_pty_PTYOutputStream */ + +/* + * Class: org_eclipse_cdt_utils_pty_PTYInputStream + * Method: read0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYInputStream_read0(JNIEnv * env, + jobject jobj, + jint jfd, + jbyteArray buf, + jint buf_len) +{ + int fd; + int status; + jbyte *data; + int data_len; + + data = (*env)->GetByteArrayElements(env, buf, 0); + data_len = buf_len; + fd = jfd; + + status = read( fd, data, data_len ); + (*env)->ReleaseByteArrayElements(env, buf, data, 0); + + if (status == 0) { + /* EOF. */ + status = -1; + } else if (status == -1) { + /* Error, toss an exception */ + jclass exception = (*env)->FindClass(env, "java/io/IOException"); + if (exception == NULL) { + /* Give up. */ + return -1; + } + (*env)->ThrowNew(env, exception, "read error"); + } + + return status; +} + + +/* + * Class: org_eclipse_cdt_utils_pty_PTYInputStream + * Method: close0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYInputStream_close0(JNIEnv * env, + jobject jobj, + jint fd) +{ + return close(fd); +} + +/* + * Class: org_eclipse_cdt_utils_pty_PTYOutputStream + * Method: write0 + * Signature: (II)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYOutputStream_write0(JNIEnv * env, + jobject jobj, + jint jfd, + jbyteArray buf, + jint buf_len) +{ + int status; + int fd; + jbyte *data; + int data_len; + + data = (*env)->GetByteArrayElements(env, buf, 0); + data_len = buf_len; + fd = jfd; + + status = write(fd, data, data_len); + (*env)->ReleaseByteArrayElements(env, buf, data, 0); + + return status; +} + + +/* + * Class: org_eclipse_cdt_utils_pty_PTYOutputStream + * Method: close0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_pty_PTYOutputStream_close0(JNIEnv * env, + jobject jobj, + jint fd) +{ + return close(fd); +} |