Skip to content

fclose returns the wrong value on success/fail #669

@ZERICO2005

Description

@ZERICO2005

https://en.cppreference.com/w/c/io/fclose.html
fclose returns 0 on success and EOF otherwise.
The default implementation of fclose wraps ti_Close, which returns 0 on error. Therefore the wrong value will be returned here:

int __attribute__((weak)) fclose(FILE *stream) {
    ti_var_t slot;

    if (stream == NULL ||
        stream == stdin ||
        stream == stdout ||
        stream == stderr)
    {
        return EOF;
    }

    slot = stream->slot;

    _file_streams[slot - 1].slot = 0;

    return ti_Close(slot); // supposed to return 0 on success here
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions