.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" and Copyright 2006 Michael Kerrisk .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sun Jul 25 10:53:39 1993 by Rik Faith (faith@cs.unc.edu) .\" Added correction due to nsd@bbc.com (Nick Duffek) - aeb, 950610 .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH strtol 3 "5 février 2023" "Pages du manuel de Linux 6.03" .SH NOM strtol, strtoll, strtoq \- Convertir une chaîne en un entier long .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP, \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .PP \fBlong strtol(const char *restrict \fP\fInptr\fP\fB,\fP \fB char **restrict \fP\fIendptr\fP\fB, int \fP\fIbase\fP\fB);\fP \fBlong long strtoll(const char *restrict \fP\fInptr\fP\fB,\fP \fB char **restrict \fP\fIendptr\fP\fB, int \fP\fIbase\fP\fB);\fP .fi .PP .RS -4 Exigences de macros de test de fonctionnalités pour la glibc (consulter \fBfeature_test_macros\fP(7))\ : .RE .PP \fBstrtoll\fP()\ : .nf _ISOC99_SOURCE || /* glibc <= 2.19 : */ _SVID_SOURCE || _BSD_SOURCE .fi .SH DESCRIPTION La fonction \fBstrtol\fP() convertit la partie initiale de la chaîne \fInptr\fP en un entier long en fonction de l'argument \fIbase\fP, qui doit être dans l'intervalle \fB2\fP à \fB36\fP (bornes comprises), ou avoir la valeur spéciale \fB0\fP. .PP The string may begin with an arbitrary amount of white space (as determined by \fBisspace\fP(3)) followed by a single optional \[aq]+\[aq] or \[aq]\-\[aq] sign. If \fIbase\fP is zero or 16, the string may then include a "0x" or "0X" prefix, and the number will be read in base 16; otherwise, a zero \fIbase\fP is taken as 10 (decimal) unless the next character is \[aq]0\[aq], in which case it is taken as 8 (octal). .PP The remainder of the string is converted to a \fIlong\fP value in the obvious manner, stopping at the first character which is not a valid digit in the given base. (In bases above 10, the letter \[aq]A\[aq] in either uppercase or lowercase represents 10, \[aq]B\[aq] represents 11, and so forth, with \[aq]Z\[aq] representing 35.) .PP If \fIendptr\fP is not NULL, \fBstrtol\fP() stores the address of the first invalid character in \fI*endptr\fP. If there were no digits at all, \fBstrtol\fP() stores the original value of \fInptr\fP in \fI*endptr\fP (and returns 0). In particular, if \fI*nptr\fP is not \[aq]\e0\[aq] but \fI**endptr\fP is \[aq]\e0\[aq] on return, the entire string is valid. .PP La fonction \fBstrtoll\fP() fonctionne comme \fBstrtol\fP() mais renvoie une valeur entière de type \fIlong long\fP. .SH "VALEUR RENVOYÉE" La fonction \fBstrtol\fP() renvoie le résultat de la conversion, à moins qu'un débordement supérieur (overflow) ou inférieur (underflow) se produise. Si un dépassement inférieur se produit, \fBstrtol\fP() renvoie \fBLONG_MIN\fP. Si un dépassement supérieur se produit, \fBstrtol\fP() renvoie \fBLONG_MAX\fP. Dans les deux cas, \fIerrno\fP contient le code d'erreur \fBERANGE\fP. La même chose est vraie pour \fBstrtoll\fP() avec \fBLLONG_MIN\fP et \fBLLONG_MAX\fP à la place de \fBLONG_MIN\fP et \fBLONG_MAX\fP. .SH ERREURS .TP \fBEINVAL\fP (pas dans C99) La \fIbase\fP indiquée n'est pas prise en charge. .TP \fBERANGE\fP La valeur retournée est hors limites. .PP L'implémentation peut aussi mettre \fIerrno\fP à \fBEINVAL\fP si aucune conversion n'a été réalisée (pas de chiffres trouvés, et \fB0\fP renvoyé). .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .ad l .nh .TS allbox; lbx lb lb l l l. Interface Attribut Valeur T{ \fBstrtol\fP(), \fBstrtoll\fP(), \fBstrtoq\fP() T} Sécurité des threads MT\-Safe locale .TE .hy .ad .sp 1 .SH STANDARDS \fBstrtol\fP(): POSIX.1\-2001, POSIX.1\-2008, C99, SVr4, 4.3BSD. .PP \fBstrtoll\fP()\ : POSIX.1\-2001, POSIX.1\-2008, C99. .SH NOTES Comme \fBstrtol\fP() peut légitimement renvoyer 0, \fBLONG_MAX\fP ou \fBLONG_MIN\fP (\fBLLONG_MAX\fP ou \fBLLONG_MIN\fP pour \fBstrtoll\fP()) à la fois en cas de succès et d'échec, le programme appelant doit positionner \fIerrno\fP à 0 avant l'appel, et déterminer si une erreur s'est produite en vérifiant si \fIerrno\fP a une valeur non nulle après l'appel. .PP POSIX.1 spécifie que dans le cas de locales autres que «\ C\ » et «\ POSIX\ », ces fonctions peuvent accepter des chaînes numériques propres à l'implémentation. .PP BSD a aussi .PP .in +4n .EX \fBquad_t strtoq(const char *\fP\fInptr\fP\fB, char **\fP\fIendptr\fP\fB, int \fP\fIbase\fP\fB);\fP .EE .in .PP avec une définition exactement analogue. Suivant l'architecture, cela peut être équivalent à \fBstrtoll\fP() ou \fBstrtol\fP(). .SH EXEMPLES Le programme suivant montre l'utilisation de \fBstrtol\fP(). Le premier argument de la ligne de commande spécifie une chaîne dans laquelle \fBstrtol\fP() analysera un nombre. Le second argument, optionnel, spécifie la base à utiliser pour la conversion. (Cet argument est converti sous forme numérique avec \fBatoi\fP(3), une fonction qui n'effectue aucune vérification d'erreur et qui a une interface plus simple que \fBstrtol\fP()). Voici plusieurs exemples de résultats produits par ce programme\ : .PP .in +4n .EX $\fB ./a.out 123\fP strtol() returned 123 $\fB ./a.out \[aq] 123\[aq]\fP strtol() returned 123 $\fB ./a.out 123abc\fP strtol() returned 123 Further characters after number: "abc" $\fB ./a.out 123abc 55\fP strtol: Invalid argument $\fB ./a.out \[aq]\[aq]\fP No digits were found $\fB ./a.out 4000000000\fP strtol: Numerical result out of range .EE .in .SS "Source du programme" .\" SRC BEGIN (strtol.c) \& .EX #include #include #include #include int main(int argc, char *argv[]) { int base; char *endptr, *str; long val; if (argc < 2) { fprintf(stderr, "Usage\ : %s str [base]\en", argv[0]); exit(EXIT_FAILURE); } str = argv[1]; base = (argc > 2) ? atoi(argv[2]) : 0; errno = 0; /* Pour distinguer la réussite/échec après l'appel */ val = strtol(str, &endptr, base); /* Check for various possible errors. */ if (errno != 0) { perror("strtol"); exit(EXIT_FAILURE); } if (endptr == str) { fprintf(stderr, "Pas de chiffre trouvé\en"); exit(EXIT_FAILURE); } /* If we got here, strtol() successfully parsed a number. */ printf("strtol() a renvoyé %ld\en", val); if (*endptr != \[aq]\e0\[aq]) /* Not necessarily an error... */ printf("Further characters after number: \e"%s\e"\en", endptr); exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VOIR AUSSI" \fBatof\fP(3), \fBatoi\fP(3), \fBatol\fP(3), \fBstrtod\fP(3), \fBstrtoimax\fP(3), \fBstrtoul\fP(3) .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 et Grégoire Scano . .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 .