libConsole/cross_getch.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sun, 27 Sep 2009 10:56:49 +0200
changeset 107 244356bc3a20
parent 93 66b3596f71b6
child 134 8325a0fc22cd
permissions -rw-r--r--
Pipes and COPY-ON-WRITE In this example, every forked process gets its own copy of the countervariable i through copy-on-write. committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * libConsole/cross_getch.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <jni.h>
#include <Console.h>

#ifdef WIN32
#include <conio.h>

int cross_getch ()
{
    int ch = -1;

    ch = getch ();

    return ch;
}

#else
#include <termios.h>

static int cross_getch ()
{
    int ch = -1, fd = 0;
    struct termios neu, alt;

    fd = fileno (stdin);
    tcgetattr (fd, &alt);
    neu = alt;
    neu.c_lflag &= ~(ICANON | ECHO);
    tcsetattr (fd, TCSANOW, &neu);
    ch = getchar ();
    tcsetattr (fd, TCSANOW, &alt);
    return ch;
}
#endif

JNIEXPORT jint JNICALL Java_Console_getch (JNIEnv * env, jclass lass)
{
    return cross_getch ();
}