Index: kmz_2_tri.c
===================================================================
--- kmz_2_tri.c	(revision 1106)
+++ kmz_2_tri.c	(revision 1107)
@@ -46,6 +46,7 @@
 	struct stat stb;
 	long arraysz;
 	DIR *dirp;
+	int n;
 
 	if ((dirp = opendir(dirname)) == NULL)
 		return(-1);
@@ -54,7 +55,11 @@
 	 * estimate the array size by taking the size of the directory file
 	 * and dividing it by a multiple of the minimum size entry.
 	 */
-	arraysz = (stb.st_size / 24);
+
+    n=0;
+    while ((d=readdir(dirp)) !=NULL) n++;
+    rewinddir(dirp);
+	arraysz = (n);
 	names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
 	if (names == NULL)
 		return(-1);