2004-11-03 13:51:07 +00:00
|
|
|
.\" 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.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" 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.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" 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()
|
|
|
|
.\"
|
2011-09-16 04:29:51 +00:00
|
|
|
.TH STRTOUL 3 2011-09-15 "GNU" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <stdlib.h>
|
|
|
|
.sp
|
2007-12-23 08:20:39 +00:00
|
|
|
.BI "unsigned long int strtoul(const char *" nptr ", char **" endptr \
|
|
|
|
", int " base );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
2007-12-23 08:20:39 +00:00
|
|
|
.BI "unsigned long long int strtoull(const char *" nptr ", char **" endptr ,
|
|
|
|
.BI " int " base );
|
2004-11-03 13:51:07 +00:00
|
|
|
.fi
|
2007-07-08 12:11:40 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
.in
|
|
|
|
.sp
|
|
|
|
.ad l
|
|
|
|
.BR strtoull ():
|
2010-09-18 16:32:42 +00:00
|
|
|
.RS 4
|
brk.2, chroot.2, faccessat.2, fchmodat.2, fchownat.2, fstatat.2, futimesat.2, getdtablesize.2, getpagesize.2, getsid.2, linkat.2, mkdirat.2, mknodat.2, openat.2, pread.2, readlinkat.2, renameat.2, setpgid.2, sigaltstack.2, symlinkat.2, sync.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, unlinkat.2, utimensat.2, vfork.2, acosh.3, asinh.3, atanh.3, dirfd.3, dprintf.3, ecvt.3, expm1.3, fexecve.3, fmemopen.3, gcvt.3, getcwd.3, gethostid.3, getpass.3, getsubopt.3, getw.3, mbsnrtowcs.3, mkfifoat.3, mkstemp.3, mktemp.3, opendir.3, posix_memalign.3, rint.3, siginterrupt.3, stpcpy.3, stpncpy.3, strdup.3, strerror.3, strnlen.3, strsignal.3, strtol.3, strtoul.3, ualarm.3, usleep.3, wcpcpy.3, wcpncpy.3, wcscasecmp.3, wcsdup.3, wcsncasecmp.3, wcsnlen.3, wcsnrtombs.3: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 06:02:38 +00:00
|
|
|
XOPEN_SOURCE\ >=\ 600 || _BSD_SOURCE || _SVID_SOURCE || _ISOC99_SOURCE ||
|
2010-09-18 16:37:36 +00:00
|
|
|
_POSIX_C_SOURCE\ >=\ 200112L;
|
2010-09-18 16:32:42 +00:00
|
|
|
.br
|
|
|
|
or
|
2007-07-08 12:11:40 +00:00
|
|
|
.I cc\ -std=c99
|
2010-09-18 16:32:42 +00:00
|
|
|
.RE
|
|
|
|
.ad
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR strtoul ()
|
|
|
|
function converts the initial part of the string
|
2007-12-13 20:46:52 +00:00
|
|
|
in \fInptr\fP to an
|
|
|
|
.I "unsigned long int"
|
|
|
|
value according to the
|
2004-11-03 13:51:07 +00:00
|
|
|
given \fIbase\fP, which must be between 2 and 36 inclusive, or be
|
|
|
|
the special value 0.
|
|
|
|
.PP
|
2006-01-19 18:45:50 +00:00
|
|
|
The string may begin with an arbitrary amount of white space (as
|
2004-11-03 13:51:07 +00:00
|
|
|
determined by
|
|
|
|
.BR isspace (3))
|
2008-06-09 15:49:35 +00:00
|
|
|
followed by a single optional \(aq+\(aq or \(aq\-\(aq
|
2007-04-12 22:42:49 +00:00
|
|
|
sign.
|
|
|
|
If \fIbase\fP is zero or 16, the string may then include a
|
2007-06-12 21:40:00 +00:00
|
|
|
"0x" prefix, and the number will be read in base 16; otherwise, a
|
2004-11-03 13:51:07 +00:00
|
|
|
zero \fIbase\fP is taken as 10 (decimal) unless the next character
|
2008-06-09 15:49:35 +00:00
|
|
|
is \(aq0\(aq, in which case it is taken as 8 (octal).
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-12-13 20:46:52 +00:00
|
|
|
The remainder of the string is converted to an
|
|
|
|
.I "unsigned long int"
|
|
|
|
value in the obvious manner,
|
|
|
|
stopping at the first character which is not a
|
2007-04-12 22:42:49 +00:00
|
|
|
valid digit in the given base.
|
2008-06-09 15:49:35 +00:00
|
|
|
(In bases above 10, the letter \(aqA\(aq in
|
|
|
|
either upper or lower case represents 10, \(aqB\(aq represents 11, and so
|
|
|
|
forth, with \(aqZ\(aq representing 35.)
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
If \fIendptr\fP is not NULL,
|
|
|
|
.BR strtoul ()
|
|
|
|
stores the address of the
|
2007-04-12 22:42:49 +00:00
|
|
|
first invalid character in \fI*endptr\fP.
|
|
|
|
If there were no digits at
|
2007-05-12 09:06:04 +00:00
|
|
|
all,
|
|
|
|
.BR strtoul ()
|
|
|
|
stores the original value of \fInptr\fP in
|
2004-11-03 13:51:07 +00:00
|
|
|
\fI*endptr\fP (and returns 0).
|
2008-06-09 15:49:35 +00:00
|
|
|
In particular, if \fI*nptr\fP is not \(aq\\0\(aq but \fI**endptr\fP
|
|
|
|
is \(aq\\0\(aq on return, the entire string is valid.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
|
|
|
The
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtoull ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function works just like the
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtoul ()
|
2007-12-13 20:46:52 +00:00
|
|
|
function but returns an
|
|
|
|
.I "unsigned long long int"
|
|
|
|
value.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR strtoul ()
|
|
|
|
function returns either the result of the conversion
|
2004-11-03 13:51:07 +00:00
|
|
|
or, if there was a leading minus sign, the negation of the result of the
|
2007-04-12 22:42:49 +00:00
|
|
|
conversion represented as an unsigned value,
|
2010-01-16 17:20:55 +00:00
|
|
|
unless the original (nonnegated) value would overflow; in
|
2007-05-12 09:06:04 +00:00
|
|
|
the latter case,
|
|
|
|
.BR strtoul ()
|
2007-07-09 20:07:44 +00:00
|
|
|
returns
|
|
|
|
.B ULONG_MAX
|
2009-02-23 02:34:12 +00:00
|
|
|
and sets \fIerrno\fP to
|
2007-07-09 20:07:44 +00:00
|
|
|
.BR ERANGE .
|
2004-11-03 13:51:07 +00:00
|
|
|
Precisely the same holds for
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtoull ()
|
2007-07-09 20:07:44 +00:00
|
|
|
(with
|
|
|
|
.B ULLONG_MAX
|
|
|
|
instead of
|
|
|
|
.BR ULONG_MAX ).
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
(not in C99)
|
|
|
|
The given
|
|
|
|
.I base
|
|
|
|
contains an unsupported value.
|
|
|
|
.TP
|
|
|
|
.B ERANGE
|
|
|
|
The resulting value was out of range.
|
|
|
|
.LP
|
|
|
|
The implementation may also set \fIerrno\fP to \fBEINVAL\fP in case
|
|
|
|
no conversion was performed (no digits seen, and 0 returned).
|
2007-05-19 04:30:20 +00:00
|
|
|
.SH "CONFORMING TO"
|
|
|
|
.BR strtoul ()
|
|
|
|
conforms to SVr4, C89, C99 and POSIX-2001, and
|
|
|
|
.BR strtoull ()
|
|
|
|
to C99 and POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
2007-04-12 22:42:49 +00:00
|
|
|
Since
|
2006-04-19 00:58:37 +00:00
|
|
|
.BR strtoul ()
|
2007-07-09 20:07:44 +00:00
|
|
|
can legitimately return 0 or
|
2011-09-08 19:22:37 +00:00
|
|
|
.B ULONG_MAX
|
|
|
|
.RB ( ULLONG_MAX
|
2007-07-09 20:07:44 +00:00
|
|
|
for
|
2006-04-19 00:58:37 +00:00
|
|
|
.BR strtoull ())
|
|
|
|
on both success and failure, the calling program should set
|
|
|
|
.I errno
|
2007-04-12 22:42:49 +00:00
|
|
|
to 0 before the call,
|
2006-04-19 00:58:37 +00:00
|
|
|
and then determine if an error occurred by checking whether
|
|
|
|
.I errno
|
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
|
|
|
has a nonzero value after the call.
|
2006-04-19 00:58:37 +00:00
|
|
|
|
2006-06-06 01:07:10 +00:00
|
|
|
In locales other than the "C" locale, other strings may be accepted.
|
2004-11-03 13:51:07 +00:00
|
|
|
(For example, the thousands separator of the current locale may be
|
|
|
|
supported.)
|
|
|
|
.LP
|
|
|
|
BSD also has
|
|
|
|
.sp
|
|
|
|
.in +4n
|
|
|
|
.nf
|
2007-12-24 16:21:35 +00:00
|
|
|
.BI "u_quad_t strtouq(const char *" nptr ", char **" endptr ", int " base );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
.fi
|
|
|
|
with completely analogous definition.
|
|
|
|
Depending on the wordsize of the current architecture, this
|
|
|
|
may be equivalent to
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtoull ()
|
2004-11-03 13:51:07 +00:00
|
|
|
or to
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtoul ().
|
2006-06-06 01:07:10 +00:00
|
|
|
|
|
|
|
Negative values are considered valid input and are
|
2007-12-13 20:46:52 +00:00
|
|
|
silently converted to the equivalent
|
|
|
|
.I "unsigned long int"
|
|
|
|
value.
|
2006-04-19 01:33:09 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
See the example on the
|
|
|
|
.BR strtol (3)
|
2007-04-12 22:42:49 +00:00
|
|
|
manual page;
|
2006-04-19 01:33:09 +00:00
|
|
|
the use of the functions described in this manual page is similar.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR atof (3),
|
|
|
|
.BR atoi (3),
|
|
|
|
.BR atol (3),
|
|
|
|
.BR strtod (3),
|
|
|
|
.BR strtol (3)
|