---
title: "path_readlink()"
description: "The path_readlink() function reads the target path that a symlink points to. It requires the PATH_READLINK right to be set on the base directory from which the symlink is understood."
url: "https://wasix.org/docs/api-reference/wasi/path_readlink/"
markdown: "https://wasix.org/docs/api-reference/wasi/path_readlink.md"
---

# `path_readlink()`

Read the value of a symlink.

## Description

The `path_readlink()` function reads the target path that a symlink points to. It requires the `PATH_READLINK` right to be set on the base directory from which the symlink is understood.

On POSIX systems, a similar functionality is provided by the `readlink()` function. It reads the value of a symbolic link and stores it in a buffer. The `readlink()` function is part of the POSIX standard and is widely supported across different platforms.

## Syntax

```ebnf
  ;;; Note: This is similar to `readlinkat` in POSIX.
  ;;; Read the contents of a symbolic link.
  (@interface func (export "path_readlink")
    (param $fd $fd)
    ;;; The path of the symbolic link from which to read.
    (param $path string)
    ;;; The buffer to which to write the contents of the symbolic link.
    (param $buf (@witx pointer u8))
    (param $buf_len $size)
    ;;; The number of bytes placed in the buffer.
    (result $error (expected $size (error $errno)))
  )
```

## Parameters

- `ctx`: A mutable reference to the function environment.
- `dir_fd`: The file descriptor representing the base directory from which the symlink is understood.
- `path`: A wasm pointer to a null-terminated string containing the path to the symlink.
- `path_len`: The length of the `path` string.
- `buf`: A wasm pointer to a buffer where the target path of the symlink will be written.
- `buf_len`: The available space in the buffer pointed to by `buf`.
- `buf_used`: A wasm pointer to a variable where the number of bytes written to the buffer will be stored.

## Return Value

The function returns an `Errno` value indicating the success or failure of the operation. If the operation is successful, it returns `Errno::Success`. Otherwise, it returns an appropriate `Errno` value.

## Logging

This function has been instrumented with debug-level logging. It will log the following information:

- `%dir_fd`: The file descriptor representing the base directory.
- `path`: The path string.

## Note

The `path_readlink()` function reads the target path of a symlink. It checks if the base directory has the necessary rights and reads the target path accordingly. On POSIX systems, a similar functionality is provided by the `readlink()` function.

---

[Documentation index](https://wasix.org/llms.txt) · [HTML version](https://wasix.org/docs/api-reference/wasi/path_readlink/)
