sysdir(3) | Library Functions Manual | sysdir(3) |
sysdir_start_search_path_enumeration
,
sysdir_get_next_search_path_enumeration
—
Enumeration of the filesystem paths for the various
standard system directories where apps, resources, etc. get
installed.
#include
<sysdir.h>
sysdir_search_path_enumeration_state
sysdir_start_search_path_enumeration
(sysdir_search_path_directory_t
dir, sysdir_search_path_domain_mask_t
domainMask);
sysdir_search_path_enumeration_state
sysdir_get_next_search_path_enumeration
(sysdir_search_path_enumeration_state
state, char *path);
The sysdir
API returns the various
standard system directories where apps, resources, etc. get installed.
Because queries can return multiple directories, the API is in the form of
an enumeration. The directories are returned in search path order: that is,
the first place to look is returned first.
sysdir_start_search_path_enumeration
()
begins enumeration of the filesystem paths for the specified directory and
domain(s). The return value should be passed to one or more calls to
sysdir_get_next_search_path_enumeration
() to obtain
the filesystem path and continue the enumeration.
sysdir_get_next_search_path_enumeration
()
returns a filesystem path for the directory and domain(s) specified by the
state value returned by
sysdir_start_search_path_enumeration
(). Subsequent
calls to sysdir_get_next_search_path_enumeration
()
should pass the state value returned by the previous call to continue the
enumeration in each domain. A state value of zero will be returned when all
domains have been enumerated.
The path buffer
that is passed to
sysdir_get_next_search_path_enumeration
()
will be filled with a null-terminated string, possibly containing as many as
PATH_MAX-1 characters.
Some directory paths returned may not exist on the filesystem.
Some combinations of dir and domainMask may return no directory paths.
Directory paths returned in the user domain will contain "~" to refer to the user's directory.
The environment variable NEXT_ROOT
is
prepended as necessary to the returned directory paths.
NEXT_ROOT
is ignored if the process is setuid or is
code signed with entitlements.
The following sysdir_search_path_directory constants are defined:
The following sysdir_search_path_domain_mask constants are defined:
The following environment variable affects the execution of
sysdir_get_next_search_path_enumeration
:
NEXT_ROOT
NEXT_ROOT
environment variable is set and
the current process is not tainted by uid or gid changes,
NEXT_ROOT
is prepended as necessary to the
returned directory paths. NEXT_ROOT
is ignored if
the process is setuid or is code signed with entitlements.#include <limits.h> #include <sysdir.h> char path[PATH_MAX]; sysdir_search_path_enumeration_state state = sysdir_start_search_path_enumeration(dir, domainMask); while ( (state = sysdir_get_next_search_path_enumeration(state, path)) != 0 ) { // Handle directory path }
The sysdir
API first appeared in OS X
10.12, iOS 10, watchOS 3 and tvOS 10 replacing the deprecated
NSSystemDirectories(3)
API.
December 22, 2015 | Darwin |