summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2017-06-10 23:41:25 +1000
committerDamien Miller <djm@mindrot.org>2017-06-10 23:41:25 +1000
commitbcd1485075aa72ba9418003f5cc27af2b049c51b (patch)
tree122b7024821c2c47b6df71639fe578bf5f571183 /sftp.c
parent072e172f1d302d2a2c6043ecbfb4004406717b96 (diff)
portability for sftp globbed ls sort by mtime
Include replacement timespeccmp() for systems that lack it. Support time_t struct stat->st_mtime in addition to timespec stat->st_mtim, as well as unsorted fallback.
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/sftp.c b/sftp.c
index 001c6ed2d..67110f738 100644
--- a/sftp.c
+++ b/sftp.c
@@ -894,9 +894,15 @@ sglob_comp(const void *aa, const void *bb)
894#define NCMP(a,b) (a == b ? 0 : (a < b ? 1 : -1)) 894#define NCMP(a,b) (a == b ? 0 : (a < b ? 1 : -1))
895 if (sort_flag & LS_NAME_SORT) 895 if (sort_flag & LS_NAME_SORT)
896 return (rmul * strcmp(ap, bp)); 896 return (rmul * strcmp(ap, bp));
897 else if (sort_flag & LS_TIME_SORT) 897 else if (sort_flag & LS_TIME_SORT) {
898#if defined(HAVE_STRUCT_STAT_ST_MTIM)
898 return (rmul * timespeccmp(&as->st_mtim, &bs->st_mtim, <)); 899 return (rmul * timespeccmp(&as->st_mtim, &bs->st_mtim, <));
899 else if (sort_flag & LS_SIZE_SORT) 900#elif defined(HAVE_STRUCT_STAT_ST_MTIME)
901 return (rmul * NCMP(as->st_mtime, bs->st_mtime));
902#else
903 return rmul * 1;
904#endif
905 } else if (sort_flag & LS_SIZE_SORT)
900 return (rmul * NCMP(as->st_size, bs->st_size)); 906 return (rmul * NCMP(as->st_size, bs->st_size));
901 907
902 fatal("Unknown ls sort type"); 908 fatal("Unknown ls sort type");