]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #978: store nanosec field
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 1 May 2021 04:22:13 +0000 (09:52 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 1 May 2021 04:46:26 +0000 (10:16 +0530)
src/nnn.c

index 8da93d3299d334e61b480a21badfaf11635a9b91..bcedcf514964c231de36902e97edd00d7965f46d 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -249,6 +249,7 @@ typedef unsigned long long ulong_t;
 typedef struct entry {
        char *name;
        time_t t;
+       uint_t t_nsec; /* Enough to hold nanosec */
        off_t size;
        blkcnt_t blocks; /* number of 512B blocks allocated */
        mode_t mode;
@@ -2515,6 +2516,11 @@ static int entrycmp(const void *va, const void *vb)
                        return 1;
                if (pb->t < pa->t)
                        return -1;
+               /* If sec matches, comare nsec */
+               if (pb->t_nsec > pa->t_nsec)
+                       return 1;
+               if (pb->t_nsec < pa->t_nsec)
+                       return -1;
        } else if (cfg.sizeorder) {
                if (pb->size > pa->size)
                        return 1;
@@ -5096,9 +5102,29 @@ static int dentfill(char *path, struct entry **ppdents)
                off += dentp->nlen;
 
                /* Copy other fields */
-               dentp->t = ((cfg.timetype == T_MOD)
-                               ? sb.st_mtime
-                               : ((cfg.timetype == T_ACCESS) ? sb.st_atime : sb.st_ctime));
+               if (cfg.timetype == T_MOD) {
+                       dentp->t = sb.st_mtime;
+#ifdef __APPLE__
+                       dentp->t_nsec = (uint_t)sb.st_mtimespec.tv_nsec;
+#else
+                       dentp->t_nsec = (uint_t)sb.st_mtim.tv_nsec;
+#endif
+               } else if (cfg.timetype == T_ACCESS) {
+                       dentp->t = sb.st_atime;
+#ifdef __APPLE__
+                       dentp->t_nsec = (uint_t)sb.st_atimespec.tv_nsec;
+#else
+                       dentp->t_nsec = (uint_t)sb.st_atim.tv_nsec;
+#endif
+               } else {
+                       dentp->t = sb.st_ctime;
+#ifdef __APPLE__
+                       dentp->t_nsec = (uint_t)sb.st_ctimespec.tv_nsec;
+#else
+                       dentp->t_nsec = (uint_t)sb.st_ctim.tv_nsec;
+#endif
+               }
+
 #if !(defined(__sun) || defined(__HAIKU__))
                if (!flags && dp->d_type == DT_LNK) {
                         /* Do not add sizes for links */