commit 4f52d9af701703e1957e307d51947a9c0f162490 from: Omar Polo date: Sun Jan 16 18:08:32 2022 UTC ftp: print mtime in ls output Print the time (HH:MM) of the last edit is within the last 6 months, the year otherwise; match what `ls -lahF' does on OpenBSD, and I think it's cool. commit - 6470594ec92ba41f32f1e7932d0a4d23382c50d9 commit + 4f52d9af701703e1957e307d51947a9c0f162490 blob - af109599289d7c0999782727e900bc126bf7f7b2 blob + 10f7a14c5ef6fc388a79ea1c2142b96b826f6987 --- kamiftp/ftp.c +++ kamiftp/ftp.c @@ -1219,15 +1219,20 @@ static void cmd_ls(int argc, const char **argv) { struct np_stat st; + time_t now, mtime; + struct tm *tm; uint64_t off = 0; uint32_t len; - char fmt[FMT_SCALED_STRSIZE], *errstr; + const char *timfmt; + char fmt[FMT_SCALED_STRSIZE], tim[13], *errstr; if (argc != 0) { printf("ls don't take arguments (yet)\n"); return; } + now = time(NULL); + if ((errstr = dup_fid(pwdfid, 1)) != NULL) { printf(".: %s\n", errstr); free(errstr); @@ -1260,7 +1265,18 @@ cmd_ls(int argc, const char **argv) if (fmt_scaled(st.length, fmt) == -1) strlcpy(fmt, "xxx", sizeof(fmt)); + + mtime = st.mtime; + + if (now > mtime && (now - mtime) < 365/2 * 24 * 12 * 60) + timfmt = "%b %e %R"; + else + timfmt = "%b %e %Y"; + if ((tm = localtime(&mtime)) == NULL || + strftime(tim, sizeof(tim), timfmt, tm) == 0) + strlcpy(tim, "unknown", sizeof(tim)); + if (st.qid.type & QTDIR) printf("d"); else @@ -1268,7 +1284,7 @@ cmd_ls(int argc, const char **argv) printf("%s", pp_perm(st.mode >> 6)); printf("%s", pp_perm(st.mode >> 3)); printf("%s", pp_perm(st.mode)); - printf(" %8s %s%s\n", fmt, st.name, + printf(" %8s %12s %s%s\n", fmt, tim, st.name, st.qid.type & QTDIR ? "/" : ""); free(st.name);