.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 2022 Alejandro Colomar .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH stpncpy 3 "12 février 2024" "Pages du manuel de Linux 6.06" .SH NOM stpncpy, strncpy \- fill a fixed\-size buffer with non\-null bytes from a string, padding with null bytes as needed .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP, \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .P \fBchar *strncpy(char \fP\fIdst\fP\fB[restrict .\fP\fIdsize\fP\fB], const char *restrict \fP\fIsrc\fP\fB,\fP \fB size_t \fP\fIdsize\fP\fB);\fP \fBchar *stpncpy(char \fP\fIdst\fP\fB[restrict .\fP\fIdsize\fP\fB], const char *restrict \fP\fIsrc\fP\fB,\fP \fB size_t \fP\fIdsize\fP\fB);\fP .fi .P .RS -4 Exigences de macros de test de fonctionnalités pour la glibc (consulter \fBfeature_test_macros\fP(7)) : .RE .P \fBstpncpy\fP()\ : .nf Depuis la glibc 2.10 : _POSIX_C_SOURCE >= 200809L Avant la glibc 2.10 : _GNU_SOURCE .fi .SH DESCRIPTION These functions copy non\-null bytes from the string pointed to by \fIsrc\fP into the array pointed to by \fIdst\fP. If the source has too few non\-null bytes to fill the destination, the functions pad the destination with trailing null bytes. If the destination buffer, limited by its size, isn't large enough to hold the copy, the resulting character sequence is truncated. For the difference between the two functions, see RETURN VALUE. .P Une implémentation de ces fonctions pourrait être cela : .P .in +4n .EX char * strncpy(char *restrict dst, const char *restrict src, size_t dsize) { stpncpy(dst, src, dsize); return dst; } \& char * stpncpy(char *restrict dst, const char *restrict src, size_t dsize) { size_t dlen; \& dlen = strnlen(src, dsize); return memset(mempcpy(dst, src, dlen), 0, dsize \- dlen); } .EE .in .SH "VALEUR RENVOYÉE" .TP \fBstrncpy\fP() renvoie \fIdst\fP. .TP \fBstpncpy\fP() renvoie un pointeur sur un octet après le dernier caractère dans la séquence de caractères de destination. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Interface Attribut Valeur T{ .na .nh \fBstpncpy\fP(), \fBstrncpy\fP() T} Sécurité des threads MT\-Safe .TE .SH STANDARDS .TP \fBstrncpy\fP() C11, POSIX.1\-2008. .TP \fBstpncpy\fP() POSIX.1\-2008. .SH HISTORIQUE .TP \fBstrncpy\fP() C89, POSIX.1\-2001, SVr4, 4.3BSD. .TP \fBstpncpy\fP() glibc 1.07. POSIX.1\-2008. .SH AVERTISSEMENTS The name of these functions is confusing. These functions produce a null\-padded character sequence, not a string (see \fBstring_copying\fP(7)). For example: .P .in +4n .EX strncpy(buf, "1", 5); // { \[aq]1\[aq], 0, 0, 0, 0 } strncpy(buf, "1234", 5); // { \[aq]1\[aq], \[aq]2\[aq], \[aq]3\[aq], \[aq]4\[aq], 0 } strncpy(buf, "12345", 5); // { \[aq]1\[aq], \[aq]2\[aq], \[aq]3\[aq], \[aq]4\[aq], \[aq]5\[aq] } strncpy(buf, "123456", 5); // { \[aq]1\[aq], \[aq]2\[aq], \[aq]3\[aq], \[aq]4\[aq], \[aq]5\[aq] } .EE .in .P Il est impossible de distinguer une troncature comme résultat de l'appel d'une séquence de caractères qui s'ajuste au tampon de destination ; la troncature peut être détectée en comparant la longueur de la chaîne d'entrée à celle du tampon de destination. .P Si vous comptez utiliser cette fonction dans une chaîne d'appels, il pourrait être utile de développer une fonction similaire qui accepte un pointeur sur la fin (un octet après le dernier élément) du tampon de destination plutôt qu'en donnant sa taille. .SH EXEMPLES .\" SRC BEGIN (stpncpy.c) .EX #include #include #include #include \& int main(void) { char *p; char buf1[20]; char buf2[20]; size_t len; \& if (sizeof(buf2) < strlen("Hello world!")) errx("strncpy: truncating character sequence"); strncpy(buf2, "Hello world!", sizeof(buf2)); len = strnlen(buf2, sizeof(buf2)); \& printf("[len = %zu]: ", len); fwrite(buf2, 1, len, stdout); putchar(\[aq]\en\[aq]); \& if (sizeof(buf1) < strlen("Hello world!")) errx("stpncpy: truncating character sequence"); p = stpncpy(buf1, "Hello world!", sizeof(buf1)); len = p \- buf1; \& printf("[len = %zu]: ", len); fwrite(buf1, 1, len, stdout); putchar(\[aq]\en\[aq]); \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VOIR AUSSI" \fBwcpncpy\fP(3), \fBstring_copying\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 , Grégoire Scano et Jean-Pierre Giraud . .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 .