dwww Home | Manual pages | Find package

getcwd(3)                  Library Functions Manual                  getcwd(3)

NOM
       getcwd,  getwd, get_current_dir_name - Obtenir le répertoire de travail
       actuel

BIBLIOTHÈQUE
       Bibliothèque C standard (libc, -lc)

SYNOPSIS
       #include <unistd.h>

       char *getcwd(char buf[.size], size_t size);
       char *get_current_dir_name(void);

       [[deprecated]] char *getwd(char buf[PATH_MAX]);

   Exigences de macros de test de fonctionnalités  pour  la  glibc  (consulter
   feature_test_macros(7)) :

       get_current_dir_name() :
           _GNU_SOURCE

       getwd() :
           Since glibc 2.12:
               (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200809L)
                   || /* glibc >= 2.19: */ _DEFAULT_SOURCE
                   || /* glibc <= 2.19: */ _BSD_SOURCE
           Before glibc 2.12:
               _BSD_SOURCE || _XOPEN_SOURCE >= 500

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  pro-
       cessus appelant. Le chemin est renvoyé comme résultat de la fonction et
       par le paramètre buf, s'il est présent.

       La fonction getcwd() copie le chemin d'accès absolu  du  répertoire  de
       travail  courant  dans  la  chaîne pointée par buf, qui est de longueur
       size.

       Si la taille du chemin absolu du répertoire de travail en cours, carac-
       tère  nul de fin compris, dépasse size octets, la fonction renvoie NULL
       et errno contient le code d'erreur ERANGE. Une application doit  détec-
       ter cette erreur et allouer un tampon plus grand si besoin est.

       As  an  extension to the POSIX.1-2001 standard, glibc's getcwd()  allo-
       cates the buffer dynamically using malloc(3)  if buf is NULL.  In  this
       case,  the  allocated  buffer  has the length size unless size is zero,
       when buf is allocated as big as necessary. The  caller  should  free(3)
       the returned buffer.

       get_current_dir_name()  allouera avec malloc(3) une chaîne suffisamment
       grande pour contenir le nom du chemin absolu du répertoire  de  travail
       courant.  Si  la  variable  d'environnement PWD est configurée, et cor-
       recte, cette valeur sera renvoyée. L'appelant doit libérer avec free(3)
       le tampon renvoyé.

       getwd()  n'allouera  aucune  mémoire (avec malloc(3)). Le paramètre buf
       doit être un pointeur sur une chaîne comportant au moins  PATH_MAX  oc-
       tets.  Si la longueur du chemin absolu du répertoire de travail actuel,
       caractère nul de fin compris, dépasse PATH_MAX octets, NULL est renvoyé
       et  errno prend la valeur ENAMETOOLONG. Notez que sur certains système,
       PATH_MAX peut ne pas être une constante connue à  la  compilation ;  de
       plus,  sa valeur peut dépendre du système de fichiers, voire être illi-
       mitée, consultez pathconf(3). Pour des raisons de portabilité et de sé-
       curité, l'utilisation de getwd() est déconseillée.

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 getcwd()  and
       getwd()  this is the same value as buf.

       En cas d'échec, ces fonctions renvoient NULL, et remplissent errno avec
       le code d'erreur. Le contenu de la chaîne pointée par buf est  indéfini
       en cas d'erreur.

ERREURS
       EACCES Impossible  de lire ou de parcourir un composant du chemin d'ac-
              cès.

       EFAULT buf pointe sur une adresse illégale.

       EINVAL L'argument size vaut zéro et buf n'est pas un pointeur NULL.

       EINVAL getwd() : buf est NULL.

       ENAMETOOLONG
              getwd() : La taille de la chaîne, terminée par un octet nul,  du
              chemin absolu dépasse PATH_MAX octets.

       ENOENT Le répertoire en cours a été supprimé.

       ENOMEM Plus assez de mémoire.

       ERANGE Le  paramètre  size 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.

ATTRIBUTS
       Pour  une explication des termes utilisés dans cette section, consulter
       attributes(7).

       ┌─────────────────────────────────┬──────────────────────┬─────────────┐
       │InterfaceAttributValeur      │
       ├─────────────────────────────────┼──────────────────────┼─────────────┤
       │getcwd(), getwd()                │ Sécurité des threads │ MT-Safe     │
       ├─────────────────────────────────┼──────────────────────┼─────────────┤
       │get_current_dir_name()           │ Sécurité des threads │ MT-Safe env │
       └─────────────────────────────────┴──────────────────────┴─────────────┘

STANDARDS
       getcwd() se conforme à POSIX.1-2001. Notez cependant  que  POSIX.1-2001
       laisse le comportement de getcwd() non spécifié si buf est NULL.

       getwd()  est  présent  dans  POSIX.1-2001, mais marquée « LEGACY ». PO-
       SIX.1-2008 supprime la spécification de getwd() et POSIX.1-2001 ne  dé-
       finit aucune erreur pour getwd(). Utilisez getcwd() à la place.

       get_current_dir_name() est une extension GNU.

NOTES
       Under  Linux,  these  functions  make  use of the getcwd()  system call
       (available since Linux 2.1.92).  On  older  systems  they  would  query
       /proc/self/cwd.  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 EACCES.

       Ces  fonctions sont souvent utilisées pour sauver le répertoire de tra-
       vail afin d'y revenir plus tard. Ouvrir le répertoire  courant  (« . »)
       et  appeler fchdir(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.

   différences entre bibliothèque C et noyau
       On  Linux, the kernel provides a getcwd()  system call, which the func-
       tions 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 PATH_MAX bytes. (Before Linux 3.12, the
       limit on the size of the returned pathname was the system page size. On
       many architectures, PATH_MAX 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 ENAMETOOLONG. In this case,
       the library functions fall back to a (slower)  alternative  implementa-
       tion that returns the full pathname.

       Following  a  change  in  Linux  2.6.36,  the  pathname returned by the
       getcwd() 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
       chroot(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 rela-
       tive pathname.

BOGUES
       Since the Linux 2.6.36 change that added "(unreachable)" in the circum-
       stances described above, the glibc implementation of getcwd()  has fai-
       led  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  getcwd()   from such a pathname will now result in
       failure with ENOENT.

VOIR AUSSI
       pwd(1), chdir(2), fchdir(2), open(2), unlink(2), free(3), malloc(3)

TRADUCTION
       La traduction française de cette page de manuel a été créée par  Chris-
       tophe  Blaess  <https://www.blaess.fr/christophe/>, Stéphan Rafin <ste-
       phan.rafin@laposte.net>, Thierry Vignaud <tvignaud@mandriva.com>, Fran-
       çois  Micaux, Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe Gué-
       rard <fevrier@tigreraye.org>, Jean-Luc  Coulon  (f5ibh)  <jean-luc.cou-
       lon@wanadoo.fr>,  Julien  Cristau <jcristau@debian.org>, Thomas Huriaux
       <thomas.huriaux@gmail.com>, Nicolas François  <nicolas.francois@centra-
       liens.net>,  Florentin  Duneau <fduneau@gmail.com>, Simon Paillard <si-
       mon.paillard@resel.enst-bretagne.fr>,   Denis   Barbier    <barbier@de-
       bian.org> et David Prévot <david@tilapin.org>

       Cette traduction est une documentation libre ; veuillez vous reporter à
       la       GNU       General       Public        License        version 3
       ⟨https://www.gnu.org/licenses/gpl-3.0.html⟩  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 à ⟨debian-l10n-french@lists.debian.org⟩.

Pages du manuel de Linux 6.03   5 février 2023                       getcwd(3)

Generated by dwww version 1.15 on Sat Jun 29 01:47:24 CEST 2024.