@@ -705,6 +705,12 @@ static PyStructSequence_Field stat_result_fields[] = {
705705#endif
706706#ifdef HAVE_STRUCT_STAT_ST_FLAGS
707707 {"st_flags" , "user defined flags for file" },
708+ #endif
709+ #ifdef HAVE_STRUCT_STAT_ST_GEN
710+ {"st_gen" , "generation number" },
711+ #endif
712+ #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
713+ {"st_birthtime" , "time of creation" },
708714#endif
709715 {0 }
710716};
@@ -733,6 +739,18 @@ static PyStructSequence_Field stat_result_fields[] = {
733739#define ST_FLAGS_IDX ST_RDEV_IDX
734740#endif
735741
742+ #ifdef HAVE_STRUCT_STAT_ST_GEN
743+ #define ST_GEN_IDX (ST_RDEV_IDX+1)
744+ #else
745+ #define ST_GEN_IDX ST_RDEV_IDX
746+ #endif
747+
748+ #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
749+ #define ST_BIRTHTIME_IDX (ST_GEN_IDX+1)
750+ #else
751+ #define ST_BIRTHTIME_IDX ST_GEN_IDX
752+ #endif
753+
736754static PyStructSequence_Desc stat_result_desc = {
737755 "stat_result" , /* name */
738756 stat_result__doc__ , /* doc */
@@ -877,8 +895,14 @@ _pystat_fromstructstat(STRUCT_STAT st)
877895 ansec = st .st_atim .tv_nsec ;
878896 mnsec = st .st_mtim .tv_nsec ;
879897 cnsec = st .st_ctim .tv_nsec ;
898+ #else
899+ #ifdef HAVE_STAT_TV_NSEC2
900+ ansec = st .st_atimespec .tv_nsec ;
901+ mnsec = st .st_mtimespec .tv_nsec ;
902+ cnsec = st .st_ctimespec .tv_nsec ;
880903#else
881904 ansec = mnsec = cnsec = 0 ;
905+ #endif
882906#endif
883907 fill_time (v , 7 , st .st_atime , ansec );
884908 fill_time (v , 8 , st .st_mtime , mnsec );
@@ -896,6 +920,29 @@ _pystat_fromstructstat(STRUCT_STAT st)
896920 PyStructSequence_SET_ITEM (v , ST_RDEV_IDX ,
897921 PyInt_FromLong ((long )st .st_rdev ));
898922#endif
923+ #ifdef HAVE_STRUCT_STAT_ST_GEN
924+ PyStructSequence_SET_ITEM (v , ST_GEN_IDX ,
925+ PyInt_FromLong ((long )st .st_gen ));
926+ #endif
927+ #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
928+ {
929+ PyObject * val ;
930+ unsigned long bsec ,bnsec ;
931+ bsec = (long )st .st_birthtime ;
932+ #ifdef HAVE_STAT_TV_NSEC2
933+ bnsec = st .st_birthtimespec .tv_nsec ;
934+ #else
935+ bnsec = 0 ;
936+ #endif
937+ if (_stat_float_times ) {
938+ val = PyFloat_FromDouble (bsec + 1e-9 * bnsec );
939+ } else {
940+ val = PyInt_FromLong ((long )bsec );
941+ }
942+ PyStructSequence_SET_ITEM (v , ST_BIRTHTIME_IDX ,
943+ val );
944+ }
945+ #endif
899946#ifdef HAVE_STRUCT_STAT_ST_FLAGS
900947 PyStructSequence_SET_ITEM (v , ST_FLAGS_IDX ,
901948 PyInt_FromLong ((long )st .st_flags ));
0 commit comments