About making libc remove function POSIX-compliant
Théo Beaudet
theobeaudet@gmail.com
Sat Sep 4 19:43:59 GMT 2021
Hi
This email is about the `int remove(const char *path)` function found
in `stdio.h` not being correct according to the POSIX standard and
thus breaking libstdc++ and libc++ (and possibly others, but I checked
these two) C++17's std::filesystem::remove (and by extension
std::filesystem::remove_all) function that rely on it, as it can only
remove files and not directories.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/remove.html
states that
> If path does not name a directory, remove(path) shall be equivalent to unlink(path).
> If path names a directory, remove(path) shall be equivalent to rmdir(path).
Currently, the function `remove`/`_remove_r` found at `newlib / libc /
stdio / remove.c` calls `_unlink_r`, and only that.
I spent some time searching using the git web view on the
sourceware.org website, and while `_unlink_r` is provided by `newlib /
libc / reent / unlinkr.c` and depends on the libgloss library to be
fully implemented (from what I see), there is no _rmdir_r equivalent.
And so I wanted to ask this question:
If it is desirable to be POSIX-compliant, where should this
modification go? In newlib directly as a modification to `remove`,
requiring a new function everywhere (namely `rmdir`) ? Or in libgloss
as a change to the unlink implementation for platforms that want it?
Finally, who would want to make this change?
--
Thanks.
Théo B.
More information about the Newlib
mailing list