BRL-CAD
|
Routines for application setup and supplying information to user programs. More...
Files | |
file | app.h |
Enumerations | |
enum | bu_dir_t { BU_DIR_CURR =1 , BU_DIR_INIT , BU_DIR_BIN , BU_DIR_LIB , BU_DIR_LIBEXEC , BU_DIR_INCLUDE , BU_DIR_DATA , BU_DIR_DOC , BU_DIR_MAN , BU_DIR_TEMP , BU_DIR_HOME , BU_DIR_CACHE , BU_DIR_CONFIG , BU_DIR_EXT , BU_DIR_LIBEXT , BU_DIR_END } |
Functions | |
DEPRECATED const char * | bu_argv0_full_path (void) |
char * | bu_getcwd (char *buf, size_t size) |
char * | bu_getiwd (char *buf, size_t size) |
const char * | bu_getprogname (void) |
void | bu_setprogname (const char *path) |
const char * | bu_which (const char *cmd) |
const char * | bu_whereis (const char *cmd) |
FILE * | bu_temp_file (char *filepath, size_t len) |
Routine to open a temporary file. More... | |
int | bu_fchmod (int fd, unsigned long pmode) |
Wrapper around fchmod. More... | |
DEPRECATED const char * | bu_brlcad_dir (const char *dirkey, int fail_quietly) |
BRL-CAD specific path queries. More... | |
DEPRECATED const char * | bu_brlcad_root (const char *rhs, int fail_quietly) |
Locate where the BRL-CAD applications and libraries are installed. More... | |
const char * | bu_dir (char *result, size_t len,...) |
Routines for application setup and supplying information to user programs.
Routines for inspecting and reporting characteristics of the current running application environment.
enum bu_dir_t |
DEPRECATED const char * bu_argv0_full_path | ( | void | ) |
DEPRECATED: This routine is replaced by bu_getcwd(). Do not use.
returns the full path to argv0, regardless of how the application was invoked.
this routine will return "(BRL-CAD)" if argv[0] cannot be identified but should never return NULL. this routine is not thread-safe.
char * bu_getcwd | ( | char * | buf, |
size_t | size | ||
) |
Routine for obtaining the current working directory.
Result is written into the provided buf, up to size chars, and returned. If buf is NULL, dynamically allocated memory will be returned and must be free'd via bu_free().
char * bu_getiwd | ( | char * | buf, |
size_t | size | ||
) |
Routine for obtaining the initial working directory during application startup.
Result is written into the provided buf, up to size chars, and returned. If buf is NULL, dynamically allocated memory will be returned and must be free'd via bu_free().
const char * bu_getprogname | ( | void | ) |
Get the name of the running application. application codes should call bu_setprogname() first to ensure that the program name is stored appropriately on platforms that do not have an intrinsic method for tracking the program name automatically.
while this routine is thread-safe and reentrant, the static string returned is shared amongst all threads.
void bu_setprogname | ( | const char * | path | ) |
Set the name of the running application. This isn't strictly necessary on platforms that have an intrinsic method for tracking the program name automatically, but is still recommended for portability and is necessary on some strict modes of compilation.
while the implementation relies on a static string shared across all threads, this routine is thread-safe and reentrant.
const char * bu_which | ( | const char * | cmd | ) |
returns the first USER path match to a given executable name.
Routine to provide BSD "which" functionality, locating binaries of specified programs from the user's PATH. This is useful to locate binaries and resources at run-time.
caller should not free the result, though it will not be preserved between calls either. the caller should strdup the result if they need to keep it around.
routine will return NULL if the executable command cannot be found.
const char * bu_whereis | ( | const char * | cmd | ) |
returns the first SYSTEM path match to a given executable cmd name.
Routine to provide BSD "whereis" functionality, locating binaries of specified programs from the SYSTEM path. This is useful to locate binaries and resources at run-time.
caller should not free the result, though it will not be preserved between calls either. the caller should strdup the result if they need to keep it around.
routine will return NULL if the executable command cannot be found.
FILE * bu_temp_file | ( | char * | filepath, |
size_t | len | ||
) |
Routine to open a temporary file.
Create a temporary file. The first readable/writable directory will be used, searching TMPDIR/TEMP/TMP environment variable directories followed by default system temp directories and ultimately trying the current directory.
The name of the temporary file will be copied into a user-provided (filepath) buffer if it is a non-NULL pointer and of a sufficient (len) length to contain the filename.
This routine is guaranteed to return a new unique file or return NULL on failure. The file should be closed via fclose() when it is no longer needed. The temporary file will be automatically unlinked on application exit. It is the caller's responsibility to set file access settings, preserve file contents, or destroy file contents if the default behavior is non-optimal.
The temporary file may no longer exist after a call to fclose(), so do not close a handle until you are are done accessing it. Calling fileno()+dup()+fdopen() can obtain a second handle on an open file.
This routine is NOT thread-safe.
Typical Use:
int bu_fchmod | ( | int | fd, |
unsigned long | pmode | ||
) |
Wrapper around fchmod.
Portable wrapper for setting a file descriptor's permissions ala fchmod().
DEPRECATED const char * bu_brlcad_dir | ( | const char * | dirkey, |
int | fail_quietly | ||
) |
BRL-CAD specific path queries.
NOTE: this API is replaced by bu_dir()
For example: bu_brlcad_dir("doc", 1); is now: bu_dir(NULL, 0, BU_DIR_DOC, NULL);
Report the relative paths being used to hold BRL-CAD applications, libraries, and data.
Recognized keys include:
Key | Looks Up |
---|---|
bin | Directory containing applications |
lib | Directory containing libraries |
include | Directory containing headers |
data | Directory containing shared data |
share | Directory containing shared data |
doc | Directory containing documentation |
man | Directory containing Unix man pages |
DEPRECATED const char * bu_brlcad_root | ( | const char * | rhs, |
int | fail_quietly | ||
) |
Locate where the BRL-CAD applications and libraries are installed.
NOTE: this API is replaced by bu_dir()
For example: bu_brlcad_root("share/tclscripts/isst/isst.tcl", 1); is now: bu_dir(NULL, 0, BU_DIR_DATA, "tclscripts", "isst", "isst.tcl", NULL);
The BRL-CAD root is searched for in the following order of precedence by testing for the rhs existence if provided or the directory existence otherwise:
BRLCAD_ROOT environment variable if set run-time path identification BRLCAD_ROOT compile-time path current directory
const char * bu_dir | ( | char * | result, |
size_t | len, | ||
... | |||
) |
Find a particular user, system, or runtime directory.
This function writes into buffer and returns, if found, the path to a given filesystm resource. The caller may specify paths to subdirectories and/or filenames as a NULL-terminated vararg list.
Paths returned will use the native directory separator. Callers may also manually concatenate subdirectory resources (e.g., "share/db/moss.g") using forward slashes and they will be converted to the native separator.
result | if non-NULL, buffer should have >= MAXPATHLEN chars |
len | is the size of the result buffer |
... | must be one of the above enumerations or a string/path |