Просмотр исходного кода

libcompat: Handle scandir function arguments being NULL

Guillem Jover лет назад: 18
Родитель
Сommit
dc1e8a195c
2 измененных файлов с 8 добавлено и 2 удалено
  1. 5 0
      ChangeLog
  2. 3 2
      libcompat/scandir.c

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+2008-09-14  Guillem Jover  <guillem@debian.org>
+
+	* libcompat/scandir.c (scandir): Handle case when filter and cmp
+	function arguments are NULL.
+
 2008-09-14  Guillem Jover  <guillem@debian.org>
 
 	* libcompat/compat.h (scandir): Rename arguments from select to

+ 3 - 2
libcompat/scandir.c

@@ -47,7 +47,7 @@ scandir(const char *dir, struct dirent ***namelist,
 		return -1;
 
 	while ((e = readdir(d)) != NULL) {
-		if (!filter(e))
+		if (filter != NULL && !filter(e))
 			continue;
 
 		m = malloc(sizeof(struct dirent) + strlen(e->d_name));
@@ -68,7 +68,8 @@ scandir(const char *dir, struct dirent ***namelist,
 	}
 	(*namelist)[used] = NULL;
 
-	qsort(*namelist, used, sizeof(struct dirent *), cmp);
+	if (cmp != NULL)
+		qsort(*namelist, used, sizeof(struct dirent *), cmp);
 
 	return used;
 }