[openssh-commits] [openssh] 01/01: portability for sftp globbed ls sort by mtime

git+noreply at mindrot.org git+noreply at mindrot.org
Sat Jun 10 23:42:40 AEST 2017


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit bcd1485075aa72ba9418003f5cc27af2b049c51b
Author: Damien Miller <djm at mindrot.org>
Date:   Sat Jun 10 23:41:25 2017 +1000

    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.
---
 configure.ac |  2 ++
 defines.h    |  7 +++++++
 includes.h   |  3 +++
 sftp.c       | 10 ++++++++--
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 46f7d495..18079acb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3814,6 +3814,8 @@ OSSH_CHECK_HEADER_FOR_FIELD([ut_time], [utmpx.h], [HAVE_TIME_IN_UTMPX])
 OSSH_CHECK_HEADER_FOR_FIELD([ut_tv], [utmpx.h], [HAVE_TV_IN_UTMPX])
 
 AC_CHECK_MEMBERS([struct stat.st_blksize])
+AC_CHECK_MEMBERS([struct stat.st_mtim])
+AC_CHECK_MEMBERS([struct stat.st_mtime])
 AC_CHECK_MEMBERS([struct passwd.pw_gecos, struct passwd.pw_class,
 struct passwd.pw_change, struct passwd.pw_expire],
 [], [], [[
diff --git a/defines.h b/defines.h
index 0420a7e8..f1662edc 100644
--- a/defines.h
+++ b/defines.h
@@ -519,6 +519,13 @@ struct winsize {
 }
 #endif
 
+#ifndef timespeccmp
+#define timespeccmp(tsp, usp, cmp)					\
+	(((tsp)->tv_sec == (usp)->tv_sec) ?				\
+	    ((tsp)->tv_nsec cmp (usp)->tv_nsec) :			\
+	    ((tsp)->tv_sec cmp (usp)->tv_sec))
+#endif
+
 #ifndef __P
 # define __P(x) x
 #endif
diff --git a/includes.h b/includes.h
index 497a038b..0fd71792 100644
--- a/includes.h
+++ b/includes.h
@@ -93,6 +93,9 @@
 #ifdef HAVE_SYS_SYSMACROS_H
 # include <sys/sysmacros.h> /* For MIN, MAX, etc */
 #endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h> /* for timespeccmp if present */
+#endif
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h> /* for MAP_ANONYMOUS */
 #endif
diff --git a/sftp.c b/sftp.c
index 001c6ed2..67110f73 100644
--- a/sftp.c
+++ b/sftp.c
@@ -894,9 +894,15 @@ sglob_comp(const void *aa, const void *bb)
 #define NCMP(a,b) (a == b ? 0 : (a < b ? 1 : -1))
 	if (sort_flag & LS_NAME_SORT)
 		return (rmul * strcmp(ap, bp));
-	else if (sort_flag & LS_TIME_SORT)
+	else if (sort_flag & LS_TIME_SORT) {
+#if defined(HAVE_STRUCT_STAT_ST_MTIM)
 		return (rmul * timespeccmp(&as->st_mtim, &bs->st_mtim, <));
-	else if (sort_flag & LS_SIZE_SORT)
+#elif defined(HAVE_STRUCT_STAT_ST_MTIME)
+		return (rmul * NCMP(as->st_mtime, bs->st_mtime));
+#else
+	return rmul * 1;
+#endif
+	} else if (sort_flag & LS_SIZE_SORT)
 		return (rmul * NCMP(as->st_size, bs->st_size));
 
 	fatal("Unknown ls sort type");

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list