1 <!-- ##### SECTION Title ##### -->
2 Miscellaneous Utility Functions
4 <!-- ##### SECTION Short_Description ##### -->
5 a selection of portable utility functions.
7 <!-- ##### SECTION Long_Description ##### -->
9 These are portable utility functions.
12 <!-- ##### SECTION See_Also ##### -->
17 <!-- ##### FUNCTION g_get_application_name ##### -->
25 <!-- ##### FUNCTION g_set_application_name ##### -->
33 <!-- ##### FUNCTION g_get_prgname ##### -->
35 Gets the name of the program. This name should NOT be localized,
36 contrast with g_get_application_name().
37 (If you are using GDK or GTK+ the program name is set in gdk_init(), which
38 is called by gtk_init(). The program name is found by taking the last
39 component of <literal>argv[0]</literal>.)
42 @Returns: the name of the program.
45 <!-- ##### FUNCTION g_set_prgname ##### -->
47 Sets the name of the program. This name should NOT be localized,
48 contrast with g_set_application_name(). Note that for thread-safety
49 reasons this function can only be called once.
52 @prgname: the name of the program.
55 <!-- ##### FUNCTION g_getenv ##### -->
64 <!-- ##### FUNCTION g_setenv ##### -->
75 <!-- ##### FUNCTION g_unsetenv ##### -->
83 <!-- ##### FUNCTION g_get_user_name ##### -->
85 Gets the user name of the current user.
88 @Returns: the user name of the current user.
91 <!-- ##### FUNCTION g_get_real_name ##### -->
93 Gets the real name of the user. This usually comes from the user's entry in the
94 <filename>passwd</filename> file. The encoding of the returned string is system
95 defined. If the real user name cannot be determined, the string "Unknown" is
99 @Returns: the user's real name.
102 <!-- ##### FUNCTION g_get_user_cache_dir ##### -->
110 <!-- ##### FUNCTION g_get_user_data_dir ##### -->
118 <!-- ##### FUNCTION g_get_user_config_dir ##### -->
126 <!-- ##### FUNCTION g_get_home_dir ##### -->
128 Gets the current user's home directory.
131 Note that in contrast to traditional Unix tools, this function
132 prefers <filename>passwd</filename> entries over the <envar>HOME</envar>
133 environment variable.
136 @Returns: the current user's home directory.
139 <!-- ##### FUNCTION g_get_tmp_dir ##### -->
141 Gets the directory to use for temporary files.
142 This is found from inspecting the environment variables <envar>TMPDIR</envar>,
143 <envar>TMP</envar>, and <envar>TEMP</envar>
144 in that order. If none of those are defined "/tmp" is returned on UNIX and
148 @Returns: the directory to use for temporary files.
151 <!-- ##### FUNCTION g_get_current_dir ##### -->
153 Gets the current directory.
154 The returned string should be freed when no longer needed.
157 @Returns: the current directory.
160 <!-- ##### FUNCTION g_basename ##### -->
167 <!-- ##### MACRO g_dirname ##### -->
169 This function is deprecated and will be removed in the next major
170 release of GLib. Use g_path_get_dirname() instead.
174 Gets the directory components of a file name.
175 If the file name has no directory components "." is returned.
176 The returned string should be freed when no longer needed.
179 @Returns: the directory components of the file.
182 <!-- ##### FUNCTION g_path_is_absolute ##### -->
184 Returns %TRUE if the given @file_name is an absolute file name,
185 i.e. it contains a full path from the root directory such as '/usr/local'
186 on UNIX or 'C:\windows' on Windows systems.
189 @file_name: a file name.
190 @Returns: %TRUE if @file_name is an absolute path.
193 <!-- ##### FUNCTION g_path_skip_root ##### -->
195 Returns a pointer into @file_name after the root component, i.e. after
196 the '/' in UNIX or 'C:\' under Windows. If @file_name is not an absolute
197 path it returns %NULL.
200 @file_name: a file name.
201 @Returns: a pointer into @file_name after the root component.
204 <!-- ##### FUNCTION g_path_get_basename ##### -->
213 <!-- ##### FUNCTION g_path_get_dirname ##### -->
215 Gets the directory components of a file name. If the file name has no
216 directory components "." is returned. The returned string should be
217 freed when no longer needed.
220 @file_name: the name of the file.
221 @Returns: the directory components of the file.
224 <!-- ##### FUNCTION g_build_filename ##### -->
234 <!-- ##### FUNCTION g_build_path ##### -->
245 <!-- ##### FUNCTION g_find_program_in_path ##### -->
254 <!-- ##### FUNCTION g_bit_nth_lsf ##### -->
256 Find the position of the first bit set in @mask, searching from (but not
257 including) @nth_bit upwards. Bits are numbered from 0 (least significant)
258 to sizeof(#gulong) * 8 - 1 (31 or 63, usually). To start searching from the
259 0th bit, set @nth_bit to -1.
262 @mask: a #gulong containing flags.
263 @nth_bit: the index of the bit to start the search from.
264 @Returns: the index of the first bit set which is higher than @nth_bit.
267 <!-- ##### FUNCTION g_bit_nth_msf ##### -->
269 Find the position of the first bit set in @mask, searching from (but not
270 including) @nth_bit downwards. Bits are numbered from 0 (least significant)
271 to sizeof(#gulong) * 8 - 1 (31 or 63, usually). To start searching from the
272 last bit, set @nth_bit to -1 or GLIB_SIZEOF_LONG * 8.
275 @mask: a #gulong containing flags.
276 @nth_bit: the index of the bit to start the search from.
277 @Returns: the index of the first bit set which is lower than @nth_bit.
280 <!-- ##### FUNCTION g_bit_storage ##### -->
282 Gets the number of bits used to hold @number,
283 e.g. if @number is 4, 3 bits are needed.
287 @Returns: the number of bits used to hold @number.
290 <!-- ##### FUNCTION g_spaced_primes_closest ##### -->
292 Gets the smallest prime number from a built-in array of primes which
293 is larger than @num. This is used within GLib to calculate the optimum
294 size of a #GHashTable.
297 The built-in array of primes ranges from 11 to 13845163 such that
298 each prime is approximately 1.5-2 times the previous prime.
302 @Returns: the smallest prime number from a built-in array of primes which is
306 <!-- ##### FUNCTION g_atexit ##### -->
308 Specifies a function to be called at normal program termination.
311 @func: the function to call on normal program termination.
314 <!-- ##### FUNCTION g_parse_debug_string ##### -->
316 Parses a string containing debugging options separated by ':' into a guint
317 containing bit flags.
318 This is used within GDK and GTK+ to parse the debug options passed on the
319 command line or through environment variables.
322 @string: a list of debug options separated by ':' or "all" to set all flags.
323 @keys: pointer to an array of #GDebugKey which associate strings with
325 @nkeys: the number of #GDebugKey in the array.
326 @Returns: the combined set of bit flags.
329 <!-- ##### STRUCT GDebugKey ##### -->
331 Associates a string with a bit flag.
332 Used in g_parse_debug_string().
338 <!-- ##### USER_FUNCTION GVoidFunc ##### -->
340 Declares a type of function which takes no arguments and has no return value.
341 It is used to specify the type function passed to g_atexit().
346 <!-- ##### USER_FUNCTION GFreeFunc ##### -->
348 Declares a type of function which takes an arbitrary data pointer argument
349 and has no return value. It is not currently used in GLib or GTK+.
352 @data: a data pointer.
355 <!-- ##### FUNCTION g_qsort_with_data ##### -->
367 <!-- ##### FUNCTION g_nullify_pointer ##### -->