Comments (5)
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, mlib.h
shows that get_file_size
and load_file
already return a value, so I think it'd be more of the programmer's responsibility to take care of it, rather than the libraries. For example, the code below should be sufficient enough in most cases.
#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.
from mlib.
Actually, it might be better to have a global variable IO_FLAGS
and every time a hardware I/O is preformed, the value of IO_FLAGS
is updated with the current system flags. That way, you can be certain there's was a success/failure.
from mlib.
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:
extern unsigned int _stop_all_data__;
#define ramstart &_stop_all_data__
load_file(file, ramstart);
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.
from mlib.
Thanks for all the info, I think the easiest way would be to implement a global variable kinda like C's errno
, but like you said it's all up to individual style. Also, thanks for those two last tid bits. It's nice to know exactly where the program ends and silly me, I forget MikeOS loads the entire end sector, even if it's not completely used.
from mlib.
Alright, ioerr
will be used. The list below will be used to help me keep track of its implementation.
- Disk API
- Serial API
from mlib.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mlib.