SpecsFs
SPECS NDK reference for the SpecsFs API, which resolves an app's well-known data and library root directories.
SpecsFs resolves the app's well-known root directories: the data directory and the library directory. The same app source builds unchanged for the device and for the macOS Simulator, because the function names and signatures are identical in both builds.
Include SpecsFs
#include <SpecsFs.h>
On the device, SpecsFs is header-only: the functions are static inline and compile into your app, so there is no library to link and nothing to load from the firmware.
SpecsFs function reference
// Returns the app's data root directory. On the device: "/data", never NULL.
// Since: v1.3.0
static inline const char *SpecsFs_getDataDir(void) { return "/data"; }
// Returns the app's library root directory. On the device: "/lib", never NULL.
// Since: v1.3.0
static inline const char *SpecsFs_getLibDir(void) { return "/lib"; }
On the device, both functions return string literals, valid for the life of the process.
Threading and safety:
- Thread-safe: may be called concurrently from any thread.
- errno-neutral: never modifies the caller's
errno.
SpecsFs in Simulator builds
SpecsFs.h selects its build by whether SPECSNDK_SIMULATOR is defined; its value doesn't matter. The NDK defines it for simulator builds (see macOS Simulator).
When SPECSNDK_SIMULATOR is defined, SpecsFs_getDataDir() and SpecsFs_getLibDir() are plain declarations implemented by the simulator's libspecs_fs, which reads the SPECS_SIM_DATA_DIR and SPECS_SIM_LIB_DIR environment variables:
- Each function returns
NULLif its variable is unset or empty. - The value is passed through verbatim: it isn't normalized, made absolute, or checked for existence.
- The library reads each variable once, on the first call.
- The returned string is owned by the library, valid for the life of the process, and must not be freed or modified.
The threading and errno rules are the same as on the device.