--- dir-index-bozo.c.orig 2021-11-23 01:19:24.436756510 +0900 +++ dir-index-bozo.c 2022-02-08 17:44:40.429573964 +0900 @@ -122,7 +122,9 @@ bozo_printf(httpd, "\r\n" - "\r\n" + "\r\n" + "\r\n" + "\r\n" "\r\n"); - bozo_printf(httpd, "Index of %s\r\n", + "\r\n" + "\r\n"); + bozo_printf(httpd, "%s\r\n", printname); - bozo_printf(httpd, "

Index of %s

\r\n", + bozo_printf(httpd, "

%s

\r\n", printname); bozo_printf(httpd, - "\r\n\r\n" - "
NameLast modifiedSize\r\n" + "\r\n" "\r\n"); for (j = k = scandir(dirpath, &de, NULL, alphasort), deo = de; @@ -162,35 +164,61 @@ htmlname = bozo_escape_html(httpd, name); if (htmlname == NULL) htmlname = name; - bozo_printf(httpd, "
"); if (strcmp(name, "..") == 0) { - bozo_printf(httpd, ""); - bozo_printf(httpd, "Parent Directory"); - } else if (!nostat && S_ISDIR(sb.st_mode)) { - bozo_printf(httpd, "", urlname); + bozo_printf(httpd, ""); + } else { unsigned long long len; + double d; - strftime(buf, sizeof buf, "%d-%b-%Y %R", gmtime(&sb.st_mtime)); + strftime(buf, sizeof buf, "", gmtime(&sb.st_mtime)); bozo_printf(httpd, "%s", buf); - - len = ((unsigned long long)sb.st_size + 1023) / 1024; - bozo_printf(httpd, "%llukB", len); + if (S_ISDIR(sb.st_mode)) { + bozo_printf(httpd, "%s", "-"); + } else if (sb.st_size > 1024) { + if (sb.st_size < 10240) { + d = (double)sb.st_size / 1024; + bozo_printf(httpd, "%.1lfK", d); + } else if (sb.st_size > 1048576) { + if (sb.st_size < 10485760) { + d = (double)sb.st_size / 1048576; + bozo_printf(httpd, "%.1lfM", d); + } else { + len = (unsigned long long)sb.st_size / 1048576; + bozo_printf(httpd, "%lluM", len); + } + } else { + len = (unsigned long long)sb.st_size / 1024; + bozo_printf(httpd, "%lluK", len); + } + } else { + len = (unsigned long long)sb.st_size; + bozo_printf(httpd, "%lluB", len); + } } bozo_printf(httpd, "\r\n"); } @@ -199,7 +227,13 @@ while (k--) free(deo[k]); free(deo); - bozo_printf(httpd, "
\r\n"); + bozo_printf(httpd, "
\r\n"); + if (strcmp(printname, "files/") == 0) { + bozo_printf(httpd, "\r\n"); + } else { + bozo_printf(httpd, "\r\n"); + + } if (httpd->dir_readme != NULL) { if (httpd->dir_readme[0] == '/') snprintf(buf, sizeof buf, "%s", httpd->dir_readme);