Date: Sun, 3 Jan 2010 01:04:51 GMT From: Kevin Barry <ta0kira@users.berlios.de> To: freebsd-gnats-submit@FreeBSD.org Subject: standards/142255: scandir prototype in dirent.h isn't compliant with POSIX 2008 Message-ID: <201001030104.o0314pUt008675@www.freebsd.org> Resent-Message-ID: <201001030110.o031A2Tb006542@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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 <dirent.h> 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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001030104.o0314pUt008675>