c-env-utils
C library to get environment information
|
#include <stdlib.h>
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | _ENVU_EXTERN __attribute__((visibility("default"))) extern |
#define | _ENVU_ENUM(s) typedef unsigned int s; enum |
#define | ENVU_VERSION "0.3.1" |
#define | ENVU_VERSION_INT 301 |
Functions | |
_ENVU_EXTERN const char * | envuGetVersion (void) |
Gets the version of c-env-utils. | |
_ENVU_EXTERN int | envuGetVersionAsInt (void) |
Gets the version of c-env-utils as an integer. | |
_ENVU_EXTERN void | envuFree (void *p) |
Frees the memory of a string allocated by c-env-utils. | |
_ENVU_EXTERN char * | envuGetExecutablePath (void) |
Gets the path to the executing binary. | |
_ENVU_EXTERN int | envuFileExists (const char *path) |
Returns if the specified path is a regular file for not. | |
_ENVU_EXTERN int | envuPathExists (const char *path) |
Returns if the specified path exists for not. | |
_ENVU_EXTERN char * | envuGetFullPath (const char *path) |
Gets a full path of the specified path. | |
_ENVU_EXTERN char * | envuGetRealPath (const char *path) |
Gets a real path of the specified path. | |
_ENVU_EXTERN char * | envuGetDirectory (const char *path) |
Gets a parent directory of the specified path. | |
_ENVU_EXTERN char * | envuGetExecutableDir (void) |
Gets the directory of the executing binary. | |
_ENVU_EXTERN char * | envuGetCwd (void) |
Gets the current working directory. | |
_ENVU_EXTERN int | envuSetCwd (const char *path) |
Sets the current working directory. | |
_ENVU_EXTERN char * | envuGetEnv (const char *name) |
Gets a value of an environment variable. | |
_ENVU_EXTERN int | envuSetEnv (const char *name, const char *value) |
Sets an environment variable. | |
_ENVU_EXTERN char * | envuGetHome (void) |
Gets user's home directory. | |
_ENVU_EXTERN char * | envuGetUsername (void) |
Gets user name. | |
_ENVU_EXTERN char * | envuGetOS (void) |
Gets the name of running OS. | |
_ENVU_EXTERN char * | envuGetOSVersion (void) |
Gets the version of running OS. | |
_ENVU_EXTERN char * | envuGetOSProductName (void) |
Gets the product name and its version of running OS. | |
_ENVU_EXTERN char ** | envuGetEnvPaths (int *path_count) |
Gets the environment paths from the PATH variable. | |
_ENVU_EXTERN char ** | envuParseEnvPaths (const char *env_path, int *path_count) |
Parses the PATH variable. | |
_ENVU_EXTERN void | envuFreeEnvPaths (char **paths) |
Frees the memory of an array allocated by envuGetEnvPaths() or envuParseEnvPaths(). | |
#define _ENVU_ENUM | ( | s | ) | typedef unsigned int s; enum |
#define _ENVU_EXTERN __attribute__((visibility("default"))) extern |
#define ENVU_VERSION "0.3.1" |
#define ENVU_VERSION_INT 301 |
_ENVU_EXTERN int envuFileExists | ( | const char * | path | ) |
Returns if the specified path is a regular file for not.
path | A path. |
_ENVU_EXTERN void envuFree | ( | void * | p | ) |
Frees the memory of a string allocated by c-env-utils.
p | A pointer to a string. |
_ENVU_EXTERN void envuFreeEnvPaths | ( | char ** | paths | ) |
Frees the memory of an array allocated by envuGetEnvPaths() or envuParseEnvPaths().
paths | A null-terminated array of strings. |
_ENVU_EXTERN char * envuGetCwd | ( | void | ) |
Gets the current working directory.
_ENVU_EXTERN char * envuGetDirectory | ( | const char * | path | ) |
Gets a parent directory of the specified path.
path | A path. |
_ENVU_EXTERN char * envuGetEnv | ( | const char * | name | ) |
Gets a value of an environment variable.
name | A name of an environment variable. |
_ENVU_EXTERN char ** envuGetEnvPaths | ( | int * | path_count | ) |
Gets the environment paths from the PATH variable.
path_count | The number of paths will be stored here if it's not a null pointer. |
_ENVU_EXTERN char * envuGetExecutableDir | ( | void | ) |
Gets the directory of the executing binary.
_ENVU_EXTERN char * envuGetExecutablePath | ( | void | ) |
Gets the path to the executing binary.
_ENVU_EXTERN char * envuGetFullPath | ( | const char * | path | ) |
Gets a full path of the specified path.
It resolves dot segments but ignores symlinks.
path | A path. |
_ENVU_EXTERN char * envuGetHome | ( | void | ) |
Gets user's home directory.
_ENVU_EXTERN char * envuGetOS | ( | void | ) |
Gets the name of running OS.
e.g. "Windows" for Windows, "Darwin" for macOS, and "Linux" for Linux distros. You can see more examples here.
_ENVU_EXTERN char * envuGetOSProductName | ( | void | ) |
Gets the product name and its version of running OS.
e.g. "Microsoft Windows 10 Home", "Mac OS X 10.15.5", and "Ubuntu 20.04 LTS". You can see more examples here.
_ENVU_EXTERN char * envuGetOSVersion | ( | void | ) |
Gets the version of running OS.
You can see examples of return values here.
_ENVU_EXTERN char * envuGetRealPath | ( | const char * | path | ) |
Gets a real path of the specified path.
It can resolve symlinks but it fails if the specified path does not exist.
path | A path. |
_ENVU_EXTERN char * envuGetUsername | ( | void | ) |
Gets user name.
_ENVU_EXTERN const char * envuGetVersion | ( | void | ) |
Gets the version of c-env-utils.
It should be of the form x.x.x
.
_ENVU_EXTERN int envuGetVersionAsInt | ( | void | ) |
Gets the version of c-env-utils as an integer.
The value should be major * 100 + minor * 100 + patch
. If revGetVersion() == "1.2.3"
then revGetVersionAsInt() == 10203
.
_ENVU_EXTERN char ** envuParseEnvPaths | ( | const char * | env_path, |
int * | path_count | ||
) |
Parses the PATH variable.
Its paths should be separated by semicolons on Windows, or by colons on other platforms.
env_path | The value of the PATH variable. |
path_count | The number of paths will be stored here if it's not a null pointer. |
_ENVU_EXTERN int envuPathExists | ( | const char * | path | ) |
Returns if the specified path exists for not.
path | A path. |
_ENVU_EXTERN int envuSetCwd | ( | const char * | path | ) |
Sets the current working directory.
path | A string that represents a directory. |
_ENVU_EXTERN int envuSetEnv | ( | const char * | name, |
const char * | value | ||
) |
Sets an environment variable.
name | A name of an environment variable. |
value | A value of an environment variable. Or a null pointer to remove the variable. |