浏览代码

unix: add Lutimes

Add Lutimes wrapping UtimesNanoAt.

Updates golang/go#30487

Change-Id: Ic5bb3b4d88be5806522eaef9bd9b8b0f5c1c8f42
Reviewed-on: https://go-review.googlesource.com/c/sys/+/164662
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Tobias Klauser 6 年之前
父节点
当前提交
30e92a19ae
共有 1 个文件被更改,包括 19 次插入0 次删除
  1. 19 0
      unix/syscall_unix.go

+ 19 - 0
unix/syscall_unix.go

@@ -395,3 +395,22 @@ func SetNonblock(fd int, nonblocking bool) (err error) {
 func Exec(argv0 string, argv []string, envv []string) error {
 	return syscall.Exec(argv0, argv, envv)
 }
+
+// Lutimes sets the access and modification times tv on path. If path refers to
+// a symlink, it is not dereferenced and the timestamps are set on the symlink.
+// If tv is nil, the access and modification times are set to the current time.
+// Otherwise tv must contain exactly 2 elements, with access time as the first
+// element and modification time as the second element.
+func Lutimes(path string, tv []Timeval) error {
+	if tv == nil {
+		return UtimesNanoAt(AT_FDCWD, path, nil, AT_SYMLINK_NOFOLLOW)
+	}
+	if len(tv) != 2 {
+		return EINVAL
+	}
+	ts := []Timespec{
+		NsecToTimespec(TimevalToNsec(tv[0])),
+		NsecToTimespec(TimevalToNsec(tv[1])),
+	}
+	return UtimesNanoAt(AT_FDCWD, path, ts, AT_SYMLINK_NOFOLLOW)
+}