-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
FS position method return valid position on error, should return -1 #9992
Comments
size_t is unsigned int. Unless you just opened the file or did a seek to 0, it will be unusual to get a 0 position. |
The problem is 0 is being used as an ERROR return, but it is actually a valid return. It is perfectly valid to have one method work on the file handle and then pass it to another method for further processing and have the second method test to see if the file has been rewound, i.e. check the position returns 0. In that case, if position() returns 0, how do I tell if the file has been rewound or if there is an error? Other FS libraries return -1, which, cast to size_t, will result in a very large number which can be used to detect the error. |
why would you depend on position to distinguish valid from invalid file? We could return |
As a user of this API, I would expect a return in the valid range, i.e. 0 to some high number, to indicate that the file is actually in that position. The 'fixes' for this seem to be either I think i) is the preferrable way and this is what the Seeed Arduino FS library does.
strtol seems use all three 'fixes' to give you the worst of all worlds
For some errors it returns an extreme value How would the maintainers of this library like to proceed? |
@drmpf I checked the very latest Arduino SD library (not ours, official SD lib) and it returns |
Fix for error return from position() Issue espressif#9992
* position_fix Fix for error return from position() Issue #9992 * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
See #10360 This should be reverted as it causes all kinds of issues, since |
Board
All
Device Description
ESP32
ESP8266 code base has the same issue
Hardware Configuration
all
Version
latest master (checkout manually)
IDE Name
Arduino
Operating System
Windows 10
Flash frequency
40Mhz
PSRAM enabled
yes
Upload speed
115200
Description
Current code returns valid file position on error, should return invalid position, i.e. -1
Current code is
should be
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: