From owner-freebsd-questions@freebsd.org Tue Apr 20 18:21:48 2021 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7F3F85E28DE for ; Tue, 20 Apr 2021 18:21:48 +0000 (UTC) (envelope-from freebsd-doc@fjl.co.uk) Received: from bs1.fjl.org.uk (bs1.fjl.org.uk [84.45.41.196]) by mx1.freebsd.org (Postfix) with ESMTP id 4FPsTR59gMz3KP5 for ; Tue, 20 Apr 2021 18:21:47 +0000 (UTC) (envelope-from freebsd-doc@fjl.co.uk) Received: from [192.168.1.181] (host86-173-148-147.range86-173.btcentralplus.com [86.173.148.147]) (authenticated bits=0) by bs1.fjl.org.uk (8.14.4/8.14.4) with ESMTP id 13KILjuJ002127 for ; Tue, 20 Apr 2021 19:21:45 +0100 (BST) (envelope-from freebsd-doc@fjl.co.uk) To: freebsd-questions@freebsd.org From: Frank Leonhardt Subject: Bug in current versions of /usr/include/dirent.h ? Message-ID: Date: Tue, 20 Apr 2021 19:21:45 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-Rspamd-Queue-Id: 4FPsTR59gMz3KP5 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of freebsd-doc@fjl.co.uk designates 84.45.41.196 as permitted sender) smtp.mailfrom=freebsd-doc@fjl.co.uk X-Spamd-Result: default: False [-2.39 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:84.45.41.196]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; DMARC_NA(0.00)[fjl.co.uk]; RCVD_IN_DNSWL_MED(-0.20)[84.45.41.196:from]; NEURAL_HAM_SHORT(-0.99)[-0.993]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:25577, ipnet:84.45.0.0/17, country:GB]; MAILMAN_DEST(0.00)[freebsd-questions]; RECEIVED_SPAMHAUS_PBL(0.00)[86.173.148.147:received] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Apr 2021 18:21:48 -0000 Weird one this! I'm currently using 12.2, but this appears to be a problem in recent versions. In FreeBSD 8, dirent.h contains the following: /* structure describing an open directory. */ typedef struct _dirdesc {         int     dd_fd;          /* file descriptor associated with directory */         long    dd_loc;         /* offset in current buffer */         long    dd_size;        /* amount of data returned by getdirentries */         char    *dd_buf;        /* data buffer */         int     dd_len;         /* size of data buffer */         long    dd_seek;        /* magic cookie returned by getdirentries */         long    dd_rewind;      /* magic cookie for rewinding */         int     dd_flags;       /* flags for readdir */         struct pthread_mutex    *dd_lock;       /* lock */         struct _telldir *dd_td; /* telldir position recording */ } DIR; Nothing wrong there. It's the structure used by opendir() etc in the standard C library. In 12.2 we've not got a structure definition, but instead a forward reference at line 87. DIR is typedefed on the following line. However, nowhere can I find where this forward reference is later resolved - meaning it isn't. Has anyone got the faintest idea what's going on? I've had a look through the source code to see where a DIR structure is used, and it may as well be a (void *) - it's used as a handle returned by opendir() in subsequent operations but never dereferenced. And before anyone questions why de-referencing it is necessary - first off, it's always been a published structure so  it's fair game. Secondly, full access to the dd_fd field was handy. If access to this structure is "deprecated" after 40 years, at the very least the handle should have been typedefed into something safer than a forward reference. So what's the sane explanation? Thanks, Frank.