.\" -*- 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 strtoll 3 "20 ​​Julio 2023" "Páginas de manual de Linux 6.05.01" .SH NOMBRE strtol, strtoll, strtoq \- convierten una cadena en un entero de tipo long .SH BIBLIOTECA Biblioteca Estándar C (\fIlibc\fP, \fI\-lc\fP) .SH SINOPSIS .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 Requisitos de Macros de Prueba de Características para glibc (véase \fBfeature_test_macros\fP(7)): .RE .PP \fBstrtoll\fP(): .nf _ISOC99_SOURCE || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE .fi .SH DESCRIPCIÓN La función \fBstrtol\fP() convierte la parte inicial de la cadena de entrada \fInptr\fP en un valor entero de tipo long de acuerdo a la \fIbase\fP dada, que debe estar entre 2 y 36 ambos incluidos o ser el valor especial 0. .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 función \fBstrtoll\fP() hace el mismo trabajo que la función \fBstrtol\fP() pero devuelve un valor entero de tipo \fIlong long\fP. .SH "VALOR DEVUELTO" La función \fBstrtol\fP() devuelve el resultado de la conversión, a menos que el valor se desbordara por arriba o por abajo. Si ocurriera un desbordamiento inferior, \fBstrtol\fP() devuelve \fBLONG_MIN\fP. Si ocurriera un desbordamiento superior, \fBstrtol\fP() devuelve \fBLONG_MAX\fP. En ambos casos, \fIerrno\fP se establece a \fBERANGE\fP. Precisamente lo mismo se aplica a \fBstrtoll\fP() (con \fBLLONG_MIN\fP y \fBLLONG_MAX\fP en lugar de \fBLONG_MIN\fP y \fBLONG_MAX\fP). .SH ERRORES .TP \fBEINVAL\fP (no está en C99) La \fIbase\fP dada contiene un valor no soportado. .TP \fBERANGE\fP El valor resultante está fuera de rango. .PP La implementación puede poner también \fIerrno\fP a \fBEINVAL\fP en caso de que no se realice ninguna conversión (no se encuentren dígitos, y se devuelva 0). .SH ATRIBUTOS Para obtener una explicación de los términos usados en esta sección, véase \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Interfaz Atributo Valor T{ .na .nh \fBstrtol\fP(), \fBstrtoll\fP(), \fBstrtoq\fP() T} Seguridad del hilo Configuración regional de multi\-hilo seguro .TE .sp 1 .SH ESTÁNDARES C11, POSIX.1\-2008. .SH HISTORIAL .TP \fBstrtol\fP() POSIX.1\-2001, C89, SVr4, 4.3BSD. .TP \fBstrtoll\fP() POSIX.1\-2001, C99. .SH NOTAS Since \fBstrtol\fP() can legitimately return 0, \fBLONG_MAX\fP, or \fBLONG_MIN\fP (\fBLLONG_MAX\fP or \fBLLONG_MIN\fP for \fBstrtoll\fP()) on both success and failure, the calling program should set \fIerrno\fP to 0 before the call, and then determine if an error occurred by checking whether \fIerrno\fP has a nonzero value after the call. .PP According to POSIX.1, in locales other than "C" and "POSIX", these functions may accept other, implementation\-defined numeric strings. .PP BSD tiene también la función .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 con una definición completamente análoga. Dependiendo del tamaño de palabra de la arquitectura actual, ésta puede ser equivalente a \fBstrtoll\fP() o a \fBstrtol\fP(). .SH EJEMPLOS The program shown below demonstrates the use of \fBstrtol\fP(). The first command\-line argument specifies a string from which \fBstrtol\fP() should parse a number. The second (optional) argument specifies the base to be used for the conversion. (This argument is converted to numeric form using \fBatoi\fP(3), a function that performs no error checking and has a simpler interface than \fBstrtol\fP().) Some examples of the results produced by this program are the following: .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 "Código fuente" .\" 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; /* To distinguish success/failure after call */ val = strtol(str, &endptr, base); \& /* Check for various possible errors. */ \& if (errno != 0) { perror("strtol"); exit(EXIT_FAILURE); } \& if (endptr == str) { fprintf(stderr, "No digits were found\en"); exit(EXIT_FAILURE); } \& /* If we got here, strtol() successfully parsed a number. */ \& printf("strtol() returned %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 "VÉASE TAMBIÉN" \fBatof\fP(3), \fBatoi\fP(3), \fBatol\fP(3), \fBstrtod\fP(3), \fBstrtoimax\fP(3), \fBstrtoul\fP(3) .PP .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Carlos Gomez Romero , Miguel Pérez Ibars y Marcos Fouces . .PP Esta traducción es documentación libre; lea la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 .UE o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD. .PP Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a .MT debian-l10n-spanish@lists.debian.org .ME .