This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2] Use latest FreeBSD definition for DIRSIZ


newlib/ChangeLog
2013-03-28  Sebastian Huber <sebastian.huber@embedded-brains.de>

	* libc/posix/scandir.c (DIRENT_NAMELEN): New define.
	(DIRSIZ): Use latest FreeBSD definition.  Use DIRENT_NAMELEN.
---
 newlib/libc/posix/scandir.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/newlib/libc/posix/scandir.c b/newlib/libc/posix/scandir.c
index 96a66de..4fddfb5 100644
--- a/newlib/libc/posix/scandir.c
+++ b/newlib/libc/posix/scandir.c
@@ -42,26 +42,29 @@ static char sccsid[] = "@(#)scandir.c	5.10 (Berkeley) 2/23/91";
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <stddef.h>
 #include <dirent.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/lock.h>
 
-/*
- * The DIRSIZ macro gives the minimum record length which will hold
- * the directory entry.  This requires the amount of space in struct dirent
- * without the d_name field, plus enough space for the name with a terminating
- * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
- */
-#undef DIRSIZ
 #ifdef _DIRENT_HAVE_D_NAMLEN
-#define DIRSIZ(dp) \
-    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
+#define DIRENT_NAMELEN(dp) ((dp)->d_namlen)
 #else
-#define DIRSIZ(dp) \
-    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + ((strlen((dp)->d_name)+1 + 3) &~ 3))
+#define DIRENT_NAMELEN(dp) (strlen((dp)->d_name))
 #endif
 
+/*
+ * The DIRSIZ macro is the minimum record length which will hold the directory
+ * entry.  This requires the amount of space in struct dirent without the
+ * d_name field, plus enough space for the name and a terminating nul byte
+ * (dp->d_namlen + 1), rounded up to a 4 byte boundary.
+ */
+#undef DIRSIZ
+#define DIRSIZ(dp)							\
+	((sizeof(struct dirent) - sizeof(dp)->d_name) +			\
+	    ((DIRENT_NAMELEN(dp) + 1 + 3) &~ 3))
+
 #ifndef __P
 #define __P(args) ()
 #endif
-- 
1.7.7


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]