package local;

import java.io.IOException;

class PrintString {

    public static native void print(String str) throws java.io.IOException;
    public static native void println(String str) throws java.io.IOException;

    public static void main(String[] args) {
	try {
	    print("Testing...  ");
	    println("printing Strings from native code.");
	} catch (IOException e) {
	    System.err.println("I/O Exception: " + e.toString());
	}
    }

    static {
	System.loadLibrary("PrintString");
    }
}



#include "local_PrintString.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <javaString.h>

void
local_PrintString_print(
    struct Hlocal_PrintString *this_h,
    Hjava_lang_String *str_h)
{
    char *str;
    int ret;

    str = makeCString(str_h);
    if (str == NULL)
	return;

    ret = printf("%s", str);
    if (ret < 0) {
	SignalError(EE(),
	    "java/io/IOException",
	    strerror(errno));
    }
}

void
local_PrintString_println(
    struct Hlocal_PrintString *this_h,
    Hjava_lang_String *str_h)
{
    char *str;
    int ret;

    str = makeCString(str_h);
    if (str == NULL)
	return;

    ret = printf("%s\n", str);
    if (ret < 0) {
	SignalError(EE(),
	    "java/io/IOException",
	    strerror(errno));
    }
}
