]> Savannah Git Hosting - gnulib.git/commitdiff
scandir: Fix _D_ALLOC_NAMLEN() on OS/2 kLIBC
authorKO Myung-Hun <komh78@gmail.com>
Thu, 1 Dec 2016 10:52:46 +0000 (19:52 +0900)
committerPádraig Brady <P@draigBrady.com>
Thu, 1 Dec 2016 11:36:57 +0000 (11:36 +0000)
On OS/2 kLIBC, d_name is not the last field of struct dirent. So
copying struct dirent according to the size calculated based on d_name
blows the fields after d_name up.

The correct way is to allocate the whole size of struct dirent.

* lib/scandir.c (_D_ALLOC_NAMLEN): Consider the fields after d_name on
OS/2 kLIBC.

ChangeLog
lib/scandir.c

index 432be6f1396e0a12f0ac3bf2199ad2333fc1e6e7..451d3a3821498dbc229a18abe91e3c593f5fc148 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-01  KO Myung-Hun  <komh78@gmail.com>
+
+       scandir: Fix _D_ALLOC_NAMLEN() on OS/2 kLIBC
+       * lib/scandir.c (_D_ALLOC_NAMLEN): Consider the fields after d_name on
+       OS/2 kLIBC.
+
 2016-12-01  KO Myung-Hun  <komh78@gmail.com>
 
        alphasort, scandir: Port to OS/2 kLIBC
index 9da342d8bafaf1f0217488f6d5a88a2715824699..a41ef1ad3e1ec1db0161220521ac067dbf6cf098 100644 (file)
 # define _D_EXACT_NAMLEN(d) strlen ((d)->d_name)
 #endif
 #ifndef _D_ALLOC_NAMLEN
-# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
+# ifndef __KLIBC__
+#  define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
+# else
+/* On OS/2 kLIBC, d_name is not the last field of struct dirent. See
+   <http://trac.netlabs.org/libc/browser/branches/libc-0.6/src/emx/include/sys/dirent.h#L68>.  */
+#  include <stddef.h>
+#  define _D_ALLOC_NAMLEN(d) (sizeof (struct dirent) - \
+                              offsetof (struct dirent, d_name))
+# endif
 #endif
 
 #if _LIBC