paulo@0: /* paulo@0: ljpath - functions to support an application that can be paulo@0: installed to either a read-write folder ("portable" config) paulo@0: or to a read-only folder ("installed" config) paulo@0: paulo@0: Copyright 2008 Damian Yerrick paulo@0: paulo@0: Insert zlib license here. paulo@0: paulo@0: */ paulo@0: paulo@0: #ifndef LJPATH_H paulo@0: #define LJPATH_H paulo@0: paulo@0: #ifdef __cplusplus paulo@0: #include paulo@0: using std::FILE; paulo@0: extern "C" paulo@0: { paulo@0: #define DISTINCT paulo@0: #else paulo@0: #include paulo@0: #define DISTINCT restrict paulo@0: #endif paulo@0: paulo@0: /** paulo@0: * Sets up the paths used by ljfopen(). paulo@0: * Determines whether the program is marked as "installed", by paulo@0: * the presence of a file called installed.ini in the folder paulo@0: * containing the executable file. If so, uses a folder in the paulo@0: * user's home directory instead of the current directory for paulo@0: * writable files. paulo@0: * @param argv0 the executable file's path paulo@0: * @return nonzero for installed; zero for portable paulo@0: */ paulo@0: int ljpathInit(const char *argv0); paulo@0: paulo@0: /** paulo@0: * Sets the skin folder to the folder containing a file. For instance, paulo@0: * in a skinnable falling block game, this would be the folder holding paulo@0: * the .skin file that describes the path to each graphic used for the paulo@0: * game display. paulo@0: * @param filename the name of the file paulo@0: */ paulo@0: void ljpathSetSkinFolder(const char *filename); paulo@0: paulo@0: /** paulo@0: * Searches for a file in read-write, skin, and read-only folders paulo@0: * @param dst pointer to a PATH_MAX-byte buffer to hold the path paulo@0: * @param filename the name of the file that will be searched for paulo@0: * @return nonzero if the file was found; 0 if not found paulo@0: */ paulo@0: int ljpathFind_r(char *DISTINCT dst, const char *DISTINCT filename); paulo@0: paulo@0: int ljpathFind_w(char *DISTINCT dst, const char *DISTINCT filename); paulo@0: paulo@0: /** paulo@0: * Searches for a file and opens it. After it is opened, the paulo@0: * caller may use stdio.h operations on it and must close it. paulo@0: * Files being read are searched for using ljpathFind_r; others are paulo@0: * searched for using ljpathFind_r paulo@0: * @param filename the name of the file that will be searched for paulo@0: * @param mode the stdio mode (r, w, a, rb, wb, ab) paulo@0: * @return a magic cookie suitable for passing to stdio.h if the file paulo@0: * was opened; 0 if not opened paulo@0: */ paulo@0: FILE *ljfopen(const char *DISTINCT filename, const char *DISTINCT mode); paulo@0: paulo@0: paulo@0: #ifdef __cplusplus paulo@0: } paulo@0: #endif paulo@0: paulo@0: #endif