BRL-CAD
Loading...
Searching...
No Matches
env.h
Go to the documentation of this file.
1/* E N V . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2007-2026 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21#ifndef BU_ENV_H
22#define BU_ENV_H
23
24#include "common.h"
25
26#include "bu/defines.h"
27#include "bu/ptbl.h"
28
30
31/** @addtogroup bu_env
32 *
33 * @brief
34 * Platform-independent methods for interacting with the parent operating
35 * system environment.
36 *
37 */
38/** @{ */
39/** @file bu/env.h */
40
41BU_EXPORT extern int bu_setenv(const char *name, const char *value, int overwrite);
42
43
44/* Specific types of machine memory information that may be requested */
45#define BU_MEM_ALL 0
46#define BU_MEM_AVAIL 1
47#define BU_MEM_PAGE_SIZE 2
48#define BU_MEM_PROCESS_AVAIL 3
49#define BU_MEM_PROCESS_RESIDENT 4
50
51/**
52 * Report memory sizes in bytes. BU_MEM_ALL and BU_MEM_AVAIL report physical
53 * system memory; the available value is a platform-specific estimate that may
54 * change immediately after it is sampled. BU_MEM_PROCESS_AVAIL reports the
55 * remaining virtual address space under a finite process limit. It returns
56 * -1 when the platform does not expose that information or the process is
57 * unlimited. BU_MEM_PROCESS_RESIDENT reports the calling process's current
58 * resident physical memory and returns -1 when that information is not
59 * available. Accounting of pages shared with other processes is platform
60 * specific.
61 *
62 * Returns -1 on error and the size of the requested memory type on
63 * success. Optionally if sz is non-NULL, the size of the requested
64 * memory type will be set to it.
65 */
66BU_EXPORT extern ssize_t bu_mem(int type, size_t *sz);
67
68
69/**
70 * Select an editor.
71 *
72 * Returns a string naming an editor to be used. If an option is needed for
73 * invoking the editor, it is supplied via the editor_opt output.
74 *
75 * When 0 is supplied to the etype parameter, all editors will be considered
76 * when using libbu's internal editors list. To restrict the set searched to
77 * console editors, set etype to 1. For only GUI editors, set etype to 2.
78 *
79 * The general pattern for trying to locate an editor using inputs (either
80 * internal or user supplied is:
81 *
82 * 1. If the input is a full, valid path it will be used as-is.
83 * 2. Otherwise, the BRL-CAD's binaries will be checked for a bundled copy.
84 * 3. Otherwise, bu_which will attempt to find the full path.
85 *
86 * The highest priority source for editors to try are the BRLCAD_EDITOR_GUI
87 * (for graphical editors) and BRLCAD_EDITOR_CONSOLE for console editors. If
88 * those are unset or don't satisfy the criteria, the VISUAL (2nd priority) or
89 * EDITOR (3rd priority) environment variables are checked next. If any of
90 * those variables are set and identify a valid edtior per current criteria
91 * they take priority over both libbu's internal list and a user supplied list.
92 *
93 * If the environment variables don't pan out, the next priority is any user
94 * supplied options via the check_for_editors array. As with the env
95 * variables, an attempt will be made to respect the etype setting.
96 *
97 * If the optional check_for_editors array is provided, libbu will first
98 * attempt to use the contents of that array to find an editor. The main
99 * purpose of check_for_editors is to allow applications to define their own
100 * preferred precedence order in case there are specific advantages to using
101 * some editors over others. It is also useful if an app wishes to list some
102 * specialized editor not part of the normal listings, although users should
103 * note that the etype modal checks will not be useful when such editors are
104 * supplied. If an application wishes to use ONLY a check_for_editors list and
105 * not fall back on libbu's internal list if it fails, they should assign the
106 * last entry of check_for_editors to be NULL to signal libbu to stop looking
107 * for an editor there:
108 *
109 * int check_for_cnt = 3; const char *check_for_editors[3] = {"editor1", "editor2", NULL};
110 *
111 * To allow libbu to continue on if all check_for_editors entries fail,
112 * don't terminate with a NULL:
113 *
114 * int check_for_cnt = 2; const char *check_for_editors[3] = {"editor1", "editor2"};
115 *
116 * In the latter case, if none of those inputs result in an editor being
117 * returned, libbu will attempt to use its own internal lists to search. We
118 * are deliberately NOT documenting the libbu's internal editor list as public
119 * API, nor do we make any guarantees about what precedence any editor that IS
120 * on the list will take relative to other editors. What editors are popular
121 * in various environments can change over time, and the purpose of this
122 * function is to provide *some* editor, rather than locking in any particular
123 * precedence. check_for_editors should be used if an app needs more
124 * guaranteed stability in lookup behaviors.
125 *
126 * If etype != 0, bu_editor will attempt to validate any candidate returns
127 * against its own internal list of GUI and console editors to avoid returning
128 * an editor that is incompatible with the specified environment. There are no
129 * strong guarantees offered for this checking - libbu's knowledge of editors
130 * is not comprehensive and specification strings for editors may break the
131 * matching being used internally. In a case where libbu CAN'T make a definite
132 * categorization (a user supplied custom editor, for example) the default
133 * behavior will be to pass through the result as successful. This is
134 * obviously not foolproof, but in various common cases libbu will avoid
135 * returning (for example) nano from an EDITOR setting when a GUI editor type
136 * was requested.
137 *
138 * Caller should NOT free the main string return from bu_editor or the contents
139 * of the editor_opts bu_ptbl. The caller has ownership of the editor_opts
140 * bu_ptbl container however, so they ARE responsible for for freeing the table
141 * itself once use of editor_opts is complete.
142 */
143BU_EXPORT const char *bu_editor(struct bu_ptbl *editor_opts, int etype, int check_for_cnt, const char **check_for_editors);
144
145/** @} */
146
148
149#endif /* BU_ENV_H */
150
151/*
152 * Local Variables:
153 * tab-width: 8
154 * mode: C
155 * indent-tabs-mode: t
156 * c-file-style: "stroustrup"
157 * End:
158 * ex: shiftwidth=4 tabstop=8
159 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
ssize_t bu_mem(int type, size_t *sz)
const char * bu_editor(struct bu_ptbl *editor_opts, int etype, int check_for_cnt, const char **check_for_editors)
int bu_setenv(const char *name, const char *value, int overwrite)
Definition ptbl.h:53