POSIX.1-2024 encourages returning EILSEQ
for filenames with a newline
#21883
Labels
bug
Observed behavior contradicts documented or intended behavior
standard library
This issue involves writing Zig code for the standard library.
POSIX.1-2024
has addedEILSEQ
as an error for most filesystem-related functions with the description:and added a note in the RATIONALE section:
(see mkdir for one example, full list of affected funtions available here and that article also talks more about this change here)
This is an application of "Austin Group Defect 251" (https://www.austingroupbugs.net/view.php?id=251) and is a break from the previous 'file paths are just an arbitrary sequences of bytes (minus NUL)' stance
This is relevant to Zig in a few ways:
EINVAL
if the underlying filesystem doesn't support the filename (e.g.|
onvfat
), which Zig doesn't handle correctly yeterror.InvalidUtf8
because WASI defines filenames to be valid UTF-8 and returns ILSEQ when a filename is not valid UTF-8EILSEQ
was previously not a documented possible error for the relevant POSIX APIs, soILSEQ
was assumed to be a WASI-specific returnWith (2), this means that we will no longer be able to distinguish between "invalid UTF-8" or "contains newline" on WASI by the error code alone, so
.ILSEQ => return error.InvalidUtf8
will no longer be an advisable way to handleILSEQ
in WASI-specific code pathsMy current thinking is that we might want to just lump all of these sort of "bad filename" related errors together and let the user attempt to sort it out, e.g. translate both
INVAL
andILSEQ
to something likeerror.BadPathName
and then have a doc comment that lays out all the possible ways it can be returned on the various platformsNote
error.BadPathName
was used as the example because it already exists and is used for this sort of purpose already, e.g. there are some existing.INVAL => return error.BadPathName
and.OBJECT_NAME_INVALID => return error.BadPathName
mappings that partially address #15607 (examples: std.posix.openZ and std.os.windows.OpenFile)This is almost a duplicate of #15607, but I thought it might be worth tracking separately so I'm making an issue for it.
The text was updated successfully, but these errors were encountered: