A new user interface for you! Read more...

File cleanup.patch of Package bam

diff --git a/src/support.c b/src/support.c
index 0c4aa3e..dae01cc 100644
--- a/src/support.c
+++ b/src/support.c
@@ -298,7 +298,7 @@
 #endif
 
 /* disable D_TYPE_HACK if we don't have support for it */
-#if !defined(DT_DIR) || !defined(DT_UNKNOWN)
+#if !defined(_DIRENT_HAVE_D_TYPE) || !defined(DT_DIR) || !defined(DT_UNKNOWN)
 	#undef D_TYPE_HACK
 #endif
 
@@ -312,50 +312,42 @@
 		
 		if(*path == 0) /* special case for current directory */
 		{
-			dir = opendir(".");
 			startpoint = buffer;
+			strcpy(buffer, ".");
 		}
 		else
 		{
-			dir = opendir(path);
-
 			/* get starting point and append a slash */
 			strcpy(buffer, path);
 			startpoint = buffer + strlen(buffer);
-			*startpoint = '/';
-			startpoint++;		
+			*(startpoint++) = '/';
+			*startpoint = 0;
 		}
 		
+		dir = opendir(buffer);
 		if(!dir)
 			return;
 		
 		while((entry = readdir(dir)) != NULL)
 		{
+			int isdir;
+			int have_d_type = 0;
 			/* make the path absolute */
 			strcpy(startpoint, entry->d_name);
 #ifdef D_TYPE_HACK
-			/* call the callback */
-			if(entry->d_type == DT_UNKNOWN)
+			if(entry->d_type != DT_UNKNOWN)
 			{
+				have_d_type = 1;
+				isdir = (entry->d_type == DT_DIR);
+			}
+#endif
+			if(!have_d_type) {
 				/* do stat to obtain if it's a directory or not */
 				stat(buffer, &info);
-				if(S_ISDIR(info.st_mode))
-					callback(buffer, 1, user);
-				else
-					callback(buffer, 0, user);
+				isdir = S_ISDIR(info.st_mode);
 			}
-			else if(entry->d_type == DT_DIR)
-				callback(buffer, 1, user);
-			else
-				callback(buffer, 0, user);
-#else
-			/* do stat to obtain if it's a directory or not */
-			stat(buffer, &info);
-			if(S_ISDIR(info.st_mode))
-				callback(buffer, 1, user);
-			else
-				callback(buffer, 0, user);
-#endif
+			/* call the callback */
+			callback(buffer, isdir, user);
 		}
 		
 		closedir(dir);