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:53:39 1993 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Added correction due to nsd@bbc.com (Nick Duffek) - aeb, 950610
|
_exit.2, brk.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, getdtablesize.2, gethostname.2, getpagesize.2, getsid.2, killpg.2, mknod.2, mknodat.2, poll.2, posix_fadvise.2, pread.2, readlink.2, setpgid.2, setreuid.2, sigaltstack.2, stat.2, symlink.2, sync.2, truncate.2, vfork.2, wait.2, wait4.2, a64l.3, abs.3, acos.3, acosh.3, asin.3, asinh.3, atan.3, atan2.3, atoi.3, cbrt.3, ceil.3, copysign.3, cosh.3, dirfd.3, div.3, ecvt.3, erf.3, erfc.3, exp.3, exp2.3, fabs.3, fdim.3, ffs.3, floor.3, fma.3, fmax.3, fmin.3, fmod.3, fpclassify.3, frexp.3, ftw.3, fwide.3, gcvt.3, getcwd.3, getdate.3, getgrent.3, gethostid.3, getpass.3, getpwent.3, getsubopt.3, getw.3, hypot.3, ilogb.3, index.3, isalpha.3, isgreater.3, iswblank.3, j0.3, ldexp.3, lockf.3, log.3, log10.3, log1p.3, logb.3, lrint.3, lround.3, mkstemp.3, mktemp.3, modf.3, mq_receive.3, mq_send.3, nan.3, nextafter.3, posix_fallocate.3, posix_memalign.3, printf.3, qecvt.3, random.3, realpath.3, remainder.3, remquo.3, rint.3, round.3, scalb.3, scalbln.3, scanf.3, siginterrupt.3, signbit.3, sigset.3, sinh.3, sqrt.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strfry.3, strpbrk.3, strsep.3, strspn.3, strstr.3, strtod.3, strtok.3, strtol.3, strtoul.3, strxfrm.3, tanh.3, tgamma.3, trunc.3, ttyslot.3, ualarm.3, usleep.3, wprintf.3, armscii-8.7, cp1251.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-3.7, iso_8859-5.7, iso_8859-6.7, iso_8859-8.7, koi8-u.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 17:19:13 +00:00
|
|
|
.TH STRTOL 3 2010-09-20 "GNU" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
strtol, strtoll, strtoq \- convert a string to a long integer
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <stdlib.h>
|
|
|
|
.sp
|
2007-12-23 08:20:39 +00:00
|
|
|
.BI "long int strtol(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 "long long int strtoll(const char *" nptr ", char **" endptr \
|
|
|
|
", 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 strtoll ():
|
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 strtol ()
|
|
|
|
function converts the initial part of the string
|
2004-11-03 13:51:07 +00:00
|
|
|
in \fInptr\fP to a long integer value according to the 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 sign.
|
2007-04-12 22:42:49 +00:00
|
|
|
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-04-12 22:42:49 +00:00
|
|
|
The remainder of the string is converted to a
|
2006-04-19 00:58:37 +00:00
|
|
|
.I long int
|
|
|
|
value
|
2004-11-03 13:51:07 +00:00
|
|
|
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 strtol ()
|
|
|
|
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 strtol ()
|
|
|
|
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 strtoll ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function works just like the
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtol ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function but returns a long long integer value.
|
|
|
|
.SH "RETURN VALUE"
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR strtol ()
|
|
|
|
function returns the result of the conversion,
|
2007-04-12 22:42:49 +00:00
|
|
|
unless the value would underflow or overflow.
|
|
|
|
If an underflow occurs,
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR strtol ()
|
2007-06-22 20:40:07 +00:00
|
|
|
returns
|
|
|
|
.BR LONG_MIN .
|
2007-05-12 09:06:04 +00:00
|
|
|
If an overflow occurs,
|
|
|
|
.BR strtol ()
|
2007-06-22 20:40:07 +00:00
|
|
|
returns
|
|
|
|
.BR LONG_MAX .
|
2007-06-22 06:05:43 +00:00
|
|
|
In both cases, \fIerrno\fP is set to
|
|
|
|
.BR ERANGE .
|
2004-11-03 13:51:07 +00:00
|
|
|
Precisely the same holds for
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtoll ()
|
2007-06-22 20:40:07 +00:00
|
|
|
(with
|
|
|
|
.B LLONG_MIN
|
|
|
|
and
|
|
|
|
.B LLONG_MAX
|
|
|
|
instead of
|
|
|
|
.B LONG_MIN
|
|
|
|
and
|
|
|
|
.BR LONG_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 strtol ()
|
|
|
|
conforms to SVr4, 4.3BSD, C89, C99 and POSIX.1-2001, and
|
|
|
|
.BR strtoll ()
|
|
|
|
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 strtol ()
|
2007-04-12 22:42:49 +00:00
|
|
|
can legitimately return 0,
|
2007-06-22 20:40:07 +00:00
|
|
|
.BR LONG_MAX ,
|
|
|
|
or
|
|
|
|
.B LONG_MIN
|
|
|
|
.RB ( LLONG_MAX
|
|
|
|
or
|
|
|
|
.B LLONG_MIN
|
|
|
|
for
|
2006-04-19 00:58:37 +00:00
|
|
|
.BR strtoll ())
|
|
|
|
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-04-18 09:02:55 +00:00
|
|
|
In locales other than the "C" locale, other strings may also 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-19 05:53:30 +00:00
|
|
|
.BI "quad_t strtoq(const char *" nptr ", char **" endptr ", int " base );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
2007-12-19 05:53:30 +00:00
|
|
|
.in
|
2004-11-03 13:51:07 +00:00
|
|
|
.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 strtoll ()
|
2004-11-03 13:51:07 +00:00
|
|
|
or to
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR strtol ().
|
2006-04-19 01:31:51 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
The program shown below demonstrates the use of
|
|
|
|
.BR strtol ().
|
2008-03-19 08:37:35 +00:00
|
|
|
The first command-line argument specifies a string from which
|
2006-04-19 01:31:51 +00:00
|
|
|
.BR strtol ()
|
|
|
|
should parse a number.
|
2007-04-12 22:42:49 +00:00
|
|
|
The second (optional) argument specifies the base to be used for
|
2006-04-19 01:31:51 +00:00
|
|
|
the conversion.
|
2006-04-20 21:56:03 +00:00
|
|
|
(This argument is converted to numeric form using
|
|
|
|
.BR atoi (3),
|
2007-04-12 22:42:49 +00:00
|
|
|
a function that performs no error checking and
|
2006-04-20 21:56:03 +00:00
|
|
|
has a simpler interface than
|
|
|
|
.BR strtol ().)
|
2006-04-19 01:31:51 +00:00
|
|
|
Some examples of the results produced by this program are the following:
|
2007-12-19 05:53:30 +00:00
|
|
|
.in +4n
|
2006-04-19 01:31:51 +00:00
|
|
|
.nf
|
|
|
|
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " ./a.out 123"
|
2006-04-19 01:31:51 +00:00
|
|
|
strtol() returned 123
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " ./a.out \(aq 123\(aq"
|
2006-04-19 01:31:51 +00:00
|
|
|
strtol() returned 123
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " ./a.out 123abc"
|
2006-04-19 01:31:51 +00:00
|
|
|
strtol() returned 123
|
|
|
|
Further characters after number: abc
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " ./a.out 123abc 55"
|
2006-04-19 01:31:51 +00:00
|
|
|
strtol: Invalid argument
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " ./a.out \(aq\(aq"
|
2006-04-19 01:31:51 +00:00
|
|
|
No digits were found
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " ./a.out 4000000000"
|
2006-04-19 01:31:51 +00:00
|
|
|
strtol: Numerical result out of range
|
|
|
|
.fi
|
2007-12-19 05:53:30 +00:00
|
|
|
.in
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strtol.3, core.5: global fix: Add ".SS Program source" to EXAMPLE
Add ".SS Program source" to clearly distinguish shell session and
descriptive text from actual program code.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:51:05 +00:00
|
|
|
.SS Program source
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getaddrinfo.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5: srcfix
s/\.R " "/\\\&/ as a way of getting a blank line after a .SS heading.
(Suggested by Sam Varshavchik <mrsam@courier-mta.com>)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-11-05 01:42:45 +00:00
|
|
|
\&
|
2006-04-19 01:31:51 +00:00
|
|
|
.nf
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int base;
|
|
|
|
char *endptr, *str;
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "Usage: %s str [base]\\n", argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
2007-04-12 22:42:49 +00:00
|
|
|
}
|
2006-04-19 01:31:51 +00:00
|
|
|
|
|
|
|
str = argv[1];
|
|
|
|
base = (argc > 2) ? atoi(argv[2]) : 10;
|
|
|
|
|
|
|
|
errno = 0; /* To distinguish success/failure after call */
|
|
|
|
val = strtol(str, &endptr, base);
|
|
|
|
|
|
|
|
/* Check for various possible errors */
|
|
|
|
|
|
|
|
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
|
|
|
|
|| (errno != 0 && val == 0)) {
|
|
|
|
perror("strtol");
|
|
|
|
exit(EXIT_FAILURE);
|
2007-04-12 22:42:49 +00:00
|
|
|
}
|
2006-04-19 01:31:51 +00:00
|
|
|
|
|
|
|
if (endptr == str) {
|
|
|
|
fprintf(stderr, "No digits were found\\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2007-04-12 22:42:49 +00:00
|
|
|
}
|
2006-04-19 01:31:51 +00:00
|
|
|
|
2006-04-20 21:56:03 +00:00
|
|
|
/* If we got here, strtol() successfully parsed a number */
|
2006-04-19 01:31:51 +00:00
|
|
|
|
|
|
|
printf("strtol() returned %ld\\n", val);
|
|
|
|
|
2008-06-09 15:49:35 +00:00
|
|
|
if (*endptr != \(aq\\0\(aq) /* Not necessarily an error... */
|
2006-04-19 01:31:51 +00:00
|
|
|
printf("Further characters after number: %s\\n", endptr);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
.fi
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR atof (3),
|
|
|
|
.BR atoi (3),
|
|
|
|
.BR atol (3),
|
|
|
|
.BR strtod (3),
|
|
|
|
.BR strtoul (3)
|