Hi
Is open() read() close() supposed to work? For me they doesn’t. It works sometimes but not all times. It also doesn’t read the file it just reads the first bytes or kbytes if large file.
fopen fread fclose is ok and stat.
Michael
I remember this issue years ago. Basically, the libc read()/write() functions didn't loop until they finished reading the number of bytes specified. While that behavior may technically meet POSIX standards, it isn't standard behavior. Incomplete reads and writes normally only happen with special files, e.g. pipes and sockets. I don't remember what changes were merged, but it sounds like the solution was only partial. There should be a closed GitHub issue about this.
On Tue, Feb 6, 2024, 5:08 AM Michael Grunditz michael.grunditz@gmail.com wrote:
Hi
Is open() read() close() supposed to work? For me they doesn’t. It works sometimes but not all times. It also doesn’t read the file it just reads the first bytes or kbytes if large file.
fopen fread fclose is ok and stat.
Michael _______________________________________________ Genode users mailing list users@lists.genode.org https://lists.genode.org/listinfo/users
Hello,
On Wed, Feb 07, 2024 at 07:07:05 CET, Nobody III wrote:
I remember this issue years ago. Basically, the libc read()/write() functions didn't loop until they finished reading the number of bytes specified. While that behavior may technically meet POSIX standards, it isn't standard behavior. Incomplete reads and writes normally only happen with special files, e.g. pipes and sockets. I don't remember what changes were merged, but it sounds like the solution was only partial. There should be a closed GitHub issue about this.
I do not know which "issue" you are referring to but I'm quite aware that we had repeating discussions about "partial reads". I see words above as your "opinion" about the matter and in no way "standard". POSIX and also the ISO C standard are quite explicit about the problematic nature of read() returning a short count in some cases. Both standards leave it to the programmer to cope with these situations and additionally provide a tool for the lazy - fread() [1]. So, if you don't want to treat short/partial reads in your code, just use fread(), but never spread misleading opinions as universal truth.
[1] https://pubs.opengroup.org/onlinepubs/9699919799/ "Upon successful completion, fread() shall return the number of elements successfully read which is less than nitems only if a read error or end-of-file is encountered."
Regards
In message 20240207073905.GA2932@genode-labs.com Christian Helmuth christian.helmuth@genode-labs.com wrote:
Hello,
I do not know which "issue" you are referring to but I'm quite aware that we had repeating discussions about "partial reads". I see words above as your "opinion" about the matter and in no way "standard". POSIX and also the ISO C standard are quite explicit about the problematic nature of read() returning a short count in some cases. Both standards leave it to the programmer to cope with these situations and additionally provide a tool for the lazy - fread() [1]. So, if you don't want to treat short/partial reads in your code, just use fread(), but never spread misleading opinions as universal truth.
Thanks for the clarification. Didn't know that it was as it should. I use fread from now on.
Michael
Hello Michael,
On Tue, Feb 06, 2024 at 13:08:22 CET, Michael Grunditz wrote:
Is open() read() close() supposed to work? For me they doesn’t. It works sometimes but not all times. It also doesn’t read the file it just reads the first bytes or kbytes if large file.
Yes, those functions are supposed to work and also do in quite some components, most of them ported applications. Could you be a bit more specific about the parameters and results in failing cases?
fopen fread fclose is ok and stat.
This hints the libc implementation copes with corner cases of the low-level functions your code does not.
Best regards
In message 20240207074350.GB2932@genode-labs.com Christian Helmuth christian.helmuth@genode-labs.com wrote:
Hello Michael,
On Tue, Feb 06, 2024 at 13:08:22 CET, Michael Grunditz wrote:
Is open() read() close() supposed to work? For me they doesnt. It works sometimes but not all times. It also doesnt read the file it just reads the first bytes or kbytes if large file.
Yes, those functions are supposed to work and also do in quite some components, most of them ported applications. Could you be a bit more specific about the parameters and results in failing cases?
I basicly do: open read only fstat to get file size malloc a buffer with that size read from it using that size close the file
fopen fread fclose is ok and stat.
This hints the libc implementation copes with corner cases of the low-level functions your code does not.
I have changed most of my code to use f* functions instead. It works just fine so no worries.
Thanks, Michael
In message 20240207074350.GB2932@genode-labs.com Christian Helmuth christian.helmuth@genode-labs.com wrote:
Hello Michael,
On Tue, Feb 06, 2024 at 13:08:22 CET, Michael Grunditz wrote:
Is open() read() close() supposed to work? For me they doesnt. It works sometimes but not all times. It also doesnt read the file it just reads the first bytes or kbytes if large file.
Yes, those functions are supposed to work and also do in quite some components, most of them ported applications. Could you be a bit more specific about the parameters and results in failing cases?
I forgot.. fstat also fails (but returns without error).
Michael
I'm sorry for misusing the term "standard behavior". I should have said "typical behavior".
On Wed, Feb 7, 2024 at 1:20 AM Michael Grunditz michael.grunditz@gmail.com wrote:
In message 20240207074350.GB2932@genode-labs.com Christian Helmuth christian.helmuth@genode-labs.com wrote:
Hello Michael,
On Tue, Feb 06, 2024 at 13:08:22 CET, Michael Grunditz wrote:
Is open() read() close() supposed to work? For me they doesn‘t. It works sometimes but not all times. It also doesn‘t read the file it just reads the first bytes or kbytes if large file.
Yes, those functions are supposed to work and also do in quite some components, most of them ported applications. Could you be a bit more specific about the parameters and results in failing cases?
I forgot.. fstat also fails (but returns without error).
Michael
Genode users mailing list users@lists.genode.org https://lists.genode.org/listinfo/users