filetraverser/unix.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sun, 24 Oct 2010 20:58:01 +0200
changeset 151 a8c2649cf277
permissions -rw-r--r--
FileTraverser Demo added Proper handling of symlinks in java apps committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * unix.c
 * Copyright (C) 2010 Markus Broeker
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>
#include <jni.h>

int isUnixLink (const char *name)
{
    struct stat st;

    assert (lstat (name, &st) == 0);
    return (S_ISLNK (st.st_mode));
}

JNIEXPORT jint JNICALL Java_Unix_isUnixLink (JNIEnv * env, jclass jc, jstring s)
{
    const char *c_string = (*env)->GetStringUTFChars (env, s, NULL);
    return isUnixLink (c_string);
}