package local;

import java.io.IOException;

class CWD {

    public static native String get() throws java.io.IOException;

    public static void main(String[] args) {
	try {
	    System.out.println("Your current working directory is " + get());
	} catch (IOException e) {
	    System.err.println("I/O Exception: " + e.toString());
	}
    }

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



#include "local_CWD.h"
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include <javaString.h>

HString *
local_CWD_get(
    struct Hlocal_CWD *this_h)
{
    HString *retval;
    char *str;

    str = getcwd(NULL, _POSIX_PATH_MAX);
				/* returns malloc'd string: must be freed */
    if (str == NULL) {
	SignalError(EE(),
	    "java/io/IOException",
	    strerror(errno));
	return NULL;
    }
    retval = makeJavaString(str, strlen(str));
    free(str);
    return retval;
}
