diff --git a/common/source/c/compile_linux_amd64.sh b/common/source/c/compile_linux_amd64.sh index daaeae5788ce2753a1e6bcb7533f09ca1f93f2e5..48dd42fcd28fe87ab6233841bd8ea0f58ae935a9 100755 --- a/common/source/c/compile_linux_amd64.sh +++ b/common/source/c/compile_linux_amd64.sh @@ -1,3 +1,3 @@ #! /bin/bash -gcc -shared -fPIC unixlink.c -o ../../../libraries/filelink/amd64-Linux/jlink.so +gcc -shared -fPIC unixlink.c -o amd64-Linux_jlink.so diff --git a/common/source/c/compile_linux_i386.sh b/common/source/c/compile_linux_i386.sh index ed19e175b686bf6e8d1c91064c28de0eb12886df..996476f6927aeaf8bf272049252b2dcc7485eb52 100755 --- a/common/source/c/compile_linux_i386.sh +++ b/common/source/c/compile_linux_i386.sh @@ -1,3 +1,3 @@ #! /bin/bash -gcc -shared unixlink.c -I/usr/java/jdk1.5.0_13/include -I/usr/java/jdk1.5.0_13/include/linux -o ../../../libraries/filelink/i386-Linux/jlink.so +gcc -shared unixlink.c -I/usr/java/jdk1.5.0_13/include -I/usr/java/jdk1.5.0_13/include/linux -o i386-Linux_jlink.so diff --git a/common/source/c/compile_macosx.sh b/common/source/c/compile_macosx.sh index b8a4feb326ec798432f2689742375facadd75ea5..d0121d8cdcfa077207ec89939431268033b954c6 100755 --- a/common/source/c/compile_macosx.sh +++ b/common/source/c/compile_macosx.sh @@ -1,4 +1,3 @@ #! /bin/bash -gcc -bundle unixlink.c -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers -o "../../../libraries/filelink/i386-Mac OS X/jlink.so" - +gcc -bundle unixlink.c -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers -o "i386-Mac OS X_jlink.so" diff --git a/common/source/c/compile_solaris_amd64.sh b/common/source/c/compile_solaris_amd64.sh new file mode 100755 index 0000000000000000000000000000000000000000..20039a9506b3a670d95d751bb66f4fe35c748345 --- /dev/null +++ b/common/source/c/compile_solaris_amd64.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +gcc -m64 -shared -fPIC -static-libgcc -R/usr/sfw/lib/amd64 unixlink.c -I/usr/java/include/ -I/usr/java/include/solaris -o amd64-SunOS_jlink.so diff --git a/common/source/c/compile_solaris_x86.sh b/common/source/c/compile_solaris_x86.sh new file mode 100755 index 0000000000000000000000000000000000000000..262857ce7ac7f0488d0e5cd671b90ac151f18208 --- /dev/null +++ b/common/source/c/compile_solaris_x86.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +gcc -shared -fPIC -static-libgcc unixlink.c -I/usr/java/include/ -I/usr/java/include/solaris -o x86-SunOS_jlink.so diff --git a/common/source/c/unixlink.c b/common/source/c/unixlink.c index bbb3c031ee64f51f4a76eff8afa32c6c595d577e..b366126d8b3eef59b94b31ae103f934762a48f90 100644 --- a/common/source/c/unixlink.c +++ b/common/source/c/unixlink.c @@ -1,6 +1,8 @@ #include <unistd.h> #include <errno.h> #include <string.h> +#include <sys/types.h> +#include <sys/stat.h> #include <jni.h> JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_common_utilities_FileLinkUtilities_hardlink @@ -8,16 +10,15 @@ JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_common_utilities_FileLinkUtilities_ { const char* pfilename; const char* plinktarget; - jboolean isCopy; int retval; - pfilename = (char *)(*env)->GetStringUTFChars(env, filename, &isCopy); - plinktarget = (char *)(*env)->GetStringUTFChars(env, linktarget, &isCopy); + pfilename = (char *)(*env)->GetStringUTFChars(env, filename, NULL); + plinktarget = (char *)(*env)->GetStringUTFChars(env, linktarget, NULL); retval = link(pfilename, plinktarget); if (retval < 0) { - retval = errno; + retval = -errno; } (*env)->ReleaseStringUTFChars(env, filename, pfilename); @@ -31,15 +32,14 @@ JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_common_utilities_FileLinkUtilities_ { const char* pfilename; const char* plinktarget; - jboolean isCopy; int retval; - pfilename = (char *)(*env)->GetStringUTFChars(env, filename, &isCopy); - plinktarget = (char *)(*env)->GetStringUTFChars(env, linktarget, &isCopy); + pfilename = (char *)(*env)->GetStringUTFChars(env, filename, NULL); + plinktarget = (char *)(*env)->GetStringUTFChars(env, linktarget, NULL); retval = symlink(pfilename, plinktarget); if (retval < 0) { - retval = errno; + retval = -errno; } (*env)->ReleaseStringUTFChars(env, filename, pfilename); @@ -48,7 +48,50 @@ JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_common_utilities_FileLinkUtilities_ return retval; } +JNIEXPORT jint JNICALL Java_ch_systemsx_cisd_common_utilities_FileLinkUtilities_linkinfo(JNIEnv *env, jclass clss, jstring filename, jintArray result) +{ + const char* pfilename; + struct stat statbuf; + jint resultbuf[4]; + int retval; + + pfilename = (char *)(*env)->GetStringUTFChars(env, filename, NULL); + retval = lstat(pfilename, &statbuf); + (*env)->ReleaseStringUTFChars(env, filename, pfilename); + if (retval < 0) + { + return -errno; + } else + { + resultbuf[0] = statbuf.st_ino; + resultbuf[1] = statbuf.st_nlink; + resultbuf[2] = S_ISLNK(statbuf.st_mode); + resultbuf[3] = statbuf.st_size; + (*env)->SetIntArrayRegion(env, result, 0, 4, resultbuf); + return 0; + } +} + +JNIEXPORT jstring JNICALL Java_ch_systemsx_cisd_common_utilities_FileLinkUtilities_readlink(JNIEnv *env, jclass clss, jstring linkname, jint linkvallen) +{ + const char* plinkname; + char plinkvalue[linkvallen + 1]; + int retval; + + plinkname = (char *)(*env)->GetStringUTFChars(env, linkname, NULL); + retval = readlink(plinkname, plinkvalue, linkvallen); + (*env)->ReleaseStringUTFChars(env, linkname, plinkname); + if (retval < 0) + { + return NULL; + } else + { + plinkvalue[linkvallen] = '\0'; + return (*env)->NewStringUTF(env, plinkvalue); + } +} + JNIEXPORT jstring JNICALL Java_ch_systemsx_cisd_common_utilities_FileLinkUtilities_strerror(JNIEnv *env, jclass clss, jint errnum) { - return (*env)->NewStringUTF(env, strerror(errnum)); + return (*env)->NewStringUTF(env, strerror(errnum < 0 ? -errnum : errnum)); }