filetraverser/unix.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 27 Dec 2013 16:00:09 +0100
changeset 167 7c6b221900bf
parent 151 a8c2649cf277
permissions -rw-r--r--
Proper Datatypes to leave the 80's
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
151
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
 * unix.c
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * Copyright (C) 2010 Markus Broeker
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <sys/types.h>
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <sys/stat.h>
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#include <unistd.h>
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
#include <assert.h>
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
#include <jni.h>
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
int isUnixLink (const char *name)
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
{
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
    struct stat st;
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
    assert (lstat (name, &st) == 0);
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
    return (S_ISLNK (st.st_mode));
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
}
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
JNIEXPORT jint JNICALL Java_Unix_isUnixLink (JNIEnv * env, jclass jc, jstring s)
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
{
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
    const char *c_string = (*env)->GetStringUTFChars (env, s, NULL);
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
    return isUnixLink (c_string);
a8c2649cf277 FileTraverser Demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
}