Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method for abstracting filesystems in a C program

I'm starting out a program in SDL which obviously needs to load resources for the filesystem. I'd like file calls within the program to be platform-independent. My initial idea is to define a macro (lets call it PTH for path) that is defined in the preprocessor based on system type and and then make file calls in the program using it. For example

SDL_LoadBMP(PTH("data","images","filename"));

would simply translate to something filesystem-relevant.

If macros are the accepted way of doing this, what would such macros look like (how can I check for which system is in use, concatenate strings in the macro?)

If not, what is the accepted way of doing this?

like image 251
Scribble Master Avatar asked Feb 24 '23 18:02

Scribble Master


1 Answers

The Boost Filesystem module is probably your best bet. It has override for the "/" operator on paths so you can do stuff like...

ifstream file2( arg_path / "foo" / "bar" );
like image 78
Andrew White Avatar answered Mar 02 '23 16:03

Andrew White