.\" -*- coding: UTF-8 -*- .\" Copyright 1983-1991, The Regents of the University of California. .\" Copyright 2011, Guillem Jover .\" Copyright 2006-2014, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: BSD-4-Clause-UC .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH readlink 2 "8 février 2026" "Pages du manuel de Linux 6.18" .SH NOM readlink, readlinkat \- Lire le contenu d'un lien symbolique .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP,\ \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .P \fBssize_t readlink(\fPsize_t bufsiz; \fB const char *restrict \fP\fIpath\fP\fB,\fP \fB char \fP\fIbuf\fP\fB[restrict \fP\fIbufsiz\fP\fB], size_t \fP\fIbufsiz\fP\fB);\fP .P \fB#include \fP/* Définition des constantes \fBAT_*\fP */ \fB#include \fP .P \fBssize_t readlinkat(\fPsize_t bufsiz; \fB int \fP\fIdirfd\fP\fB, const char *restrict \fP\fIpath\fP\fB,\fP \fB char \fP\fIbuf\fP\fB[restrict \fP\fIbufsiz\fP\fB], size_t \fP\fIbufsiz\fP\fB);\fP .P .fi .RS -4 Exigences de macros de test de fonctionnalités pour la glibc (consulter \fBfeature_test_macros\fP(7)) : .RE .P \fBreadlink\fP(): .nf .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L || /* glibc <= 2.19 : */ _BSD_SOURCE .fi .P \fBreadlinkat\fP(): .nf Depuis la glibc 2.10 : _POSIX_C_SOURCE >= 200809L avant la glibc 2.10 : _ATFILE_SOURCE .fi .SH DESCRIPTION \fBreadlink\fP() places the contents of the symbolic link \fIpath\fP in the buffer \fIbuf\fP, which has size \fIbufsiz\fP. \fBreadlink\fP() does not append a terminating null byte to \fIbuf\fP. It will (silently) truncate the contents (to a length of \fIbufsiz\fP characters), in case the buffer is too small to hold all of the contents. .SS readlinkat() L'appel système \fBreadlinkat\fP() fonctionne exactement comme \fBreadlink\fP(), les seules différences étant décrites ici. .P If \fIpath\fP is relative, then it is interpreted relative to the directory referred to by the file descriptor \fIdirfd\fP (rather than relative to the current working directory of the calling process, as is done by \fBreadlink\fP() for a relative pathname). .P If \fIpath\fP is relative and \fIdirfd\fP is the special value \fBAT_FDCWD\fP, then \fIpath\fP is interpreted relative to the current working directory of the calling process (like \fBreadlink\fP()). .P Si \fIpath\fP est absolu, alors \fIdirfd\fP est ignoré. .P .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d Since Linux 2.6.39, \fIpath\fP can be an empty string, in which case the call operates on the symbolic link referred to by \fIdirfd\fP (which should have been obtained using \fBopen\fP(2) with the \fBO_PATH\fP and \fBO_NOFOLLOW\fP flags). .P Consultez \fBopenat\fP(2) pour une explication de la nécessité de \fBreadlinkat\fP(). .SH "VALEUR RENVOYÉE" S'il réussit, ces appels renvoient le nombre d'octets placés dans \fIbuf\fP (si la valeur renvoyée est égale à \fIbufsiz\fP, il se peut qu'il y ait eu une troncature). S'il échoue, il renvoie \fB\-1\fP et écrit \fIerrno\fP pour indiquer l'erreur. .SH ERREURS .TP \fBEACCES\fP Un élément du chemin d'accès ne permet pas la recherche. (Consultez aussi \fBpath_resolution\fP(7).) .TP \fBEBADF\fP (\fBreadlinkat\fP()) \fIpath\fP is relative but \fIdirfd\fP is neither \fBAT_FDCWD\fP nor a valid file descriptor. .TP \fBEFAULT\fP \fIbuf\fP pointe en dehors de l'espace d'adressage accessible. .TP \fBEINVAL\fP .\" At the glibc level, bufsiz is unsigned, so this error can only occur .\" if bufsiz==0. However, the in the kernel syscall, bufsiz is signed, .\" and this error can also occur if bufsiz < 0. .\" See: http://thread.gmane.org/gmane.linux.man/380 .\" Subject: [patch 0/3] [RFC] kernel/glibc mismatch of "readlink" syscall? \fIbufsiz\fP n'est pas un nombre positif. .TP \fBEINVAL\fP The named file (i.e., the final filename component of \fIpath\fP) is not a symbolic link. .TP \fBEIO\fP Une erreur d'entrée\-sortie s'est produite durant la lecture du système de fichiers. .TP \fBELOOP\fP Trop de liens symboliques ont été rencontrés en parcourant le chemin. .TP \fBENAMETOOLONG\fP Un nom de chemin d'accès ou l'un des composants d'un nom de chemin d'accès est trop long. .TP \fBENOENT\fP Le fichier indiqué n'existe pas. .TP \fBENOMEM\fP La mémoire disponible du noyau n'était pas suffisante. .TP \fBENOTDIR\fP Un élément du chemin d'accès n'est pas un répertoire. .TP \fBENOTDIR\fP (\fBreadlinkat\fP()) \fIpath\fP is relative and \fIdirfd\fP is a file descriptor referring to a file other than a directory. .SH NORMES POSIX.1\-2024. .SH HISTORIQUE .TP \fBreadlink\fP() 4.4BSD (apparue dans 4.2BSD), POSIX.1\-2001, POSIX.1\-2008. .TP \fBreadlinkat\fP() POSIX.1\-2008. Linux 2.6.16, glibc 2.4. .P Jusqu'à la glibc 2.4 incluse, le type de retour de \fBreadlink\fP() était déclaré comme \fIint\fP. À présent, le type de retour est déclaré comme \fIssize_t\fP, ainsi que le prescrit POSIX.1\-2001. .SS glibc On older kernels where \fBreadlinkat\fP() is unavailable, the glibc wrapper function falls back to the use of \fBreadlink\fP(). When \fIpath\fP is relative, glibc constructs a pathname based on the symbolic link in \fI/proc/self/fd\fP that corresponds to the \fIdirfd\fP argument. .SH NOTES L'utilisation d'un tampon de taille statique risque de ne pas fournir assez de place pour le contenu du lien symbolique. La taille nécessaire au tampon peut être lue dans la valeur \fIstat.st_size\fP renvoyée par un appel à \fBlstat\fP(2) sur le lien. Cependant, le nombre d'octets écrits par \fBreadlink\fP() et par \fBreadlinkat\fP() devrait être vérifié pour s'assurer que la taille du lien symbolique n'a pas augmenté entre les appels. L'allocation dynamique du tampon pour \fBreadlink\fP() et pour \fBreadlinkat\fP() résout aussi un problème habituel de portabilité si \fBPATH_MAX\fP est utilisé comme taille de tampon, car la définition de cette constante n'est pas garantie selon les POSIX si le système n'a pas ce genre de limite. .SH EXEMPLES Le programme suivant alloue le tampon nécessaire à \fBreadlink\fP() dynamiquement à partir des données fournies par \fBlstat\fP(), en se rabattant sur un tampon de taille \fBPATH_MAX\fP si \fBlstat\fP(2) signale une taille de zéro. .P .\" SRC BEGIN (readlink.c) .EX #include #include #include #include #include #include \& int main(int argc, char *argv[]) { char *buf; ssize_t nbytes, bufsiz; struct stat sb; \& if (argc != 2) { fprintf(stderr, "Usage: %s \[rs]n", argv[0]); exit(EXIT_FAILURE); } \& if (lstat(argv[1], &sb) == \-1) { perror("lstat"); exit(EXIT_FAILURE); } \& /* Add one to the link size, so that we can determine whether the buffer returned by readlink() was truncated. */ \& bufsiz = sb.st_size + 1; \& /* Some magic symlinks under (for example) /proc and /sys report \[aq]st_size\[aq] as zero. In that case, take PATH_MAX as a "good enough" estimate. */ \& if (sb.st_size == 0) bufsiz = PATH_MAX; \& buf = malloc(bufsiz); if (buf == NULL) { perror("malloc"); exit(EXIT_FAILURE); } \& nbytes = readlink(argv[1], buf, bufsiz); if (nbytes == \-1) { perror("readlink"); exit(EXIT_FAILURE); } \& /* Print only \[aq]nbytes\[aq] of \[aq]buf\[aq], as it doesn't contain a terminating null byte (\[aq]\[rs]0\[aq]). */ printf("\[aq]%s\[aq] points to \[aq]%.*s\[aq]\[rs]n", argv[1], (int) nbytes, buf); \& /* If the return value was equal to the buffer size, then the link target was larger than expected (perhaps because the target was changed between the call to lstat() and the call to readlink()). Warn the user that the returned target may have been truncated. */ \& if (nbytes == bufsiz) printf("(Returned buffer may have been truncated)\[rs]n"); \& free(buf); exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VOIR AUSSI" \fBreadlink\fP(1), \fBlstat\fP(2), \fBstat\fP(2), \fBsymlink\fP(2), \fBrealpath\fP(3), \fBpath_resolution\fP(7), \fBsymlink\fP(7) .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot , Frédéric Hantrais et Jean-Philippe MENGUAL . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .