Introduction
Introduction Statistics Contact Development Disclaimer Help
Add size and date/time to dir listing. - geomyidae - A small C-based gopherd.
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit 7f132215d36985b9a17a338fb5bb451a09116303
parent f9779c166558b9b0e70754fa9ce6026e5c10fffa
Author: Christoph Lohmann <[email protected]>
Date: Fri, 12 Jun 2020 21:07:14 +0200
Add size and date/time to dir listing.
This applies and old patch by Evil_Bob. Dank u!
Diffstat:
M handlr.c | 9 +++++++--
M ind.c | 35 +++++++++++++++++++++++++++++…
M ind.h | 2 ++
M main.c | 2 +-
4 files changed, 45 insertions(+), 3 deletions(-)
---
diff --git a/handlr.c b/handlr.c
@@ -66,8 +66,13 @@ handledir(int sock, char *path, char *port, char *base, char…
if (stat(file, &st) >= 0 && S_ISDIR(st.st_mode))
type = gettype("index.gph");
e = file + strlen(base);
- ret = dprintf(sock, "%c%s\t%s\t%s\t%s\r\n", *type->typ…
- dirent[i]->d_name, e, ohost, port);
+ ret = dprintf(sock,
+ "%c%-50.50s %10s %16s\t%s\t%s\t%s\r\n",
+ *type->type,
+ dirent[i]->d_name,
+ humansize(st.st_size),
+ humantime(&(st.st_mtim.tv_sec)),
+ e, ohost, port);
free(file);
free(dirent[i]);
}
diff --git a/ind.c b/ind.c
@@ -10,6 +10,8 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
+#include <time.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -513,3 +515,36 @@ setcgienviron(char *file, char *path, char *port, char *ba…
}
+char *
+humansize(off_t n)
+{
+ static char buf[16];
+ const char postfixes[] = "BKMGTPE";
+ double size;
+ int i = 0;
+
+ for (size = n; size >= 1024 && i < strlen(postfixes); i++)
+ size /= 1024;
+
+ if (!i) {
+ snprintf(buf, sizeof(buf), "%ju%c", (uintmax_t)n,
+ postfixes[i]);
+ } else {
+ snprintf(buf, sizeof(buf), "%.1f%c", size, postfixes[i]);
+ }
+
+ return buf;
+}
+
+char *
+humantime(const time_t *clock)
+{
+ static char buf[32];
+ struct tm *tm;
+
+ tm = localtime(clock);
+ strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M %Z", tm);
+
+ return buf;
+}
+
diff --git a/ind.h b/ind.h
@@ -50,6 +50,8 @@ char *reverselookup(char *host);
void setcgienviron(char *file, char *path, char *port, char *base,
char *args, char *sear, char *ohost, char *chost,
int istls);
+char *humansize(off_t n);
+char *humantime(const time_t *clock);
#endif
diff --git a/main.c b/main.c
@@ -202,7 +202,7 @@ handlerequest(int sock, char *req, int rlen, char *base, ch…
}
if (recvb[0] != '/' || strstr(recvb, "..")){
- dprintf(sock, selinval);
+ dprintf(sock, "%s", selinval);
return;
}
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.