From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10027 invoked from network); 1 Nov 2007 15:40:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 1 Nov 2007 15:40:31 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 67144 invoked from network); 1 Nov 2007 15:40:25 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Nov 2007 15:40:25 -0000 Received: (qmail 12091 invoked by alias); 1 Nov 2007 15:40:22 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24050 Received: (qmail 12072 invoked from network); 1 Nov 2007 15:40:21 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 1 Nov 2007 15:40:21 -0000 Received: (qmail 66827 invoked from network); 1 Nov 2007 15:40:21 -0000 Received: from esacom89-ext.esoc.esa.int (HELO esacom89-int.esoc.esa.int) (131.176.86.4) by a.mx.sunsite.dk with SMTP; 1 Nov 2007 15:40:13 -0000 Received: from esacom53.esoc.esa.int (131-176-86-254.esoc.esa.int [131.176.86.254]) by esacom89-int.esoc.esa.int (8.13.3/8.13.3/ESA-External-v4.0) with ESMTP id lA1FeA5B008822 for ; Thu, 1 Nov 2007 15:40:11 GMT Received: from dcle12.dev.esoc.esa.int (dcle12.dev.esoc.esa.int [131.176.58.71]) by esacom53.esoc.esa.int (8.12.10/8.12.10/ESA-Internal-v3.2) with ESMTP id lA1Fe5Yk024113 for ; Thu, 1 Nov 2007 15:40:05 GMT Received: from dcle12 (localhost [127.0.0.1]) by dcle12.dev.esoc.esa.int (8.13.8+Sun/8.13.8) with ESMTP id lA1Fe1Iw022004 for ; Thu, 1 Nov 2007 15:40:03 GMT From: Oliver Kiddle To: Zsh workers Subject: PATCH: support for nanosecond timestamps Date: Thu, 01 Nov 2007 16:40:01 +0100 Message-ID: <22003.1193931601@dcle12> 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