source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: work around lack of d_namlen and ALIGN/ALIGNBYTES on Linux
@ 2014-08-11  3:19 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-08-11  3:19 UTC (permalink / raw)
  To: source

Log Message:
-----------
work around lack of d_namlen and ALIGN/ALIGNBYTES on Linux

Modified Files:
--------------
    mdocml:
        Makefile
        compat_fts.c
        configure

Added Files:
-----------
    mdocml:
        test-dirent-namlen.c

Revision Data
-------------
Index: compat_fts.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/compat_fts.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lcompat_fts.c -Lcompat_fts.c -u -p -r1.1 -r1.2
--- compat_fts.c
+++ compat_fts.c
@@ -404,7 +404,7 @@ fts_build(FTS *sp)
 	FTSENT *cur, *tail;
 	DIR *dirp;
 	void *oldaddr;
-	size_t len, maxlen;
+	size_t dlen, len, maxlen;
 	int nitems, cderrno, descend, level, nlinks, nostat, doadjust;
 	int saved_errno;
 	char *cp;
@@ -489,11 +489,17 @@ fts_build(FTS *sp)
 		if (ISDOT(dp->d_name))
 			continue;
 
-		if (!(p = fts_alloc(sp, dp->d_name, (size_t)dp->d_namlen)))
+#ifdef HAVE_DIRENT_NAMLEN
+		dlen = dp->d_namlen;
+#else
+		dlen = strlen(dp->d_name);
+#endif
+
+		if (!(p = fts_alloc(sp, dp->d_name, dlen)))
 			goto mem1;
-		if (dp->d_namlen >= maxlen) {	/* include space for NUL */
+		if (dlen >= maxlen) {	/* include space for NUL */
 			oldaddr = sp->fts_path;
-			if (fts_palloc(sp, dp->d_namlen +len + 1)) {
+			if (fts_palloc(sp, dlen + len + 1)) {
 				/*
 				 * No more memory for path or structures.  Save
 				 * errno, free up the current structure and the
@@ -520,7 +526,7 @@ mem1:				saved_errno = errno;
 
 		p->fts_level = level;
 		p->fts_parent = sp->fts_cur;
-		p->fts_pathlen = len + dp->d_namlen;
+		p->fts_pathlen = len + dlen;
 		if (p->fts_pathlen < len) {
 			/*
 			 * If we wrap, free up the current structure and
@@ -680,23 +686,18 @@ fts_alloc(FTS *sp, const char *name, siz
 	FTSENT *p;
 	size_t len;
 
-	/*
-	 * The file name is a variable length array and no stat structure is
-	 * necessary if the user has set the nostat bit.  Allocate the FTSENT
-	 * structure, the file name and the stat structure in one chunk, but
-	 * be careful that the stat structure is reasonably aligned.  Since the
-	 * fts_name field is declared to be of size 1, the fts_name pointer is
-	 * namelen + 2 before the first possible address of the stat structure.
-	 */
 	len = sizeof(FTSENT) + namelen;
-	len += sizeof(struct stat) + ALIGNBYTES;
 	if ((p = calloc(1, len)) == NULL)
 		return (NULL);
 
 	p->fts_path = sp->fts_path;
 	p->fts_namelen = namelen;
 	p->fts_instr = FTS_NOINSTR;
-	p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2);
+	p->fts_statp = malloc(sizeof(struct stat));
+	if (p->fts_statp == NULL) {
+		free(p);
+		return (NULL);
+	}
 	memcpy(p->fts_name, name, namelen);
 
 	return (p);
Index: configure
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/configure,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lconfigure -Lconfigure -u -p -r1.9 -r1.10
--- configure
+++ configure
@@ -32,6 +32,7 @@ runtest() {
 cat config.h.pre
 echo
 echo "#define VERSION \"${VERSION}\""
+runtest dirent-namlen DIRENT_NAMLEN
 runtest fgetln FGETLN
 runtest fts FTS
 runtest getsubopt GETSUBOPT
Index: Makefile
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v
retrieving revision 1.437
retrieving revision 1.438
diff -LMakefile -LMakefile -u -p -r1.437 -r1.438
--- Makefile
+++ Makefile
@@ -115,7 +115,9 @@ CGIBIN		 = man.cgi
 
 DBLIB		+= -lsqlite3
 
-TESTSRCS	 = test-fgetln.c \
+TESTSRCS	 = test-dirent-namlen.c \
+		   test-fgetln.c \
+		   test-fts.c \
 		   test-getsubopt.c \
 		   test-mmap.c \
 		   test-ohash.c \
--- /dev/null
+++ test-dirent-namlen.c
@@ -0,0 +1,10 @@
+#include <sys/types.h>
+#include <dirent.h>
+
+int
+main(void)
+{
+	struct dirent	 entry;
+
+	return (sizeof(entry.d_namlen) == 0);
+}
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-08-11  3:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-11  3:19 mdocml: work around lack of d_namlen and ALIGN/ALIGNBYTES on Linux schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).