1/* BEGIN LICENSE BLOCK 2 * Version: CMPL 1.1 3 * 4 * The contents of this file are subject to the Cisco-style Mozilla Public 5 * License Version 1.1 (the "License"); you may not use this file except 6 * in compliance with the License. You may obtain a copy of the License 7 * at www.eclipse-clp.org/license. 8 * 9 * Software distributed under the License is distributed on an "AS IS" 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11 * the License for the specific language governing rights and limitations 12 * under the License. 13 * 14 * The Original Code is The ECLiPSe Constraint Logic Programming System. 15 * The Initial Developer of the Original Code is Cisco Systems, Inc. 16 * Portions created by the Initial Developer are 17 * Copyright (C) 2006 Cisco Systems, Inc. All Rights Reserved. 18 * 19 * 20 * Contributor(s): 21 * 22 * END LICENSE BLOCK */ 23 24/* 25 * Eclipse Java interface 26 * 27 * An auxiliary library which should not depend on anything else. 28 * Containing just chdir() functions (Java has no chdir), which are 29 * used to change the current directory while loading libec_java.so 30 * to prevent the need to set LD_LIBRARY_PATH. 31 * This is hacky, but it has been requested by Parc Technologies. 32 * 33 * $Id: ec_java_load.c,v 1.1 2006/09/23 01:54:08 snovello Exp $ 34 * 35 */ 36 37#include "com_parctechnologies_eclipse_NativeEclipse.h" 38 39#ifdef _WIN32 40#include <direct.h> 41#define getcwd(buf,len) _getcwd(buf,len) 42#define chdir(dir) _chdir(dir) 43#else 44#include <unistd.h> 45#endif 46 47#define MAX_PATH_LEN 1024 48static char old_cwd[MAX_PATH_LEN]; 49 50 51/* 52 * Class: eclipse_NativeEclipse 53 * Method: ec_chdir 54 * Signature: 55 * Returns 0 if ok, -1 if error 56 */ 57JNIEXPORT jint JNICALL Java_com_parctechnologies_eclipse_NativeEclipse_chdir 58 (JNIEnv * e, jclass jc, jstring jsDir) 59{ 60 const char *Dir; 61 jint res; 62 63 if (!getcwd(old_cwd, MAX_PATH_LEN)) 64 return -1; 65 Dir = (*e)->GetStringUTFChars(e,jsDir,NULL); 66 res = (jint) chdir(Dir); 67 (*e)->ReleaseStringUTFChars(e,jsDir,Dir); 68 return res; 69} 70 71/* 72 * Class: eclipse_NativeEclipse 73 * Method: ec_resetdir 74 * Signature: 75 * Returns 0 if ok, -1 if error 76 */ 77JNIEXPORT jint JNICALL Java_com_parctechnologies_eclipse_NativeEclipse_resetdir 78 (JNIEnv * e, jclass jc) 79{ 80 return (jint) chdir(old_cwd); 81} 82 83