From owner-freebsd-standards@FreeBSD.ORG Sun Jan 3 01:10:02 2010 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 778BF10656A3 for ; Sun, 3 Jan 2010 01:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 3AAE78FC22 for ; Sun, 3 Jan 2010 01:10:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o031A2UN006543 for ; Sun, 3 Jan 2010 01:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o031A2Tb006542; Sun, 3 Jan 2010 01:10:02 GMT (envelope-from gnats) Resent-Date: Sun, 3 Jan 2010 01:10:02 GMT Resent-Message-Id: <201001030110.o031A2Tb006542@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Kevin Barry Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60DC11065676 for ; Sun, 3 Jan 2010 01:04:52 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 4F6408FC1A for ; Sun, 3 Jan 2010 01:04:52 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0314pLL008677 for ; Sun, 3 Jan 2010 01:04:51 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o0314pUt008675; Sun, 3 Jan 2010 01:04:51 GMT (envelope-from nobody) Message-Id: <201001030104.o0314pUt008675@www.freebsd.org> Date: Sun, 3 Jan 2010 01:04:51 GMT From: Kevin Barry To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: standards/142255: scandir prototype in dirent.h isn't compliant with POSIX 2008 X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jan 2010 01:10:02 -0000 >Number: 142255 >Category: standards >Synopsis: scandir prototype in dirent.h isn't compliant with POSIX 2008 >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Jan 03 01:10:01 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Kevin Barry >Release: 8.0-RELEASE >Organization: >Environment: FreeBSD kpbarry.student.cwru.edu 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:02:08 UTC 2009 root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: The POSIX standard declares 'scandir' as follows, copied directly: int scandir(const char *dir, struct dirent ***namelist, int (*sel)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); The problem in FreeBSD is the 'sel' argument, which is a pointer to a function taking a 'struct dirent *' without the 'const'. This is a problem when trying to write POSIX-portable code. In C I only receive a warning when trying to pass a function pointer of the correct type, however, in C++ this is an error. An argument cast isn't the solution because I still need my code to work in Linux; therefore, I've had to separate the call to 'scandir' in a C file, separate from the C++ code. Another solution is to C-cast a pointer to 'scandir' and dereference it, which I might consider. Thanks! Kevin Barry >How-To-Repeat: #include static int sel(const struct dirent*) { return 1; } int main() { scandir(0, 0, &sel, 0); } Compile the above with g++. >Fix: Change the prototype of 'scandir' in dirent.h. >Release-Note: >Audit-Trail: >Unformatted: