From owner-freebsd-amd64@FreeBSD.ORG Sat Jan 17 13:40:14 2009 Return-Path: Delivered-To: amd64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 57C821065672 for ; Sat, 17 Jan 2009 13:40:14 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id 1816C8FC21 for ; Sat, 17 Jan 2009 13:40:14 +0000 (UTC) (envelope-from des@des.no) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 979F06D43F; Sat, 17 Jan 2009 13:23:49 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 7AD5E844EF; Sat, 17 Jan 2009 14:23:49 +0100 (CET) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Garrett Cooper References: <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com> Date: Sat, 17 Jan 2009 14:23:49 +0100 In-Reply-To: <7d6fde3d0901160041n55466290l55f737d274a40895@mail.gmail.com> (Garrett Cooper's message of "Fri, 16 Jan 2009 00:41:37 -0800") Message-ID: <86wscuyska.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: "amd64@freebsd.org" , Hackers freeBSD Subject: Re: Confused by segfault with legitimate call to strerror(3) on amd64 / sysctl(3) setting `odd' errno's X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jan 2009 13:40:14 -0000 Garrett Cooper writes: > #include > #include > #include > #include > #include You should always put your sys includes before your non-sys includes, and in any case, 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 , 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 --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no