# std.fs.path.dirname: return null when input path is root · gitcafe/zig

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

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

Visibility: public

Requested revision: 7d0c461b77890847899548cc69a701bcb0a3a6a6

Requested commit: 7d0c461b77890847899548cc69a701bcb0a3a6a6

Commit: 7d0c461b77890847899548cc69a701bcb0a3a6a6

Tree: f2704a3ef8a5836fddfc74887a50a3197a9da7e4

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
std.fs.path.dirname: return null when input path is root

This intentionally diverges from the unix dirname command, as well as
Python and Node.js standard libraries, which all have this edge case
return the input path, unmodified. This is a footgun, and nobody should
have ever done it this way.

Even the man page contradicts the behavior. It says:
"strip last component from file name". Now consider, if you
remove the last item from an array of length 1, then you
have now an array of length 0. After you strip the last component, there
should be no components remaining. Clearly, returning the input parameter
unmodified in this case does not match the documented behavior. This is
my justification for taking a stand on this API design.

closes #6746
closes #6727
closes #6584
closes #6592
closes #6602

```

## Parents

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

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