Module Name:    src
Committed By:   dogcow
Date:           Mon Aug 16 10:00:56 UTC 2010

Modified Files:
        src/libexec/httpd: dir-index-bozo.c

Log Message:
readdir -> scandir and requisite changes, so that bozohttpd now sorts
directory listings.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/libexec/httpd/dir-index-bozo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/dir-index-bozo.c
diff -u src/libexec/httpd/dir-index-bozo.c:1.8 src/libexec/httpd/dir-index-bozo.c:1.9
--- src/libexec/httpd/dir-index-bozo.c:1.8	Mon May 10 03:37:45 2010
+++ src/libexec/httpd/dir-index-bozo.c	Mon Aug 16 10:00:56 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir-index-bozo.c,v 1.8 2010/05/10 03:37:45 mrg Exp $	*/
+/*	$NetBSD: dir-index-bozo.c,v 1.9 2010/08/16 10:00:56 dogcow Exp $	*/
 
 /*	$eterna: dir-index-bozo.c,v 1.17 2010/05/10 02:51:28 mrg Exp $	*/
 
@@ -61,13 +61,13 @@
 {
 	bozohttpd_t *httpd = request->hr_httpd;
 	struct stat sb;
-	struct dirent *de;
+	struct dirent **de;
 	struct tm *tm;
 	DIR *dp;
 	char buf[MAXPATHLEN];
 	char spacebuf[48];
 	char *file = NULL;
-	int l, i;
+	int l, j, i;
 
 	if (!isindex || !httpd->dir_indexing)
 		return 0;
@@ -123,11 +123,11 @@
 	directory_hr(httpd);
 	bozo_printf(httpd, "<pre>");
 
-	while ((de = readdir(dp)) != NULL) {
+	for (j = scandir(dirname, &de, NULL, alphasort); j--; de++) {
 		int nostat = 0;
-		char *name = de->d_name;
+		char *name = (*de)->d_name;
 
-		if (strcmp(name, ".") == 0 || 
+		if (strcmp(name, ".") == 0 ||
 		    (strcmp(name, "..") != 0 &&
 		     httpd->hide_dots && name[0] == '.'))
 			continue;
@@ -183,15 +183,18 @@
 		bozo_printf(httpd, "\r\n");
 	}
 
+	if (de)
+		free(de);
 	closedir(dp);
 	bozo_printf(httpd, "</pre>");
 	directory_hr(httpd);
 	bozo_printf(httpd, "</body></html>\r\n\r\n");
 	bozo_flush(httpd, stdout);
-	
+
 done:
 	if (file)
 		free(file);
 	return 1;
 }
 #endif /* NO_DIRINDEX_SUPPORT */
+

Reply via email to