My unix is a little rusty, when I find that “cd ~” takes me to the home directory on my Mac system (when using the command-line interface).
Therefore, I’ve tried to use paths like:
~/Library/Preferences/
to write to or read files from the Preferences folder on MacOS X. However, it fails to open a file for reading or writing. (Null pointer returned from SDL_RWFromFile.)
If I use a path in the program’s own directory, such as the following, it works:
/myData/
[Of course, a filename is appended to each of the paths above.]
I’m wondering if SDL programs are incapable of reading/writing to files inside the user’s home directory, or is the problem simply the ~ character? How would I access the home directory (for things like /Library/Preferences and /Library/Application Support/) without using this character?
Give you the path to the home directory (Remember that advanced
users may remap their home directories).
Give you more specific directories (like Preferences) which can be
directly asked for instead of appending to the home directory (better
practice again in case users modify paths)
Try looking up:
stringByExpandingTildeInPath (category on NSString I think)
NSHomeDirectory()
NSSearchPathForDirectoriesInDomains()
You will obviously have to integrate this platform specific code into
your SDL so it does not affect other platforms. You will probably find
it easiest to implement the backend in a .m file (Objective-C), but
make the public API your SDL app calls a regular C function declared
in a corresponding .h file. In theory, this C function interface could
be generic enough so you can implement a different backend for every
other platform you need to support.
-EricOn 11/11/10, VernJensen wrote:
My unix is a little rusty, when I find that “cd ~” takes me to the home
directory on my Mac system (when using the command-line interface).
Therefore, I’ve tried to use paths like:
~/Library/Preferences/
to write to or read files from the Preferences folder on MacOS X. However,
it fails to open a file for reading or writing. (Null pointer returned from
SDL_RWFromFile.)
If I use a path in the program’s own directory, such as the following, it
works:
/myData/
[Of course, a filename is appended to each of the paths above.]
I’m wondering if SDL programs are incapable of reading/writing to files
inside the user’s home directory, or is the problem simply the ~ character?
How would I access the home directory (for things like /Library/Preferences
and /Library/Application Support/) without using this character?
And that works in Windows? path is a local character array; it lives on the
stack. ‘return path’ should return a pointer to the array ‘path’, which data
is not guaranteed to survive for long.
JeffOn Friday 12 November 2010 09:28, Jonathan Dearborn wrote:
I use this on Windows:
string getHomeDir()
{
char path[PATH_MAX];
If that’s C++, the local char array is converted to a new string during
the return, so there’s no problem.On November 12, 2010 2:15:09 pm Jeff Post wrote:
On Friday 12 November 2010 09:28, Jonathan Dearborn wrote:
I use this on Windows:
string getHomeDir()
{
char path[PATH_MAX];
And that works in Windows? path is a local character array; it lives on
the stack. ‘return path’ should return a pointer to the array ‘path’,
which data is not guaranteed to survive for long.
Yeah, my language selection was perhaps a bit subtle, but the point was
there. I was going to put a throw in there, which would have made it more
clear. For C, I would take a char* argument and fill that in instead, just
wrapping and simplifying the SHGetSpecialFolderPath call:
And that works in Windows? path is a local character array; it lives on
the stack. ‘return path’ should return a pointer to the array ‘path’,
which data is not guaranteed to survive for long.
If that’s C++, the local char array is converted to a new string during
the return, so there’s no problem.