llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

read_unlocked doesn't support _IOLBF and _IONBF modes

Open vonosmas opened this issue 1 year ago • 4 comments

read_unlocked currently only supports _IOFBF buffering, this bug is to track adding support for _IOLBF and _IONBF modes. (note - write_unlocked already does have support for them).

See WIP patch in https://github.com/llvm/llvm-project/compare/main...braydonk:llvm-project:braydonk-file-buf-modes

@michaelrj-google - LMK if this can be marked as "good-first-issue"?

vonosmas avatar Dec 16 '24 22:12 vonosmas

@llvm/issue-subscribers-libc

Author: Alexey Samsonov (vonosmas)

`read_unlocked` currently only supports _IOFBF buffering, this bug is to track adding support for _IOLBF and _IONBF modes. (note - `write_unlocked` already does have support for them).

See WIP patch in https://github.com/llvm/llvm-project/compare/main...braydonk:llvm-project:braydonk-file-buf-modes

@michaelrj-google - LMK if this can be marked as "good-first-issue"?

llvmbot avatar Dec 16 '24 22:12 llvmbot

Hi @michaelrj-google May I try this issue?

jackhong12 avatar Dec 18 '24 00:12 jackhong12

@jackhong12 feel free to try it, I'll assign it to you. Feel free to reach out over github or discord if you have questions.

michaelrj-google avatar Dec 18 '24 00:12 michaelrj-google

Do we need to support _IOLBF for read_unlocked? If so, what is the behavior? It seems gnu libc doesn't support _IOLBF for fread. Could we directly apply _IOFBF buffering if the mode is _IOLBF?

I have checked the implementation of _IOLBF in https://github.com/llvm/llvm-project/compare/main...braydonk:llvm-project:braydonk-file-buf-modes, but I'm confused. If we only copy the data until the newline character \n, the data behind it might be lost.

https://github.com/braydonk/llvm-project/blob/99ecdd90e2d59554b5e021e0c8965b92e7d388d2/libc/src/__support/File/file.cpp#L299-L304

jackhong12 avatar Dec 18 '24 08:12 jackhong12