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

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

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

Visibility: public

Requested revision: bf03ae7acc2e8478958e46b2e418fcf29aa99128

Requested commit: bf03ae7acc2e8478958e46b2e418fcf29aa99128

Commit: bf03ae7acc2e8478958e46b2e418fcf29aa99128

Tree: ba03bad3ffa9d79677a2c46860b54c6046bb25ec

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

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

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