[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/4] scandir: Fix _D_ALLOC_NAMLEN() on OS/2 kLIBC
From: |
KO Myung-Hun |
Subject: |
[PATCH 4/4] scandir: Fix _D_ALLOC_NAMLEN() on OS/2 kLIBC |
Date: |
Thu, 1 Dec 2016 19:52:46 +0900 |
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.
---
lib/scandir.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/scandir.c b/lib/scandir.c
index 9da342d..a41ef1a 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -36,7 +36,15 @@
# 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
--
2.9.2
- [PATCH 0/4] OS/2 patches, KO Myung-Hun, 2016/12/01
- [PATCH 2/4] relocatable: Fix that /@unixroot prefix is not working on OS/2 kLIBC, KO Myung-Hun, 2016/12/01
- [PATCH 1/4] sys_socket: typedef sa_family_t correctly on OS/2 kLIBC, KO Myung-Hun, 2016/12/01
- [PATCH 3/4] alphasort, scandir: Port to OS/2 kLIBC, KO Myung-Hun, 2016/12/01
- [PATCH 4/4] scandir: Fix _D_ALLOC_NAMLEN() on OS/2 kLIBC,
KO Myung-Hun <=
- Re: [PATCH 0/4] OS/2 patches, Pádraig Brady, 2016/12/01