public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* stat st_birthtim(espec)
@ 2020-10-19  6:06 Phil Budne
  2020-10-19 12:01 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Budne @ 2020-10-19  6:06 UTC (permalink / raw)
  To: cygwin

While checking if an OSS project of mine (www.snobol4.org/csnobol4)
compiled cleanly under Cygwin, I was happy to discover that struct
stat contains file birth time as on various BSD based systems.

BUT, I was unhappy to find out that MacOS 10.15 and Cygwin 3.1.7 have
non-overlapping definitions for birth time information.

FreeBSD 12, NetBSD 9, and OSX 10.15 all have a "timespec" available as
"st_birthtimespec", but Cygwin does not.

On FreeBSD, NetBSD, and Cygwin the actual member of struct stat is
st_birthtim, but on OSX, the member is st_birthtimespec, and there is
no define for st_birthtim.

A st_birthtimespec define in cygwin/stat.h would make it easier to
write portable code.

Snips from .../stat.h, possible patch below:

==== /*      $NetBSD: stat.h,v 1.69 2019/09/15 23:55:22 christos Exp $       */
struct    timespec st_birthtim; /* time of creation */
#define st_birthtime            st_birthtim.tv_sec
#define st_birthtimespec        st_birthtim
#define st_birthtimensec        st_birthtimespec.tv_nsec

==== * $FreeBSD: releng/12.1/sys/sys/stat.h 326023 2017-11-20 19:43:44Z pfg $
struct timespec st_birthtim;    /* time of file creation */
#define st_birthtime            st_birthtim.tv_sec
#define st_birthtimespec        st_birthtim
NO st_birthtimensec

==== CYGWIN_NT-10.0 WinDev2005Eval 3.1.7(0.340/5/3) 2020-08-22 17:48 x86_64 Cygwin
timestruc_t   st_birthtim;
#define st_birthtime st_birthtim.tv_sec
NO st_birthtimespec
NO st_birthtimensec

==== OSX 10.15
NO st_birthtim
struct timespec st_birthtimespec;       /* time of file creation(birth) */
#define st_birthtime st_birthtimespec.tv_sec
NO st_birthtimensec

================================================================

From f07900b9a8e9e56b04fac493f86196079bcf9001 Mon Sep 17 00:00:00 2001
From: phil <phil@ultimate.com>
Date: Mon, 19 Oct 2020 01:33:15 -0400
Subject: [PATCH] add st_birthtimespec define

---
 winsup/cygwin/include/cygwin/stat.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/winsup/cygwin/include/cygwin/stat.h b/winsup/cygwin/include/cygwin/stat.h
index 0e489d7a9..a5adf29f3 100644
--- a/winsup/cygwin/include/cygwin/stat.h
+++ b/winsup/cygwin/include/cygwin/stat.h
@@ -65,6 +65,7 @@ extern int lstat64 (const char *__restrict file_name,
 #define st_mtime st_mtim.tv_sec
 #define st_ctime st_ctim.tv_sec
 #define st_birthtime st_birthtim.tv_sec
+#define st_birthtimespec st_birthtim
 
 /* POSIX IPC objects are not implemented as distinct file types, so the
    below macros have to return 0.  The expression is supposed to catch
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: stat st_birthtim(espec)
  2020-10-19  6:06 stat st_birthtim(espec) Phil Budne
@ 2020-10-19 12:01 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-10-19 12:01 UTC (permalink / raw)
  To: cygwin

On Oct 19 02:06, Phil Budne wrote:
> While checking if an OSS project of mine (www.snobol4.org/csnobol4)
> compiled cleanly under Cygwin, I was happy to discover that struct
> stat contains file birth time as on various BSD based systems.
> 
> BUT, I was unhappy to find out that MacOS 10.15 and Cygwin 3.1.7 have
> non-overlapping definitions for birth time information.
> 
> FreeBSD 12, NetBSD 9, and OSX 10.15 all have a "timespec" available as
> "st_birthtimespec", but Cygwin does not.
> 
> On FreeBSD, NetBSD, and Cygwin the actual member of struct stat is
> st_birthtim, but on OSX, the member is st_birthtimespec, and there is
> no define for st_birthtim.
> 
> A st_birthtimespec define in cygwin/stat.h would make it easier to
> write portable code.

Well, portable code should use the st_atim/st_mtim/st_ctim members
directly and not use st_birthtim at all.

For the headers we're usually looking for Linux compatibility in the
first place and if that's any indication, we should add all the
st_XYZtimensec members, but *only* if __USE_XOPEN2K8 is defined
(equivalent _XOPEN_SOURCE >= 700 for Cygwin/newlib)

GLibc does not provide any st_XYZtimespec definitions, though.  I don't
think it really makes a lot of sense to add those with portability in
mind.


Corinna

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-19 12:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-19  6:06 stat st_birthtim(espec) Phil Budne
2020-10-19 12:01 ` Corinna Vinschen

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 read-only IMAP folder(s) and NNTP newsgroup(s).