How to call stat() C function to get file type?

Hi,

I’m trying to call stat() C function (from sys/stat.h) to get actual file/dir type that are behind symbolic links.

Here’s what I have at the moment:

    val dir = opendir(path)
    if (dir != null) {
        try {
            var entry = platform.posix.readdir(dir)
            while (entry != null) {
                println("fsLF name/type: '${entry.pointed.d_name.toKString()}'/'${entry.pointed.d_type}'")
                if (entry.pointed.d_type == DT_LNK.toUByte()) {
                    println("link")
                }
                println("fsLF stat: '${stat(entry.pointed.d_name.toKString(), null)}'") // This one always returns -1, however, I need to know what type is behind a symlink: dir or file
                entry = readdir(dir)
            }
        } finally {
            closedir(dir)
        }
    }

Currently stat() call always returns -1. And want it to return something meaningful that can be interpreted as file or dir type.

Any idea what went wrong?
Thanks.