feat(新增平台): 支持darwin平台

This commit is contained in:
2026-01-07 10:53:29 +08:00
parent be86327699
commit a2375ceaf6
3 changed files with 56 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 xiaoqidun
Copyright (c) 2021-2026 肖其顿 (XIAO QI DUN)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,4 +1,4 @@
// +build !windows
//go:build !windows && !darwin
package setft

54
setft_darwin.go Normal file
View File

@@ -0,0 +1,54 @@
package setft
import (
"syscall"
"time"
"unsafe"
)
const (
_ATTR_BIT_MAP_COUNT = 5
_ATTR_CMN_CRTIME = 0x00000200
_ATTR_CMN_MODTIME = 0x00000400
_ATTR_CMN_ACCTIME = 0x00001000
_SYS_SETATTRLIST = 221
)
type _AttrList struct {
bitmapCount uint16
reserved uint16
commonAttr uint32
volAttr uint32
dirAttr uint32
fileAttr uint32
forkattr uint32
}
func SetFileTime(path string, atime, ctime, mtime time.Time) (err error) {
p, err := syscall.BytePtrFromString(path)
if err != nil {
return err
}
attrList := _AttrList{
bitmapCount: _ATTR_BIT_MAP_COUNT,
commonAttr: _ATTR_CMN_CRTIME | _ATTR_CMN_MODTIME | _ATTR_CMN_ACCTIME,
}
times := []syscall.Timespec{
syscall.NsecToTimespec(ctime.UnixNano()),
syscall.NsecToTimespec(mtime.UnixNano()),
syscall.NsecToTimespec(atime.UnixNano()),
}
_, _, errno := syscall.Syscall6(
_SYS_SETATTRLIST,
uintptr(unsafe.Pointer(p)),
uintptr(unsafe.Pointer(&attrList)),
uintptr(unsafe.Pointer(&times[0])),
uintptr(len(times)*int(unsafe.Sizeof(times[0]))),
0,
0,
)
if errno != 0 {
return errno
}
return nil
}