Date: Sat, 17 Jan 2009 14:23:49 +0100 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: Garrett Cooper <yanefbsd@gmail.com> Cc: "amd64@freebsd.org" <amd64@freebsd.org>, Hackers freeBSD <freebsd-hackers@freebsd.org> Subject: Re: Confused by segfault with legitimate call to strerror(3) on amd64 / sysctl(3) setting `odd' errno's Message-ID: <86wscuyska.fsf@ds4.des.no> In-Reply-To: <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com> (Garrett Cooper's message of "Fri, 16 Jan 2009 00:41:37 -0800") References: <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Garrett Cooper <yanefbsd@gmail.com> writes:
> #include <err.h>
> #include <errno.h>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/sysctl.h>
You should always put your sys includes before your non-sys includes,
and in any case, <sys/types.h> should always come first.
> printf("Errno: %d\n", errno);
> errx(errno, "Error: %s", strerror(errno));
In addition to what everybody else said, errno is not an appropriate
value for errx's first argument. Use 1 or EXIT_FAILURE (or one of the
macros defined in <sysexits.h>, but I wouldn't recommend it). Also, you
probably want to use err(), not errx(), and *always* compile with -Wall
-Wextra, and unless you're going to run gdb on your program, -O2 (which
enables additional code analysis)
DES
--
Dag-Erling Smørgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86wscuyska.fsf>
