Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] ff_fseek() documentation inadequate #53

Closed
carlk3 opened this issue Nov 8, 2023 · 1 comment
Closed

[DOC] ff_fseek() documentation inadequate #53

carlk3 opened this issue Nov 8, 2023 · 1 comment

Comments

@carlk3
Copy link
Contributor

carlk3 commented Nov 8, 2023

Describe the issue

ff_fseek has important restrictions that are not mentioned. Since this behavior is non-standard, I believe it would be best to state the restrictions rather than leave them unsaid. They might come as a surprise to someone used to, say, POSIX.

According to The Open Group Base Specifications, fseek , “The fseek() function shall allow the file-position indicator to be set beyond the end of existing data in the file. If data is later written at this point, subsequent reads of data in the gap shall return bytes with the value 0 until data is actually written into the gap.”

However, in +FAT, if you try to ff_fseek past the end of existing data in the file you will get an Illegal seek (29) error.

According to The Open Group Base Specifications, fseek , "The fseek() function shall set the file-position indicator for the stream pointed to by stream... The new position, measured in bytes from the beginning of the file, shall be obtained by adding offset to the position specified by whence. The specified point is the beginning of the file for SEEK_SET, the current value of the file-position indicator for SEEK_CUR, or end-of-file for SEEK_END."

However, if a file is opened for append (ff_fopen pcMode "a" or "a+") and the file already exists, +FAT defines "The beginning of the file" to be the end of the preexisting file. Therefore it is impossible to ff_fseek or ff_rewind to the absolute beginning of the file or to any position between there and the end of the preexisting file.

ff_rewind says it "Moves the current read/write position back to the start of a file." It should be clarified that if the file is opened for append with ff_fopen or ff_truncate the "start of a file" is considered to be the end of any preexisting file.

The GNU C Library Reference Manual says this about file position: "Streams and descriptors that are opened for append access are treated specially for output: output to such files is always appended sequentially to the end of the file, regardless of the file position. However, the file position is still used to control where in the file reading is done."

Reference
Please attach the URL at which you are experiencing the issue.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/stdio_API/ff_rewind.html

Screenshot
If applicable, please attach screenshot.

Browser

  • Browser: [e.g. Chrome]
  • Version: [e.g. 80.0.3987.132]
@bhoomrs
Copy link
Member

bhoomrs commented Oct 4, 2024

Updated the website to include behaviour and restrictions of the FreeRTOS-specific ff_fseek() function.

@bhoomrs bhoomrs closed this as completed Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants