struct stat.h with nanosecond resolution
Andreas Jaeger
aj@suse.de
Tue Dec 3 03:07:00 GMT 2002
Ulrich Drepper <drepper@redhat.com> writes:
> Andreas Jaeger wrote:
>
>> This will not work since it clashes with struct timeval which is
>> defined as:
>
> It just means we'll have to rename the members of timeval as well.
Oh no, it's getting even uglier.
>
>> Do we really need to rename the members of struct __timespec also?
>
> Yes, it's necessary. <sys/stat.h> does not allow any symbols with the
> prefix tv_* to be defined.
And a member is a symbol? Ok, then we have no choice. Here's my
current version. Is my handling of xstatconv correct?
Andreas
============================================================
Index: time/time.h
--- time/time.h 28 Aug 2002 08:01:10 -0000 1.66
+++ time/time.h 3 Dec 2002 10:57:42 -0000
@@ -106,18 +106,26 @@ typedef __timer_t timer_t;
#endif /* timer_t not defined and <time.h> or need timer_t. */
#undef __need_timer_t
+#ifndef ____timespec_defined
+# define ____timespec_defined 1
+/* POSIX.1b structure for a time value. This is like a `struct timeval' but
+ has nanoseconds instead of microseconds. This is an internal name. */
+struct __timespec
+ {
+ __time_t __tv_sec; /* Seconds. */
+ long int __tv_nsec; /* Nanoseconds. */
+ };
+#endif /* ____timespec not defined. */
#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 exported names for POSIX.1b timespec structure. */
+# define timespec __timespec
+# undef tv_sec
+# 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/generic/bits/time.h
--- sysdeps/generic/bits/time.h 18 Oct 2002 20:35:42 -0000 1.8
+++ sysdeps/generic/bits/time.h 3 Dec 2002 10:57:42 -0000
@@ -66,8 +66,11 @@ extern long int __sysconf (int);
microsecond but also has a range of years. */
struct timeval
{
- __time_t tv_sec; /* Seconds. */
+ __time_t __tv_sec; /* Seconds. */
__suseconds_t tv_usec; /* Microseconds. */
};
+/* We need this define for struct timespec. */
+# undef tv_sec
+# define tv_sec __tv_sec
# endif /* struct timeval */
#endif /* need timeval */
============================================================
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 10:57:43 -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
============================================================
Index: sysdeps/unix/sysv/linux/xstatconv.c
--- sysdeps/unix/sysv/linux/xstatconv.c 2 Oct 2002 08:33:46 -0000 1.10
+++ sysdeps/unix/sysv/linux/xstatconv.c 3 Dec 2002 10:57:43 -0000
@@ -60,18 +60,12 @@ xstat_conv (int vers, struct kernel_stat
buf->st_size = kbuf->st_size;
buf->st_blksize = kbuf->st_blksize;
buf->st_blocks = kbuf->st_blocks;
- buf->st_atime = kbuf->st_atime;
-#ifdef _HAVE_STAT___UNUSED1
- buf->__unused1 = 0;
-#endif
- buf->st_mtime = kbuf->st_mtime;
-#ifdef _HAVE_STAT___UNUSED2
- buf->__unused2 = 0;
-#endif
- buf->st_ctime = kbuf->st_ctime;
-#ifdef _HAVE_STAT___UNUSED3
- buf->__unused3 = 0;
-#endif
+ buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+ buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+ buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+ buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+ buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+ buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
#ifdef _HAVE_STAT___UNUSED4
buf->__unused4 = 0;
#endif
@@ -121,18 +115,13 @@ xstat64_conv (int vers, struct kernel_st
buf->st_size = kbuf->st_size;
buf->st_blksize = kbuf->st_blksize;
buf->st_blocks = kbuf->st_blocks;
- buf->st_atime = kbuf->st_atime;
-#ifdef _HAVE_STAT64___UNUSED1
- buf->__unused1 = 0;
-#endif
- buf->st_mtime = kbuf->st_mtime;
-#ifdef _HAVE_STAT64___UNUSED2
- buf->__unused2 = 0;
-#endif
- buf->st_ctime = kbuf->st_ctime;
-#ifdef _HAVE_STAT64___UNUSED3
- buf->__unused3 = 0;
-#endif
+
+ buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+ buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+ buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+ buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+ buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+ buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
#ifdef _HAVE_STAT64___UNUSED4
buf->__unused4 = 0;
#endif
@@ -216,18 +205,12 @@ xstat32_conv (int vers, struct stat64 *k
__set_errno (EOVERFLOW);
return -1;
}
- buf->st_atime = kbuf->st_atime;
-#ifdef _HAVE_STAT___UNUSED1
- buf->__unused1 = 0;
-#endif
- buf->st_mtime = kbuf->st_mtime;
-#ifdef _HAVE_STAT___UNUSED2
- buf->__unused2 = 0;
-#endif
- buf->st_ctime = kbuf->st_ctime;
-#ifdef _HAVE_STAT___UNUSED3
- buf->__unused3 = 0;
-#endif
+ buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+ buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+ buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+ buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+ buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+ buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
#ifdef _HAVE_STAT___UNUSED4
buf->__unused4 = 0;
#endif
============================================================
Index: sysdeps/unix/sysv/linux/kernel_stat.h
--- sysdeps/unix/sysv/linux/kernel_stat.h 12 Aug 2000 04:38:53 -0000 1.4
+++ sysdeps/unix/sysv/linux/kernel_stat.h 3 Dec 2002 10:57:43 -0000
@@ -15,31 +15,19 @@ struct kernel_stat
unsigned long int st_size;
unsigned long int st_blksize;
unsigned long int st_blocks;
- unsigned long int st_atime;
- unsigned long int __unused1;
-#define _HAVE___UNUSED1
- unsigned long int st_mtime;
- unsigned long int __unused2;
-#define _HAVE___UNUSED2
- unsigned long int st_ctime;
- unsigned long int __unused3;
-#define _HAVE___UNUSED3
+ struct __timespec st_atim;
+ struct __timespec st_mtim;
+ struct __timespec st_ctim;
unsigned long int __unused4;
#define _HAVE___UNUSED4
unsigned long int __unused5;
#define _HAVE___UNUSED5
};
-#define _HAVE_STAT___UNUSED1
-#define _HAVE_STAT___UNUSED2
-#define _HAVE_STAT___UNUSED3
#define _HAVE_STAT___UNUSED4
#define _HAVE_STAT___UNUSED5
#define _HAVE_STAT___PAD1
#define _HAVE_STAT___PAD2
-#define _HAVE_STAT64___UNUSED1
-#define _HAVE_STAT64___UNUSED2
-#define _HAVE_STAT64___UNUSED3
#define _HAVE_STAT64___PAD1
#define _HAVE_STAT64___PAD2
#define _HAVE_STAT64___ST_INO
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj
More information about the Libc-alpha
mailing list