github.com/nikandfor/tlog@v0.21.5-0.20231108111739-3ef89426a96d/rotated/ctime_darwin.go (about)

     1  package rotated
     2  
     3  import (
     4  	"io/fs"
     5  	"syscall"
     6  	"time"
     7  )
     8  
     9  func fileCtime(fstat func(string) (fs.FileInfo, error), name string, now time.Time) time.Time {
    10  	inf, err := fstat(name)
    11  	if err != nil {
    12  		return now
    13  	}
    14  
    15  	return ctime(inf, now)
    16  }
    17  
    18  func ctime(inf fs.FileInfo, now time.Time) time.Time {
    19  	stat, ok := inf.Sys().(*syscall.Stat_t)
    20  	if !ok {
    21  		return now
    22  	}
    23  
    24  	return time.Unix(stat.Ctimespec.Unix())
    25  }