From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@sunsite.dk>
Subject: PATCH: support for nanosecond timestamps
Date: Thu, 01 Nov 2007 16:40:01 +0100 [thread overview]
Message-ID: <22003.1193931601@dcle12> (raw)
The following patch adds support in zsh for high resolution timestamps
on systems that support them. This affects the following:
-N (file unread) conditional flag
-ot (older than) and -nt (newer than) conditional flags
o/O (ordered) glob qualifiers with a/m/c sort specifiers (including
with - glob qualifier to act on symlinks)
Does anyone know of any other features that could make use of this? I
have grepped for mtime/atime in the source and the other references are
for checking for history/utmp/mail file updates and the stat module.
I've noticed occasionally in the past that things like (om) and -nt
haven't done as I wanted because operations are simply too fast so I'm
hoping this will be useful. Hopefully it doesn't break anyone's
scripts.
Oliver
PS. Does curses_keys.h need to be added to .cvsignore perhaps: cvs
shouldn't be listing it in the diff output below.
? Src/Modules/curses_keys.h
Index: configure.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/configure.ac,v
retrieving revision 1.76
diff -u -r1.76 configure.ac
--- configure.ac 29 Oct 2007 10:30:06 -0000 1.76
+++ configure.ac 1 Nov 2007 15:15:29 -0000
@@ -977,6 +977,17 @@
AC_DEFINE(sigset_t, unsigned int)
fi
+dnl check structures for high resolution timestamps
+AC_CHECK_MEMBERS([struct stat.st_atim.tv_nsec,
+ struct stat.st_atimespec.tv_nsec,
+ struct stat.st_atimensec,
+ struct stat.st_mtim.tv_nsec,
+ struct stat.st_mtimespec.tv_nsec,
+ struct stat.st_mtimensec,
+ struct stat.st_ctim.tv_nsec,
+ struct stat.st_ctimespec.tv_nsec,
+ struct stat.st_ctimensec])
+
dnl Check for struct timezone since some old SCO versions do not define it
zsh_TYPE_EXISTS([
#ifdef HAVE_SYS_TIME_H
Index: Src/cond.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/cond.c,v
retrieving revision 1.13
diff -u -r1.13 cond.c
--- Src/cond.c 24 Jul 2007 09:36:48 -0000 1.13
+++ Src/cond.c 1 Nov 2007 15:15:30 -0000
@@ -344,19 +344,39 @@
case 'G':
return !((st = getstat(left)) && st->st_gid == getegid());
case 'N':
+#if defined(GET_ST_MTIME_NSEC) && defined(GET_ST_ATIME_NSEC)
+ if (!(st = getstat(left)))
+ return 1;
+ return (st->st_atime == st->st_mtime) ?
+ GET_ST_ATIME_NSEC(*st) > GET_ST_MTIME_NSEC(*st) :
+ st->st_atime > st->st_mtime;
+#else
return !((st = getstat(left)) && st->st_atime <= st->st_mtime);
+#endif
case 't':
return !isatty(mathevali(left));
case COND_NT:
case COND_OT:
{
time_t a;
+#ifdef GET_ST_MTIME_NSEC
+ long nsecs;
+#endif
if (!(st = getstat(left)))
return 1;
a = st->st_mtime;
+#ifdef GET_ST_MTIME_NSEC
+ nsecs = GET_ST_MTIME_NSEC(*st);
+#endif
if (!(st = getstat(right)))
return 1;
+#ifdef GET_ST_MTIME_NSEC
+ if (a == st->st_mtime) {
+ return !((ctype == COND_NT) ? nsecs > GET_ST_MTIME_NSEC(*st) :
+ nsecs < GET_ST_MTIME_NSEC(*st));
+ }
+#endif
return !((ctype == COND_NT) ? a > st->st_mtime : a < st->st_mtime);
}
case COND_EF:
Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.60
diff -u -r1.60 glob.c
--- Src/glob.c 22 Oct 2007 09:27:05 -0000 1.60
+++ Src/glob.c 1 Nov 2007 15:15:39 -0000
@@ -52,6 +52,18 @@
long _mtime;
long _ctime;
long _links;
+#ifdef GET_ST_ATIME_NSEC
+ long ansec;
+ long _ansec;
+#endif
+#ifdef GET_ST_MTIME_NSEC
+ long mnsec;
+ long _mnsec;
+#endif
+#ifdef GET_ST_CTIME_NSEC
+ long cnsec;
+ long _cnsec;
+#endif
};
#define GS_NAME 1
@@ -373,6 +385,15 @@
matchptr->mtime = buf.st_mtime;
matchptr->ctime = buf.st_ctime;
matchptr->links = buf.st_nlink;
+#ifdef GET_ST_ATIME_NSEC
+ matchptr->ansec = GET_ST_ATIME_NSEC(buf);
+#endif
+#ifdef GET_ST_MTIME_NSEC
+ matchptr->mnsec = GET_ST_MTIME_NSEC(buf);
+#endif
+#ifdef GET_ST_CTIME_NSEC
+ matchptr->cnsec = GET_ST_CTIME_NSEC(buf);
+#endif
}
if (statted & 2) {
matchptr->_size = buf2.st_size;
@@ -380,6 +401,15 @@
matchptr->_mtime = buf2.st_mtime;
matchptr->_ctime = buf2.st_ctime;
matchptr->_links = buf2.st_nlink;
+#ifdef GET_ST_ATIME_NSEC
+ matchptr->_ansec = GET_ST_ATIME_NSEC(buf);
+#endif
+#ifdef GET_ST_MTIME_NSEC
+ matchptr->_mnsec = GET_ST_MTIME_NSEC(buf);
+#endif
+#ifdef GET_ST_CTIME_NSEC
+ matchptr->_cnsec = GET_ST_CTIME_NSEC(buf);
+#endif
}
matchptr++;
@@ -885,12 +915,24 @@
break;
case GS_ATIME:
r = a->atime - b->atime;
+#ifdef GET_ST_ATIME_NSEC
+ if (!r)
+ r = a->ansec - b->ansec;
+#endif
break;
case GS_MTIME:
r = a->mtime - b->mtime;
+#ifdef GET_ST_MTIME_NSEC
+ if (!r)
+ r = a->mnsec - b->mnsec;
+#endif
break;
case GS_CTIME:
r = a->ctime - b->ctime;
+#ifdef GET_ST_CTIME_NSEC
+ if (!r)
+ r = a->cnsec - b->cnsec;
+#endif
break;
case GS_LINKS:
r = b->links - a->links;
@@ -900,12 +942,24 @@
break;
case GS__ATIME:
r = a->_atime - b->_atime;
+#ifdef GET_ST_ATIME_NSEC
+ if (!r)
+ r = a->_ansec - b->_ansec;
+#endif
break;
case GS__MTIME:
r = a->_mtime - b->_mtime;
+#ifdef GET_ST_MTIME_NSEC
+ if (!r)
+ r = a->_mnsec - b->_mnsec;
+#endif
break;
case GS__CTIME:
r = a->_ctime - b->_ctime;
+#ifdef GET_ST_CTIME_NSEC
+ if (!r)
+ r = a->_cnsec - b->_cnsec;
+#endif
break;
case GS__LINKS:
r = b->_links - a->_links;
Index: Src/system.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/system.h,v
retrieving revision 1.47
diff -u -r1.47 system.h
--- Src/system.h 11 Oct 2007 20:32:00 -0000 1.47
+++ Src/system.h 1 Nov 2007 15:15:40 -0000
@@ -805,3 +805,24 @@
# define USE_GETPWUID
#endif
+#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
+# define GET_ST_ATIME_NSEC(st) (st).st_atim.tv_nsec
+#elif HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
+# define GET_ST_ATIME_NSEC(st) (st).st_atimespec.tv_nsec
+#elif HAVE_STRUCT_STAT_ST_ATIMENSEC
+# define GET_ST_ATIME_NSEC(st) (st).st_atimensec
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+# define GET_ST_MTIME_NSEC(st) (st).st_mtim.tv_nsec
+#elif HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
+# define GET_ST_MTIME_NSEC(st) (st).st_mtimespec.tv_nsec
+#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
+# define GET_ST_MTIME_NSEC(st) (st).st_mtimensec
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC
+# define GET_ST_CTIME_NSEC(st) (st).st_ctim.tv_nsec
+#elif HAVE_STRUCT_STAT_ST_CTIMESPEC_TV_NSEC
+# define GET_ST_CTIME_NSEC(st) (st).st_ctimespec.tv_nsec
+#elif HAVE_STRUCT_STAT_ST_CTIMENSEC
+# define GET_ST_CTIME_NSEC(st) (st).st_ctimensec
+#endif
next reply other threads:[~2007-11-01 15:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-01 15:40 Oliver Kiddle [this message]
2007-11-01 15:50 ` Stephane Chazelas
2007-11-01 17:37 ` Oliver Kiddle
2007-11-01 18:28 ` Stephane Chazelas
2007-11-04 17:14 ` Peter Stephenson
2007-11-05 14:45 ` Oliver Kiddle
2007-11-05 15:26 ` Stephane Chazelas
2007-11-05 15:31 ` Peter Stephenson
2007-11-04 16:46 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=22003.1193931601@dcle12 \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).