This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: struct stat.h with nanosecond resolution


Ulrich Drepper <drepper@redhat.com> writes:

> Andreas Jaeger wrote:
>
>> I'm not sure that this is right either.  Uli, what is the proper way
>> to handle <time.h>?  I currently don't see a clean solution for
>> this:-(
>
> We have something similar in a number of places.
>
> <time.h> unconditionally defines struct __timespec.  The member names
> are namespace-protected as well.
>
> If __need_timespec is defined or <time.h> is included normally three new
> macros are defined:
>
> #define timespec __timespec
> #define tv_sec __tv_sec
> #define tv_nsec __tv_nsec
>
>
> The only acceptable alternative is to not use a struct at all in
> POSIX/Unix mode.  Use the "inlined" time_t/long fields.

Looking at how fileutils handles this, I think we should go with your
first proposal.

Here's what I'm currently testing,
Andreas

============================================================
Index: time/time.h
--- time/time.h	28 Aug 2002 08:01:10 -0000	1.66
+++ time/time.h	3 Dec 2002 09:02:50 -0000
@@ -79,6 +79,14 @@ __END_NAMESPACE_STD
 __USING_NAMESPACE_STD(time_t)
 #endif
 
+/* POSIX.1b structure for a time value.  This is like a `struct timeval' but
+   has nanoseconds instead of microseconds.  */
+struct __timespec
+  {
+    __time_t __tv_sec;		/* Seconds.  */
+    long int __tv_nsec;		/* Nanoseconds.  */
+  };
+
 #endif /* time_t not defined and <time.h> or need time_t.  */
 #undef	__need_time_t
 
@@ -106,18 +114,13 @@ typedef __timer_t timer_t;
 #endif /* timer_t not defined and <time.h> or need timer_t.  */
 #undef	__need_timer_t
 
-
 #if !defined __timespec_defined && \
     ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_timespec)
 # define __timespec_defined	1
 
-/* POSIX.1b structure for a time value.  This is like a `struct timeval' but
-   has nanoseconds instead of microseconds.  */
-struct timespec
-  {
-    __time_t tv_sec;		/* Seconds.  */
-    long int tv_nsec;		/* Nanoseconds.  */
-  };
+# define timespec __timespec
+# define tv_sec __tv_sec
+# define tv_nsec __tv_nsec
 
 #endif /* timespec not defined and <time.h> or need timespec.  */
 #undef	__need_timespec
============================================================
Index: sysdeps/unix/sysv/linux/bits/stat.h
--- sysdeps/unix/sysv/linux/bits/stat.h	8 Feb 2002 07:48:10 -0000	1.15
+++ sysdeps/unix/sysv/linux/bits/stat.h	3 Dec 2002 09:02:50 -0000
@@ -60,12 +60,9 @@ struct stat
 #else
     __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
 #endif
-    __time_t st_atime;			/* Time of last access.  */
-    unsigned long int __unused1;
-    __time_t st_mtime;			/* Time of last modification.  */
-    unsigned long int __unused2;
-    __time_t st_ctime;			/* Time of last status change.  */
-    unsigned long int __unused3;
+    struct __timespec st_atim;		/* Time of last access.  */
+    struct __timespec st_mtim;		/* Time of last modification.  */
+    struct __timespec st_ctim;		/* Time of last status change.  */
 #ifndef __USE_FILE_OFFSET64
     unsigned long int __unused4;
     unsigned long int __unused5;
@@ -74,6 +71,10 @@ struct stat
 #endif
   };
 
+#define st_atime st_atim.__tv_sec	/* Backward compatibility.  */
+#define st_mtime st_mtim.__tv_sec
+#define st_ctime st_ctim.__tv_sec
+
 #ifdef __USE_LARGEFILE64
 struct stat64
   {
@@ -91,12 +92,9 @@ struct stat64
     __blksize_t st_blksize;		/* Optimal block size for I/O.  */
 
     __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
-    __time_t st_atime;			/* Time of last access.  */
-    unsigned long int __unused1;
-    __time_t st_mtime;			/* Time of last modification.  */
-    unsigned long int __unused2;
-    __time_t st_ctime;			/* Time of last status change.  */
-    unsigned long int __unused3;
+    struct __timespec st_atim;		/* Time of last access.  */
+    struct __timespec st_mtim;		/* Time of last modification.  */
+    struct __timespec st_ctim;		/* Time of last status change.  */
     __ino64_t st_ino;			/* File serial number.		*/
   };
 #endif

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]