1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" References consulted:
.\" Linux libc source code
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
.\" 386BSD man pages
.\" Modified Sun Jul 25 10:54:03 1993 by Rik Faith (faith@cs.unc.edu)
.\" Fixed typo, aeb, 950823
.\" 2002-02-22, joey, mihtjel: Added strtoull()
.\" Traducción revisada por Miguel Pérez Ibars <mpi79470@alu.um.es> el 21-enero-2005
.\"
.TH STRTOUL 3 "30 mayo 2002" "GNU" "Manual del Programador de Linux"
.SH NOMBRE
strtoul, strtoull, strtouq \- convierten una cadena en un entero largo sin signo
.SH SINOPSIS
.nf
.B #include <stdlib.h>
.sp
.BI "unsigned long int"
.BI "strtoul(const char *" nptr ", char **" endptr ", int " base );
.sp
.BI "unsigned long long int"
.BI "strtoull(const char *" nptr ", char **" endptr ", int " base );
.fi
.SH DESCRIPCIÓN
La función \fBstrtoul()\fP convierte la parte inicial de la cadena \fInptr\fP en un
valor entero largo sin signo de acuerdo con la \fIbase\fP dada, la cual debe estar entre 2 y 36
inclusive, o ser el valor especial 0.
.PP
La cadena debe comenzar con una cantidad arbitraria de espacios en blanco
(determinado por
.BR isspace (3))
y seguida por un opcional y único signo `+' o `-'.
Si \fIbase\fP es cero o 16, la cadena puede entonces incluir un prefijo
`0x' , y el número se leerá en base 16; en caso contrario, una \fIbase\fP
cero se toma como 10 (decimal) a menos que el siguiente caracter sea `0',
en cuyo caso se toma como 8 (octal).
.PP
El resto de la cadena se convierte en un valor entero largo sin signo de la
manera obvia, deteniéndose en el primer caracter que no sea un dígito válido
en la base dada. (En bases por encima de 10, la letra `A' mayúscula o
minúscula representa 10, `B' representa 11, y así en adelante, con `Z'
representando 35).
.PP
Si \fIendptr\fP no es NULL, \fBstrtoul()\fP almacena la dirección del primer
caracter no válido en \fI*endptr\fP. Si no hubiera dígitos en absoluto
\fBstrtoul()\fP almacena el valor original de \fInptr\fP en \fI*endptr\fP.
(y devuelve 0).
En particular, si \fI*nptr\fP es distinto de `\\0' pero \fI**endptr\fP
es `\\0' a la vuelta, la cadena entera es válida.
.PP
La función
.B strtoull()
hace el mismo trabajo que la función
.B strtoul()
pero devuelve un valor entero de tipo long long.
.SH "VALOR DEVUELTO"
La función \fBstrtoul()\fP devuelve o el resultado de la conversión o, si
hubiera un signo menos delante, la negación del resultado de la conversión,
a menos que el valor original (no-negado) se hubiera sobrepasado; en tal
caso, \fBstrtoul()\fP devuelve ULONG_MAX y asigna ERANGE a la variable global
\fIerrno\fP.
Precisamente lo mismo se aplica a
.B strtoull()
(con ULLONG_MAX en lugar de ULONG_MAX).
.SH ERRORES
.TP
.B ERANGE
El valor resultante está fuera de rango.
.TP
.B EINVAL
(no está en C99)
La
.I base
dada contiene un valor no soportado.
.LP
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 OBSERVACIONES
En otras localizaciones distintas a la localización "C", se pueden aceptar
también otras cadenas.
(Por ejemplo, el separador de miles de la localización actual puede estar
soportado.)
.LP
BSD tiene también la función
.sp
.in +4n
.nf
.BI "u_quad_t"
.BI "strtouq(const char *" nptr ", char **" endptr ", int base" );
.sp
.in -4n
.fi
con una definición completamente análoga.
Dependiendo del tamaño de palabra de la arquitectura actual,
ésta puede ser equivalente a
.B strtoull()
o a
.BR strtoul() .
.SH "CONFORME A"
.B strtoul()
es conforme con SVID 3, BSD 4.3, ISO 9899 (C99) y POSIX, y
.BR strtoull()
es conforme con ISO 9899 (C99) y POSIX-2001.
.SH "VÉASE TAMBIÉN"
.BR atof (3),
.BR atoi (3),
.BR atol (3),
.BR strtod (3),
.BR strtol (3)
|