-
Notifications
You must be signed in to change notification settings - Fork 0
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
Documentation error in Disk API #5
Comments
Thanks for bringing this to my attention! I'll go through each of those functions later tonight or tomorrow to figure out what needs to be done. Unfortunately, #include "mlib.h"
int main(int argc, char** argv) {
char *file = "example.txt";
if(!file_exists(file)) {
size = get_file_size(file);
if (size < 28671) {
/* Load 4 KiB away from this program. */
load_file(file, 28672); /* This should probably return a pointer. */
/* Example: int *p = load_file(file, 28672); */
} else {
print_string("The File is too large to load!\r\n");
}
} else {
print_string("Error loading the file!\r\n");
}
} This should catch most problems caused by disk I/O. |
Actually, it might be better to have a global variable |
You could also return multiple values from the function by having an extra parameter that is an int* type. That is how I have currently implemented it. However, that is entirely up to individual style. If you want to know the memory location after the end of the program, the Smaller C linker has a macro 'stop_alldata', that should expand to the location in memory after the program. Like so:
Hopefully the C compiler will not mangle the constant name. I am a little concerned about the return value of MikeOS's os_get_file_size, in that it does not account for "slack space". I will raise this issue on the MikeOS forum, in the meantime you should round up to the nearest 512 bytes. |
Thanks for all the info, I think the easiest way would be to implement a global variable kinda like C's |
Alright,
|
I have found another error in the MikeOS documentation.
All disk functions use the carry flag to report a disk error, except os_get_file_list which returns a blank string. However, the MikeOS documentation fails to mention that os_create_file and os_remove_file use the carry flag to indicate an error.
I checked your implementation and found your 'load_file', 'create_file' and 'remove_file' functions do not handle the carry flag. Additionally, in 'get_file_size' you return zero as the file size if a disk error occurs, which may be misleading.
The text was updated successfully, but these errors were encountered: