.\" -*- coding: UTF-8 -*- .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Modified Wed Jul 21 22:35:42 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified 18 Mar 1996 by Martin Schulze (joey@infodrom.north.de): .\" Corrected description of getwd(). .\" Modified Sat Aug 21 12:32:12 MET 1999 by aeb - applied fix by aj .\" Modified Mon Dec 11 13:32:51 MET 2000 by aeb .\" Modified Thu Apr 22 03:49:15 CEST 2002 by Roger Luethi .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH GETCWD 3 "30 avril 2018" GNU "Manuel du programmeur Linux" .SH NOM getcwd, getwd, get_current_dir_name \- Obtenir le répertoire de travail actuel .SH SYNOPSIS .nf \fB#include \fP .PP \fBchar *getcwd(char *\fP\fIbuf\fP\fB, size_t \fP\fIsize\fP\fB);\fP .PP \fBchar *getwd(char *\fP\fIbuf\fP\fB);\fP .PP \fBchar *get_current_dir_name(void);\fP .fi .PP .RS -4 Exigences de macros de test de fonctionnalités pour la glibc (consulter \fBfeature_test_macros\fP(7))\ : .RE .PP \fBget_current_dir_name\fP()\ : .RS _GNU_SOURCE .RE .PP \fBgetwd\fP()\ : .ad l .RS 4 .PD 0 .TP 4 Depuis la glibc 2.12 : .nf (_XOPEN_SOURCE\ >=\ 500) && ! (_POSIX_C_SOURCE\ >=\ 200809L) || /* Glibc since 2.19: */ _DEFAULT_SOURCE || /* Glibc versions <= 2.19: */ _BSD_SOURCE .fi .TP 4 Avant la glibc 2.12\ : .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 .PD .RE .ad b .SH DESCRIPTION Ces fonctions renvoient une chaîne terminée par une octet nul contenant un chemin absolu correspondant au répertoire de travail actuel du processus appelant. Le chemin est renvoyé comme résultat de la fonction et par le paramètre \fIbuf\fP, s'il est présent. .PP La fonction \fBgetcwd\fP() copie le chemin d'accès absolu du répertoire de travail courant dans la chaîne pointée par \fIbuf\fP, qui est de longueur \fIsize\fP. .PP Si la taille du chemin absolu du répertoire de travail en cours, caractère nul de fin compris, dépasse \fIsize\fP octets, la fonction renvoie NULL et \fIerrno\fP contient le code d'erreur \fBERANGE\fP. Une application doit détecter cette erreur et allouer un tampon plus grand si besoin est. .PP As an extension to the POSIX.1\-2001 standard, glibc's \fBgetcwd\fP() allocates the buffer dynamically using \fBmalloc\fP(3) if \fIbuf\fP is NULL. In this case, the allocated buffer has the length \fIsize\fP unless \fIsize\fP is zero, when \fIbuf\fP is allocated as big as necessary. The caller should \fBfree\fP(3) the returned buffer. .PP \fBget_current_dir_name\fP() allouera avec \fBmalloc\fP(3) une chaîne suffisamment grande pour contenir le nom du chemin absolu du répertoire de travail courant. Si la variable d'environnement \fBPWD\fP est configurée, et correcte, cette valeur sera renvoyée. L'appelant doit libérer avec \fBfree\fP(3) le tampon renvoyé. .PP \fBgetwd\fP() n'allouera aucune mémoire (avec \fBmalloc\fP(3)). Le paramètre \fIbuf\fP doit être un pointeur sur une chaîne comportant au moins \fBPATH_MAX\fP octets. Si la longueur du chemin absolu du répertoire de travail actuel, caractère nul de fin compris, dépasse \fBPATH_MAX\fP octets, NULL est renvoyé et \fIerrno\fP prend la valeur \fBENAMETOOLONG\fP. Notez que sur certains système, \fBPATH_MAX\fP peut ne pas être une constante connue à la compilation\ ; de plus, sa valeur peut dépendre du système de fichiers, voire être illimitée, consultez \fBpathconf\fP(3). Pour des raisons de portabilité et de sécurité, l'utilisation de \fBgetwd\fP() est déconseillée. .SH "VALEUR RENVOYÉE" On success, these functions return a pointer to a string containing the pathname of the current working directory. In the case of \fBgetcwd\fP() and \fBgetwd\fP() this is the same value as \fIbuf\fP. .PP En cas d'échec, ces fonctions renvoient NULL, et remplissent \fIerrno\fP avec le code d'erreur. Le contenu de la chaîne pointée par \fIbuf\fP est indéfini en cas d'erreur. .SH ERREURS .TP \fBEACCES\fP Impossible de lire ou de parcourir un composant du chemin d'accès. .TP \fBEFAULT\fP \fIbuf\fP pointe sur une adresse illégale. .TP \fBEINVAL\fP L'argument \fIsize\fP vaut zéro et \fIbuf\fP n'est pas un pointeur NULL. .TP \fBEINVAL\fP \fBgetwd\fP()\ : \fIbuf\fP est NULL. .TP \fBENAMETOOLONG\fP \fBgetwd\fP()\ : La taille de la chaîne, terminée par un octet nul, du chemin absolu dépasse \fBPATH_MAX\fP octets. .TP \fBENOENT\fP Le répertoire en cours a été supprimé. .TP \fBENOMEM\fP Plus assez de mémoire. .TP \fBERANGE\fP Le paramètre \fIsize\fP est inférieur à la longueur du nom du chemin absolu du répertoire de travail, caractère nul de fin compris. Allouez un tampon plus grand et réessayez. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbw22 lb lb l l l. Interface Attribut Valeur T{ \fBgetcwd\fP(), \fBgetwd\fP() T} Sécurité des threads MT\-Safe T{ \fBget_current_dir_name\fP() T} Sécurité des threads MT\-Safe env .TE .SH CONFORMITÉ \fBgetcwd\fP() se conforme à POSIX.1\-2001. Notez cependant que POSIX.1\-2001 laisse le comportement de \fBgetcwd\fP() non spécifié si \fIbuf\fP est NULL. .PP \fBgetwd\fP() est présent dans POSIX.1\-2001, mais marquée «\ LEGACY\ ». POSIX.1\-2008 supprime la spécification de \fBgetwd\fP() et POSIX.1\-2001 ne définit aucune erreur pour \fBgetwd\fP(). Utilisez \fBgetcwd\fP() à la place. .PP \fBget_current_dir_name\fP() est une extension GNU. .SH NOTES Under Linux, these functions make use of the \fBgetcwd\fP() system call (available since Linux 2.1.92). On older systems they would query \fI/proc/self/cwd\fP. If both system call and proc filesystem are missing, a generic implementation is called. Only in that case can these calls fail under Linux with \fBEACCES\fP. .PP .\" Ces fonctions sont souvent utilisées pour sauver le répertoire de travail afin d'y revenir plus tard. Ouvrir le répertoire courant («\ .\ ») et appeler \fBfchdir\fP(2) pour y revenir est habituellement une alternative plus rapide et plus fiable (surtout sur d'autres systèmes que Linux) si l'on dispose de suffisamment de descripteurs de fichier. .SS "différences entre bibliothèque C et noyau" .\" commit 3272c544da48f8915a0e34189182aed029bd0f2b On Linux, the kernel provides a \fBgetcwd\fP() system call, which the functions described in this page will use if possible. The system call takes the same arguments as the library function of the same name, but is limited to returning at most \fBPATH_MAX\fP bytes. (Before Linux 3.12, the limit on the size of the returned pathname was the system page size. On many architectures, \fBPATH_MAX\fP and the system page size are both 4096 bytes, but a few architectures have a larger page size.) If the length of the pathname of the current working directory exceeds this limit, then the system call fails with the error \fBENAMETOOLONG\fP. In this case, the library functions fall back to a (slower) alternative implementation that returns the full pathname. .PP .\" commit 8df9d1a4142311c084ffeeacb67cd34d190eff74 Following a change in Linux 2.6.36, the pathname returned by the \fBgetcwd\fP() system call will be prefixed with the string "(unreachable)" if the current directory is not below the root directory of the current process (e.g., because the process set a new filesystem root using \fBchroot\fP(2) without changing its current directory into the new root). Such behavior can also be caused by an unprivileged user by changing the current directory into another mount namespace. When dealing with pathname from untrusted sources, callers of the functions described in this page should consider checking whether the returned pathname starts with '/' or '(' to avoid misinterpreting an unreachable path as a relative pathname. .SH BOGUES Since the Linux 2.6.36 change that added "(unreachable)" in the circumstances described above, the glibc implementation of \fBgetcwd\fP() has failed to conform to POSIX and returned a relative pathname when the API contract requires an absolute pathname. With glibc 2.27 onwards this is corrected; calling \fBgetcwd\fP() from such a pathname will now result in failure with \fBENOENT\fP. .SH "VOIR AUSSI" \fBpwd\fP(1), \fBchdir\fP(2), \fBfchdir\fP(2), \fBopen\fP(2), \fBunlink\fP(2), \fBfree\fP(3), \fBmalloc\fP(3) .SH COLOPHON Cette page fait partie de la publication\ 5.10 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page peuvent être trouvées à l'adresse \%https://www.kernel.org/doc/man\-pages/. .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 et David Prévot . 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. 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 .