import libc.(rename);
import unix.*;
import io.errors.*;
public import io.filesystem.executable.*;

readLink(x) {
    var path_max = pathconf(cstring(x), _PC_PATH_MAX);
    if (path_max < 0)
        path_max = 4096;

    var buf = String();
    resize(buf, path_max);

    var size = readlink(cstring(x), Pointer[CChar](begin(buf)), size_t(path_max));
    if (size < 0)
        throw GenericIOError(errno());

    resize(buf, size);
    return move(buf);
}

moveFile(fromPath, toPath) {
    var ok = rename(cstring(fromPath), cstring(toPath));
    if (ok != 0)
        throw GenericIOError(errno());
}

deleteFile(path) {
    var ok = unlink(cstring(path));
    if (ok != 0)
        throw GenericIOError(errno());
}

