Provided by: manpages-fr-dev_4.21.0-2_all bug

NOM

       stpcpy, strcpy, strcat - Copier ou concaténer une chaîne

BIBLIOTHÈQUE

       Bibliothèque C standard (libc, -lc)

SYNOPSIS

       #include <string.h>

       char *stpcpy(char *restrict dst, const char *restrict src);
       char *strcpy(char *restrict dst, const char *restrict src);
       char *strcat(char *restrict dst, const char *restrict src);

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

       stpcpy() :
           Depuis la glibc 2.10 :
               _POSIX_C_SOURCE >= 200809L
           Avant la glibc 2.10 :
               _GNU_SOURCE

DESCRIPTION

       stpcpy()
       strcpy()
              Ces fonctions copient la chaîne pointée par src dans  une  chaîne  dans  le  tampon
              pointé  par  dst.  Le  programmeur  est  responsable de l'allocation d'un tampon de
              destination suffisamment grand, c'est-à-dire strlen(src) + 1.  Pour  la  différence
              entre les deux fonctions voir VALEUR RENVOYÉE.

       strcat()
              Cette  fonction concatène la chaîne pointée par src après la chaîne pointée par dst
              (écrasant son octet NULL final). Le programmeur  est  responsable  de  l'allocation
              d'un   tampon   de   destination  suffisamment  grand,  c'est-à-dire  strlen(dst) +
              strlen(src) + 1.

       Une implémentation de ces fonctions pourrait être :

           char *
           stpcpy(char *restrict dst, const char *restrict src)
           {
               char  *p;

               p = mempcpy(dst, src, strlen(src));
               *p = '\0';

               return p;
           }

           char *
           strcpy(char *restrict dst, const char *restrict src)
           {
               stpcpy(dst, src);
               return dst;
           }

           char *
           strcat(char *restrict dst, const char *restrict src)
           {
               stpcpy(dst + strlen(dst), src);
               return dst;
           }

VALEUR RENVOYÉE

       stpcpy()
              Cette fonction renvoie un pointeur vers l'octet NULL final de la chaîne copiée.

       strcpy()
       strcat()
              Ces fonctions renvoient dst.

ATTRIBUTS

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

       ┌────────────────────────────────────────────────────────┬──────────────────────┬─────────┐
       │InterfaceAttributValeur  │
       ├────────────────────────────────────────────────────────┼──────────────────────┼─────────┤
       │stpcpy(), strcpy(), strcat()                            │ Sécurité des threads │ MT-Safe │
       └────────────────────────────────────────────────────────┴──────────────────────┴─────────┘

STANDARDS

       stpcpy()
              POSIX.1-2008.

       strcpy()
       strcat()
              POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD.

AVERTISSEMENTS

       Les chaînes src et dst ne doivent pas se chevaucher.

       Si le tampon de destination n'est pas assez grand,  le  comportement  est  indéfini.  Voir
       _FORTIFY_SOURCE dans feature_test_macros(7).

       strcat()   peut   être   très   inefficace.   Lire   à   ce   sujet  Shlemiel  the painter
       ⟨https://www.joelonsoftware.com/2001/12/11/back-to-basics/⟩.

EXEMPLES

       #include <err.h>
       #include <stdio.h>
       #include <stdlib.h>
       #include <string.h>

       int
       main(void)
       {
           char    *p;
           char    *buf1;
           char    *buf2;
           size_t  len, maxsize;

           maxsize = strlen("Hello ") + strlen("world") + strlen("!") + 1;
           buf1 = malloc(sizeof(*buf1) * maxsize);
           if (buf1 == NULL)
               err(EXIT_FAILURE, "malloc()");
           buf2 = malloc(sizeof(*buf2) * maxsize);
           if (buf2 == NULL)
               err(EXIT_FAILURE, "malloc()");

           p = buf1;
           p = stpcpy(p, "Hello ");
           p = stpcpy(p, "world");
           p = stpcpy(p, "!");
           len = p - buf1;

           printf("[len = %zu]: ", len);
           puts(buf1);  // "Hello world!"
           free(buf1);

           strcpy(buf2, "Hello ");
           strcat(buf2, "world");
           strcat(buf2, "!");
           len = strlen(buf2);

           printf("[len = %zu]: ", len);
           puts(buf2);  // "Hello world!"
           free(buf2);

           exit(EXIT_SUCCESS);
       }

VOIR AUSSI

       strdup(3), string(3), wcscpy(3), string_copying(7)

TRADUCTION

       La traduction française de cette  page  de  manuel  a  été  créée  par  Christophe  Blaess
       <https://www.blaess.fr/christophe/>,  Stéphan  Rafin  <stephan.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.coulon@wanadoo.fr>,   Julien    Cristau    <jcristau@debian.org>,    Thomas    Huriaux
       <thomas.huriaux@gmail.com>, Nicolas François <nicolas.francois@centraliens.net>, Florentin
       Duneau <fduneau@gmail.com>, Simon Paillard <simon.paillard@resel.enst-bretagne.fr>,  Denis
       Barbier   <barbier@debian.org>,   David   Prévot  <david@tilapin.org>,  Frédéric  Hantrais
       <fhantrais@gmail.com>, Grégoire Scano  <gregoire.scano@malloc.fr>  et  Jean-Pierre  Giraud
       <jean-pierregiraud@neuf.fr>

       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⟩.