stat st_birthtim(espec)

Phil Budne
Mon Oct 19 06:06:06 GMT 2020

While checking if an OSS project of mine (
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 <>
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

More information about the Cygwin mailing list