This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH v2] Use latest FreeBSD definition for DIRSIZ
- From: Sebastian Huber <sebastian dot huber at embedded-brains dot de>
- To: newlib at sourceware dot org
- Cc: Sebastian Huber <sebastian dot huber at embedded-brains dot de>
- Date: Thu, 28 Mar 2013 15:15:50 +0100
- Subject: [PATCH v2] Use latest FreeBSD definition for DIRSIZ
- References: <1364468303-7319-1-git-send-email-sebastian dot huber at embedded-brains dot de>
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