[syslinux] [PATCH 2/3] COM32 API: restructure DIR

Gene Cumm gene.cumm at gmail.com
Thu Mar 5 18:46:00 PST 2009


From: Gene Cumm <gene.cumm at gmail.com>

COM32 API: restructure DIR to include a dirent to eliminate the need
for alloc()/free() of dirents

Signed-off-by: Gene Cumm <gene.cumm at gmail.com>

---

Counted incorrectly.  Depends on previous patches.


diff --git a/com32/include/dirent.h b/com32/include/dirent.h
index 5161828..a544050 100644
--- a/com32/include/dirent.h
+++ b/com32/include/dirent.h
@@ -29,6 +29,7 @@ typedef struct {
 	uint16_t	dd_fd;
 	size_t		dd_sect;
 	char		dd_name[NAME_MAX + 1];	/* directory */
+	struct dirent	dd_de;
 } DIR;

 __extern DIR *opendir(const char *);
diff --git a/com32/lib/readdir.c b/com32/lib/readdir.c
index 353b61b..c6d991c 100644
--- a/com32/lib/readdir.c
+++ b/com32/lib/readdir.c
@@ -33,21 +33,16 @@ struct dirent *readdir(DIR *dir)
 		/* Don't do this as we won't be able to rewind.
 		dir->dd_fd = regs.esi.w[0];	/* Shouldn't be needed? */
 		if ((!(regs.eflags.l & EFLAGS_CF)) && (regs.esi.w[0] != 0)) {
-			newde = calloc(1, sizeof(newde));
-			if (newde != NULL) {
-				strcpy(newde->d_name, __com32.cs_bounce);
-				newde->d_mode = regs.edx.w[0];
-				newde->d_type = (newde->d_mode & S_IFMT) >> 12;
-				newde->d_size = regs.eax.l;
-				newde->d_ino = regs.ebx.l;
-				dir->dd_stat = 1;
-			} else {
-				dir->dd_stat = -2;
-				errno = ENOMEM;
-			}
+			newde = dir->dd_de;
+			strcpy(newde->d_name, __com32.cs_bounce);
+			newde->d_mode = regs.edx.w[0];
+			newde->d_type = (newde->d_mode & S_IFMT) >> 12;
+			newde->d_size = regs.eax.l;
+			newde->d_ino = regs.ebx.l;
+			dir->dd_stat = 1;
 		} else {
 			dir->dd_stat = -1;
-			errno = EIO;	/* Is this the right number? */
+			errno = EIO;	/* FIXME: Is this the right number? */
 		}
 	} else {
 		errno = EBADF;




More information about the Syslinux mailing list