A NOTE has been added to this issue. ====================================================================== https://www.austingroupbugs.net/view.php?id=1931 ====================================================================== Reported By: dag-erling Assigned To: ====================================================================== Project: 1003.1(2024)/Issue8 Issue ID: 1931 Category: System Interfaces Type: Clarification Requested Severity: Editorial Priority: normal Status: New Name: Dag-Erling Smørgrav Organization: User Reference: Section: System Interfaces Page Number: 614 Line Number: 21757-21763, 21770-21772 Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2025-06-21 10:16 UTC Last Modified: 2025-07-17 16:12 UTC ====================================================================== Summary: Behavior of scandir() when no entries are selected ======================================================================
---------------------------------------------------------------------- (0007222) geoffclare (manager) - 2025-07-17 16:12 https://www.austingroupbugs.net/view.php?id=1931#c7222 ---------------------------------------------------------------------- Change lines 21757-21763 from: <blockquote>The <i>scandir</i>( ) function shall scan the directory <i>dir</i>, calling the function referenced by <i>sel</i> on each directory entry. Entries for which the function referenced by <i>sel</i> returns non-zero shall be stored in strings allocated as if by a call to <i>malloc</i>( ), and sorted as if by a call to <i>qsort</i>( ) with the comparison function <i>compar</i>, except that <i>compar</i> need not provide total ordering. The strings are collected in array <i>namelist</i> which shall be allocated as if by a call to <i>malloc</i>( ). If <i>sel</i> is a null pointer, all entries shall be selected. If the comparison function <i>compar</i> does not provide total ordering, the order in which the directory entries are stored is unspecified.</blockquote> to: <blockquote>The <i>scandir</i>( ) function shall scan the directory <i>dir</i>, calling the function referenced by <i>sel</i> on each directory entry. Entries for which the function referenced by <i>sel</i> returns non-zero shall be stored in <b>dirent</b> structures allocated as if by a call to <i>malloc</i>( ), and sorted as if by a call to <i>qsort</i>( ) with the comparison function <i>compar</i>, except that <i>compar</i> need not provide total ordering. The <b>dirent</b> structures are collected in the array pointed to by <i>namelist</i> which shall be allocated as if by a call to <i>malloc</i>( ) if at least one entry is selected by <i>sel</i>; if no entries are selected, it is unspecified whether the array is allocated as if by a call to <i>malloc</i> or the value pointed to by <i>namelist</i> is set to a null pointer. If <i>sel</i> is a null pointer, all entries shall be selected. If the comparison function <i>compar</i> does not provide total ordering, the order in which the directory entries are stored is unspecified.</blockquote> Change the example lines 21799-21815 to:<blockquote><pre> #include <dirent.h> #include <stdio.h> #include <stdlib.h> ... struct dirent **files; int i,n; n = scandir(".", &files, NULL, alphasort); if (n < 0) perror("scandir"); else { for (i = 0; i < n; i++) { printf("%s\n", files[i]->d_name); free(files[i]); } } if (files) free(files); ... </pre></blockquote> Page 615 lines 21826-21828, change: <blockquote>For functions that allocate memory as if by <i>malloc</i>( ), the application should release such memory when it is no longer required by a call to <i>free</i>( ). For <i>scandir</i>( ), this is <i>namelist</i> (including all of the individual strings in <i>namelist</i>).</blockquote> to: <blockquote>For functions that allocate memory as if by <i>malloc</i>( ), the application should deallocate such memory when it is no longer required by a call to <i>free</i>( ). For <i>scandir</i>( ), this is the array pointed to by <i>namelist</i> (including all of the individual <b>dirent</b> structures in the array).</blockquote> Issue History Date Modified Username Field Change ====================================================================== 2025-06-21 10:16 dag-erling New Issue 2025-06-21 10:18 dag-erling Note Added: 0007205 2025-06-24 09:23 geoffclare Project Issue 8 drafts => 1003.1(2024)/Issue8 2025-07-17 16:12 geoffclare Note Added: 0007222 ======================================================================