add DIRSIZ macro for internal use
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 17 Jan 1989 08:42:37 +0000 (00:42 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 17 Jan 1989 08:42:37 +0000 (00:42 -0800)
SCCS-vsn: lib/libc/gen/scandir.c 5.5

usr/src/lib/libc/gen/scandir.c

index 032544a..d892258 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)scandir.c  5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)scandir.c  5.5 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /*
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -30,6 +30,16 @@ static char sccsid[] = "@(#)scandir.c        5.4 (Berkeley) %G%";
 #include <sys/stat.h>
 #include <dirent.h>
 
 #include <sys/stat.h>
 #include <dirent.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
+#define DIRSIZ(dp) \
+    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
+
 scandir(dirname, namelist, select, dcomp)
        char *dirname;
        struct dirent *(*namelist[]);
 scandir(dirname, namelist, select, dcomp)
        char *dirname;
        struct dirent *(*namelist[]);