# std.Io.Threaded: reinstate fchmodat fallback · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/e41342af83022202c6e413cd84c12b41f19c681a)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: e41342af83022202c6e413cd84c12b41f19c681a

Requested commit: e41342af83022202c6e413cd84c12b41f19c681a

Commit: e41342af83022202c6e413cd84c12b41f19c681a

Tree: 622264e2ef6a094923e7adb290ec717af90d644c

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
std.Io.Threaded: reinstate fchmodat fallback

Stephen Gregoratto (original author of the fallback) says:

I read through both libcs again to compare:

Musl:
- `stat` path. Check error.
- If path is a symlink, return `OPNOTSUPP`.
- `openat` path as `O_PATH|O_NOFOLLOW|O_CLOEXEC`. Return `OPNOTSUPP` if we got `ELOOP`.
- Build procfs filename.
- `stat` procfs file.
- If procfs file is a symlink, return `OPNOTSUPP`.
- close path fd.

Glibc:
- open path as `O_PATH|O_NOFOLLOW|O_CLOEXEC`.
- fstatat path fd.
- If path is a symlink, return `OPNOTSUPP`.
- Build procfs filename.
- chmod procfs filename. Return `OPNOTSUPP` if we got `ENOENT`.
- close path fd.

I prefer glibc since you open the path first, which avoids a possible
TOCTOU race.

```

## Parents

- [64de4a7371e3851dddf39c608d08d480395bb0ab](https://git.cafe/gitcafe/zig/commit/64de4a7371e3851dddf39c608d08d480395bb0ab?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/e41342af83022202c6e413cd84c12b41f19c681a?format=markdown)
