Utility API
These are useful functions used in Oasis.
OasisNet.h
OasisUtil.h
Network
Obtains a list of network interface names installed on the device.
ifnames[][IFNAMSIZ]
OUT
Returns the list of network interface names.
ifnames_size
The maximum size of the network interface name list.
flags
The flag value applied during searching.
Returns the number of network interfaces. Returns -1 on failure.
The flag value performs OR'ing of the following values:
#define NETIF_LIST_F_LOOPBACK_INCLUDED 0x0001
#define NETIF_LIST_F_MULTICAST_SUPPORTED 0x0002
NETIF_LIST_F_LOOPBACK_INCLUDED: Includes the loopback device during searching.
NETIF_LIST_F_MULTICAST_SUPPORTED: Includes only network interfaces that support multicast during searching.
Obtains a list of network interface names and a list of indices installed on the device.
ifnames[][IFNAMSIZ]
OUT
Returns the list of network interface names.
ifindices[]
OUT
Returns the list of network interface indices.
ifnames_size
The maximum size of the network interface name and index lists.
flags
The flag value applied during searching.
Returns the number of network interfaces. Returns -1 on failure.
Obtains the currently active network interface name and hardware address.
ifname
OUT
Returns the network name.
ifname_size
The size of the network name buffer. Measured in bytes.
macaddr
OUT
Returns the hardware address.
maclen
The size of the hardware address buffer. Measured in bytes.
Obtains the hardware address connected to the socket.
s
The socket handle number.
macaddr
OUT
Returns the hardware address.
maclen
The size of the hardware address buffer. Measured in bytes.
Obtains the hardware address corresponding to the network interface name.
ifname
The network interface name.
macaddr
OUT
Returns the hardware address.
maclen
The size of the hardware address buffer. Measured in bytes.
Obtains the network configuration settings of the network interface name.
if_name
The network interface name.
netaddr
OUT
Returns the IPv4 address.
netmask
OUT
Returns the Netmask.
gateway
OUT
Returns the gateway address.
Verifies whether the address is within the same local network.
in
The IPv4 address to verify.
-
true: It is within the same local network.
-
false: It is within a different network.
Verifies whether the address is the IPv4 address of my device.
in
The IPv4 address to verify.
-
true: It is my network address.
-
false: It is not my network address.
Converts a network address into a string. The converted string format is <IPv4 address>/<Port Number>.
addr
The address to convert.
Returns the converted string address.
Obtains the index of the network interface connected to the socket.
s
The socket handle number.
Returns the network interface index number on success, and returns -1 on failure.
Obtains the index of the network interface connected to the local address.
Returns the network interface index number on success, and returns -1 on failure.
Verifies whether the network interface name is valid.
netif_name
The network interface name.
-
true: It is valid.
-
false: It is not valid.
Verifies whether all network interface names in the list are valid.
network_interfaces
The list of network interface names separated by commas (,). For example, it is formatted like "eth0,wlan0".
Returns "true" if all are valid. Returns "false" if even one is invalid.
Obtains a list of network interface names.
network_interfaces
The list of network interface names separated by commas (,). If it is not nullptr, it verifies whether the network interface names in this list are valid, and returns -1 if even one is invalid. If all are valid, it returns this list name. If it is nullptr, it finds and returns the list of network interface names existing on the device based on the flags value.
ifnames[][IFNAMSIZ]
OUT
Returns the list of network interface names.
ifnames_size
The maximum size of the network interface name list.
flags
The flag value applied during searching.
Returns the list size on success. Returns -1 on failure.
Verifies whether the network connected to the network interface is down.
ifname
The network interface name.
-
true: The network is down.
-
false: The network is up.
Activates the Oasis DNS client component.
enable
Activates if true, and deactivates if false.
Specifies the network transport type to be used by the Oasis DNS client component.
transport
A value of "0" uses TCP, and a value of "1" uses UDP.
Configures the maximum time to wait for the Oasis DNS client component to resolve the FQDN.
timeout
The maximum waiting time. Measured in milliseconds.
Converts an FQDN into an IPv4 address using the DNS service.
netaddr
The FQDN. For example, it is a fully qualified name like "www.mediastek.com".
addr4_ptr
OUT
Returns the converted address string.
use_systemd
Uses the system's DNS service if true. Uses the Oasis DNS service if false.
Obtains a list of IPv4 addresses from the FQDN using the DNS service. Useful when a single FQDN has multiple IPv4 addresses.
netaddr
The FQDN. For example, it is a fully qualified name like "www.mediastek.com".
addrs
OUT
Returns the converted list of IPv4 addresses.
Decodes an encoded URL.
url
The encoded URL string.
len
The string length.
decoded_url
OUT
Returns the decoded URL string.
Returns the length of the decoded URL string on success. Returns -1 on failure.
Encodes a URL.
url
The URL to encode.
encoded_url
OUT
Returns the encoded URL string.
Returns the length of the encoded URL string on success. Returns -1 on failure.
Converts a file extension into a MIME type. Supported extensions must be pre-registered during Oasis initialization or dynamically registered via the API. Case-insensitive.
extension
The string pointer indicating the extension.
Returns the corresponding MIME type for the file if the extension is supported. Returns "application/octet-stream" for an unknown extension.
Returns the MIME type from a file name that has a typical file extension.
Returns the MIME type for supported extensions, and returns "application/octet-stream" for unsupported extensions.
Below is the MIME type table per file extension recognized by Oasis:
| Extension |
MIME Type |
| html, htm, osp |
text/html |
| png |
image/png |
| gif |
image/gif |
| bmp |
image/bmp |
| jpeg, jpg |
image/jpeg |
| css |
text/css |
| js |
application/x-javascript |
| mp4 |
video/mp4 |
| avi |
video/x-msvideo |
| cgi |
text/html |
| pdf |
application/pdf |
| Others |
application/octet-stream |
Strings
Converts byte array data into a hexadecimal string. One byte is converted into two hexadecimal characters. The length of the returned string is twice the data length.
data
The byte array data pointer.
length
The array length.
lowercase
Uses lowercase hexadecimal characters (abcdef) if "true". Uses uppercase hexadecimal characters (ABCDEF) if "false".
A string composed of hexadecimal characters. For example, if the lowercase value is "true", it is converted like <span class="monotext">5f1bc26509002142b6f2</span>. If the lowercase value is "false", it is converted like <span class="monotext">5F1BC26509002142B6F2</span>.
Returns a Hex Dump format string where one line consists of 16 bytes, and each line is composed of hexadecimal characters and ASCII from the byte array data.
data
The byte array data pointer.
length
The array length.
lowercase
Uses lowercase hexadecimal characters (abcdef) if "true". Uses uppercase hexadecimal characters (ABCDEF) if "false".
The Hex Dump format string.
Below is an example of toHexDumpString:
" 00000000 33 59 c6 dd 97 07 1d d4 3b d3 5c 40 b3 b0 c9 a4 3Y......;.\@....\n 00000010 f1 0b 36 39 59 5c ed e8 dd 63 42 ce f9 d0 88 2c ..69Y...cB....,\n 00000020 29 4e 09 c0 \n"
Printing this string to the console looks like the following:
00000000 33 59 c6 dd 97 07 1d d4 3b d3 5c 40 b3 b0 c9 a4 3Y......;.\@....
00000010 f1 0b 36 39 59 5c ed e8 dd 63 42 ce f9 d0 88 2c ..69Y\...cB....,
00000020 29 4e 09 c0 )N..
Returns a string where the byte array data is converted into respective ASCII values. Non-printable characters are converted into ".". For example, it returns in a format like <span class="monotext">.p.j..#...Pp...[.av.r.H...o'.Z.D..</span>.
data
The byte array data pointer.
length
The array length.
Returns the converted string.
Converts 32-bit array data into a string separated by ".". For example, it returns in a format like <span class="monotext">561719494.513318045.664304121.498333846</span>.
data
The 32-bit array data pointer.
length
The array length.
Converts byte array data into a string separated by ".". For example, it returns in a format like <span class="monotext">70.230.47.188.127.96</span>.
data
The byte array data pointer.
length
The array length.
Verifies whether the string is composed entirely of numbers (0123456789).
-
true: Composed entirely of numbers.
-
false: Composed of other characters besides numbers.
Verifies whether the string is composed entirely of hexadecimal characters (0123456789abcdefABCDEF).
-
true: Composed entirely of hexadecimal characters.
-
false: Composed of other characters besides hexadecimal characters.
Returns a formatted string. The format is identical to printf.
format
The format string.
...
The argument list.
Returns the formatted string.
Receives va_list as an argument and returns a formatted string. The format is identical to printf.
format
The format string.
args
The argument list.
Returns the formatted string.
Changes the from string into the to string within a string.
str
IN
OUT
The string.
from
The string to find.
to
The string to substitute.
Converts a string into a number. If the string starts with "0x" or "0X", it is considered a hexadecimal string and converted from hexadecimal to a number. Otherwise, it is considered a decimal string. If there is a hexadecimal notation such as \xNN in the middle of a decimal string, only that part is converted from hexadecimal to a number. It converts into a number only up to the part recognized as a number symbol.
string
The string pointer.
Returns the converted numeric value.
Converts a string into an array. If the string starts with "0b" or "0B", it is considered a binary number, grouped by 8 bits and converted into a single-byte value. If the last byte is not a complete 8 bits, the number of unfilled bits is returned to padding_bits_ptr. For example, if only 3 bits are filled with "110", a value of 5 is returned, and the last element value of the array becomes "192" (in binary, "1100 0000"). If the string starts with "0x" or "0X", it is considered a hexadecimal string, and two hexadecimal characters are converted and stored as a single-byte numeric value. In other cases, one character of the string is stored directly in the array byte by byte; if "\xNN" exists in the middle of this string, NN is considered a hexadecimal character and the converted numeric value is stored, if "\0" exists, "0" is stored, and if "\" exists, "\" is stored.
string
The string pointer.
buffer
The buffer pointer to convert.
size
The buffer size. Measured in bytes. Specify at least the minimum string length.
padding_bits_ptr
OUT
Returns the number of last unfilled bits in the case of binary conversion.
Returns the byte array size. Returns -22 (EINVAL) on failure.
Base64
Obtains the decoded data from a BASE64 encoded string.
out
OUT
The buffer pointer to store the decoding result.
in
The BASE64 encoded string.
out_length
The length of the buffer where the decoding result will be stored. Measured in bytes. It is smaller than the encoded string length.
Returns the decoded data length on success. Returns -1 on failure.
Obtains a BASE64 encoded string from data.
buf
The buffer pointer to store the encoded string.
buf_len
The buffer length to store the encoded string. Measured in bytes.
src
The data pointer to encode.
len
The data length to encode. Measured in bytes.
line_length
If it is not 0, it breaks the encoded string by the line_length length line by line and returns it. Each line distinction uses "\a".
Returns the encoded string length on success. If composed of multiple lines, the number of line separators "\a" is also included. For 3 lines, it is 2 greater than the actual encoded length. Returns -1 on failure.
Below is the BASE64 encoded string when line_length is 0:
BN+faS4nrqxihBlI7FrA/ouSVhdvYqNNWzVdZxkMPB3r24YZAjTFZLnerKU4bKTE/vrbbV1+u7i0GB/NJFvqDzZwKDik7Zxdy0gDBLSnyLKhox/+Idq21fPVohcwjCdm/E+eoT06/giCAQw2qNToSncISJni/27V1BHtBZ0=
Below is the BASE64 encoded string when line_length is 32:
BN+faS4nrqxihBlI7FrA/ouSVhdvYqNN<0x0a>
WzVdZxkMPB3r24YZAjTFZLnerKU4bKTE<0x0a>
/vrbbV1+u7i0GB/NJFvqDzZwKDik7Zxd<0x0a>
y0gDBLSnyLKhox/+Idq21fPVohcwjCdm<0x0a>
/E+eoT06/giCAQw2qNToSncISJni/27V<0x0a>
1BHtBZ0=
Random Data and UUID
Obtains a random byte array.
buf
The buffer pointer to store the random byte array.
length
The buffer size. Measured in bytes.
Obtains a UUID string. For example, it is a string formatted like <span class="monotext">1c7ffde7-ae42-1ce9-ae55-8000206779f2</span>.
Time
Obtains the timeval structure as a string converted to the format "yyyy/mm/dd hh:mm:ss". Based on UTC+0. For example, it is converted to a format like <span class="monotext">2000/06/07 21:34:39</span>.
tv
The pointer to the timeval structure to convert.
Returns the converted string.
Returns the difference between two timeval structures.
x
The pointer to the timeval structure.
y
The pointer to the timeval structure.
Returns the x-y value. Measured in microseconds.
Obtains the CLOCK_MONOTONIC value. This is an incrementally increasing timer value after system booting.
tv
OUT
The pointer to the timeval structure to be stored.
Obtains an incrementally increasing timer value after system booting. Measured in microseconds.
Obtains a value where the timespec value is converted into a microsecond value. timespec can represent nanosecond values.
ts
The timespec structure reference.
Returns the converted value.
Obtains a value where the timespec value is converted into a microsecond value. timespec can represent nanosecond values.
ts
The pointer to the timespec structure.
Returns the converted value.
Decomposes microseconds into hours, minutes, seconds, and microseconds.
usec
The microsecond value.
h
OUT
Returns the hours. The hours value can exceed 24 (a day).
m
OUT
Returns the minutes.
s
OUT
Returns the seconds.
u
OUT
Returns the microseconds.
Parameter Map
Merges two key-value maps. If prefix_string is given, keys having this string as a prefix are changed to key names with this prefix removed, and then merged.
tag_string
The TAG string to be used for simple reference like log output, etc.
to_parameters
IN
OUT
The parameter map where the merged result is returned.
from_parameters
The parameter map to find the key-value elements to merge.
prefix_string
If it is not nullptr, it finds keys having the string specified in this argument as a prefix from from_parameters and uses keys with the prefix removed. For example, if prefix_string is channel1-, and a key named channel1-fps exists in from_parameters, the merged key becomes fps.
copy_prefixed_pair_only
If "true", it merges only key-value elements whose key prefix matches such as channel1-. If "false", when prefix_string is specified, it merges key elements with this prefix removed, and other keys are merged without modification.
Merges two key-value maps. If prefix_string is given, keys having this string as a prefix are changed to key names with this prefix removed, and then merged. If excluded_prefix_string is given, keys having this prefix are excluded from merging.
tag_string
The TAG string to be used for simple reference like log output, etc.
to_parameters
IN
OUT
The parameter map where the merged result is returned.
from_parameters
The parameter map to find the key-value elements to merge.
prefix_string
If it is not nullptr, it finds keys having the string specified in this argument as a prefix from from_parameters and uses keys with the prefix removed. For example, if prefix_string is channel1-, and a key named channel1-fps exists in from_parameters, the merged key becomes fps.
excluded_prefix_string
If it is not nullptr, it finds keys having the string specified in this argument as a prefix from from_parameters and excludes them from merging.
copy_prefixed_pair_only
Merges two key-value maps. Key names matching the regular expression string given as exclude_regex are excluded from merging.
tag_string
The TAG string to be used for simple reference like log output, etc.
IN
OUT
The parameter map where the merged result is returned.
from_parameters
The parameter map to find the key-value elements to merge.
exclude_regex
The regular expression to find key names of elements to exclude from merging.
Outputs a key-value map as log messages.
tag
The string pointer to be used as a TAG when outputting logs.
parameters
The key-value map to dump.
key
If it is not nullptr, it outputs only elements having this key value.
INI Files
The get_profile_section, get_profile_section_names, get_profile_string, and write_profile_string functions all manipulate the contents of files with an ini type extension.
An ini file is composed of multiple sections, and each section consists of <Key Name>=<Value> lines. # or ; are used as comment delimiters. If <Value> contains spaces, it starts with double quotes and ends with double quotes. Section names are case-sensitive.
; Comment
# Comment
[Section1 Name]
KeyName=Value # Comment
KeyName=Value ; Comment
An example is shown below:
[general]
key1=value1
key2="general value2" ; comment
[section1]
key1=section1_value1
key2="section1 value2" ; comment
[section2]
key1=section2_value1
key2="section2 value2" ; comment
Finds a section in the file and obtains the "Key=Value" list. If there is a comment on the corresponding line, the comment is also included. Each line in the list ends with a null character ('\0'). An additional null character ('\0') is appended at the very end.
section
The string pointer indicating the section name to find.
buf
OUT
The pointer to the buffer to store the "Key=Value" list.
buf_size
The buffer size. Measured in bytes.
file
The ini file path.
Returns the size of the "Key=Value" list on success. Measured in bytes. Returns -1 on failure.
:[general], __data=0xffffeafcf4c8, __size=47 of 47:
00000000 6b 65 79 31 3d 76 61 6c 75 65 31 00 6b 65 79 32 key1=value1.key2
00000010 3d 22 67 65 6e 65 72 61 6c 20 76 61 6c 75 65 32 ="general value2
00000020 22 20 20 3b 20 63 6f 6d 6d 65 6e 74 00 00 00 " ; comment...
Obtains a list of section names from the file. Each line ends with a null character ('\0'). An additional null character ('\0') is appended at the very end.
buf
The buffer pointer where the section name list will be stored.
buf_size
The buffer size. Measured in bytes.
file
The ini file path.
Returns the size of the section name list on success. Measured in bytes. Returns -1 on failure.
:section list, __data=0xffffeafcf4c8, __size=27 of 27:
00000000 67 65 6e 65 72 61 6c 00 73 65 63 74 69 6f 6e 31 general.section1
00000010 00 73 65 63 74 69 6f 6e 32 00 00 .section2..
Obtains the value of an entry having the key name key located inside section from the file.
section
The string pointer indicating the section name to find.
key
The string pointer indicating the key name inside the section to find.
default_str
The default value to be stored in the buffer if key cannot be found. If it is nullptr, and key is not found, it returns -1. An empty string is also allowed.
buf
OUT
The pointer to the buffer where the value will be stored.
buf_size
The buffer size. Measured in bytes.
file
The ini file path.
Returns the length of the value string on success. Returns 0 if it is an empty string. Returns -1 on failure.
Overwrites the value of an entry having the key name key located inside section with the str string in the file. If there are whitespace characters (spaces or tabs) inside str, double quotes are appended to the front and back of the string. If str is nullptr, it deletes the key entry.
section
The string pointer indicating the section name to find.
key
The string pointer indicating the key name inside the section to find.
str
The string pointer to overwrite with the new value.
file
The ini file path.
File Path
Obtains the directory path from a file path.
Returns the directory path.
Obtains the Leaf string consisting of the file name, delimiter (.), and extension from a file path.
Returns the Leaf string of the path. Returns an empty string if there is no Leaf.
Obtains the file name excluding the extension from a file path.
path
The file path.
make_lower
Converts to lowercase and returns if "true". Returns without case conversion if "false".
Returns the file name. Returns an empty string if there is no file name.
Returns the extension of the file from a file path.
path
The file path.
make_lower
Converts to lowercase and returns if "true". Returns without case conversion if "false".
The extension string. Returns an empty string if there is no extension.
Below are examples of applying the above functions to several paths:
path: /a/b/c/d/file.ext
get_path_dir: /a/b/c/d
get_path_leaf: file.ext
get_path_leaf_name: file
get_file_ext: ext
path: /a/b/c/d/
get_path_dir: /a/b/c/d
get_path_leaf:
get_path_leaf_name:
get_file_ext:
path: /a/b/c/d/file
get_path_dir: /a/b/c/d
get_path_leaf: file
get_path_leaf_name: file
get_file_ext:
path: /a/b/c/d/.ext
get_path_dir: /a/b/c/d
get_path_leaf: .ext
get_path_leaf_name:
get_file_ext: ext
path: /a/b/c/d/.
get_path_dir: /a/b/c/d
get_path_leaf: .
get_path_leaf_name:
get_file_ext:
Changes an absolute path into a canonical absolute path.
path
The absolute path. If it does not start with '/', it returns path as it is to c_path.
c_path
OUT
Returns the canonical absolute path.
Returns the start pointer of the canonical absolute path string.
Changes an absolute path into a canonical absolute path.
path
The absolute path. If it does not start with '/', it returns path as it is to c_path.
c_path
OUT
Returns the canonical absolute path.
Returns the start pointer of the canonical absolute path string.
File I/O
Writes a string to a file. Overwrites if the file already exists.
file_path
The file path.
value
The string pointer.
Returns the number of written bytes on success. Returns -1 on failure.
Appends a string to a file. Creates a new file if the file does not exist.
file_path
The file path.
value
The string pointer.
Returns the number of written bytes on success. Returns -1 on failure.
Reads a string from a text file.
file_path
The file path.
value
OUT
The buffer pointer to store the string.
size
The buffer size. Measured in bytes.
trim_trailing_lws
Removes whitespace characters (0x20, 0x0d, 0x0a, 0x09), etc. at the end of the last line string if "true".
Returns the number of read bytes on success. Returns -1 on failure.
Reads all lines from a text file consisting of multiple lines. A null character ('\0') is appended to the end of each line. An additional null character ('\0') is appended at the very end.
file_path
The file path.
value
OUT
The buffer pointer to store the entire string.
size
The buffer size. Measured in bytes. If the buffer size is too small, the total string data read will be truncated.
Returns the total number of read bytes on success. Returns -1 on failure.
Below is an example of HEX DUMPing the read data buffer:
readLinesFromFile, __data=0xfffff09f8d68, __size=206 of 206:
00000000 23 20 63 6f 6d 6d 65 6e 74 0a 00 0a 00 5b 67 65 # comment....[ge
00000010 6e 65 72 61 6c 5d 0a 00 6b 65 79 31 3d 76 61 6c neral]..key1=val
00000020 75 65 31 0a 00 6b 65 79 32 3d 22 67 65 6e 65 72 ue1..key2="gener
00000030 61 6c 20 76 61 6c 75 65 32 22 20 20 3b 20 63 6f al value2" ; co
00000040 6d 6d 65 6e 74 0a 00 0a 00 5b 73 65 63 74 69 6f mment....[sectio
00000050 6e 31 5d 0a 00 6b 65 79 32 3d 0a 00 6b 65 79 33 n1]..key2=..key3
00000060 3d 22 6e 65 77 20 6b 65 79 20 76 61 6c 75 65 22 ="new key value"
00000070 0a 00 6b 65 79 31 3d 22 73 68 6f 72 74 20 76 61 ..key1="short va
00000080 6c 75 65 22 0a 00 0a 00 5b 73 65 63 74 69 6f 6e lue"....[section
00000090 32 5d 0a 00 6b 65 79 31 3d 73 65 63 74 69 6f 6e 2]..key1=section
000000a0 32 5f 76 61 6c 75 65 31 0a 00 6b 65 79 32 3d 22 2_value1..key2="
000000b0 73 65 63 74 69 6f 6e 32 20 76 61 6c 75 65 32 22 section2 value2"
000000c0 20 20 3b 20 63 6f 6d 6d 65 6e 74 0a 00 00 ; comment...
Reads tail_count lines from the end of a text file consisting of multiple lines. The first line of the list is stored starting from the top line. The last line of the list is identical to the last line of the file.
file_path
The file path.
tail_count
The number of lines from the end. If the value is "0", it reads the entire lines.
lines
OUT
The string list reference where each line will be stored.
trim_trailing_lws
Removes whitespace characters (0x20, 0x0d, 0x0a, 0x09), etc. at the end of each line string if "true". Whitespace characters at the beginning of a line are always removed.
skip_empty_lines
Excludes empty strings if "true".
skip_bash_comment_lines
Excludes comment lines starting with '#' if "true".
Returns the size of the lines list on success. Returns -1 on failure.
Reads a text file where each line consists of <Key><delimiter><Value> to obtain a key-value map.
file_path
The file path.
parameters
Returns the converted key-value map.
delimiter
The delimiter between "Key" and "Value".
Returns the key-value map size on success. Returns 0 on failure.
Creates a file with the given access permission mode and writes data. Overwrites if the file already exists.
data
The pointer to the data to write.
length
The data length. Measured in bytes.
file_path
The file path.
mode
The access permission mode of the file to be created. An octal representation "0666" means "rw-rw-rw-".
Returns the number of written bytes on success. Returns -1 on failure.
Reads data as a uint8_t type from a file.
file_path
The file path.
data
OUT
The vector reference to store the read data.
Returns the total number of read bytes on success. Returns -1 on failure.
Reads data as a char type from a file.
file_path
The file path.
data
OUT
The vector reference to store the read data.
Returns the total number of read bytes on success. Returns -1 on failure.
Obtains the system folder path where the Oasis File System is mounted.
offs_mounted_path
OUT
The buffer pointer to store the mounted path.
size
The buffer size. Measured in bytes.
Returns the path string pointer if the mounted path is found. Returns nullptr if it cannot be found.
Verifies whether a path is located within the path mounted on the Oasis File System.
-
true: The path is located on the Oasis File System.
-
false: The path is not located on the Oasis File System.
Verifies whether a block device is mounted.
blkdev_path
The block device path to verify. For example, it is like /dev/mmcblk0p1.
blkdev_mounted_path
OUT
Stores the mounted folder path if it is not nullptr and is mounted.
blkdev_fs_type
OUT
Stores the file system type string if it is not nullptr and is mounted.
-
true: It is mounted.
-
false: It is not mounted.
Verifies whether a mounted path is a specific file system type.
path
The mounting path.
type
The file system type. Options include ext4, squashfs, devtmpfs, tmpfs, proc, sysfs, ubifs, fuse.ssfs, fuse.ntfs-3g, fuse.offs, etc. The file system types can be verified in /proc/filesystems.
-
true: It is the specific file system type.
-
false: It is not the specific file system type.
Resources and Environment Variables
Obtains the total CPU utilization.
Returns the percentage rate.
Obtains the CPU utilization of the calling process.
irix_mode
Calculates the sum of all CPU utilization in Irix mode if "true", and calculates the value divided by the number of processes in Solaris mode if "false".
Returns the percentage rate.
Obtains the available actual physical memory size. Returns the sum of unallocated memory and buffered or cached memory in bytes.
The available memory size. Measured in bytes.
Obtains the actual physical memory size currently used by the calling process.
The used memory size. Measured in bytes.
Obtains the number of threads created and used by the calling process.
Returns the thread count.
Terminates all processes with the specified program name. Sends a SIGTERM signal and waits for timeout_msec until all processes are terminated. If running processes are still found afterwards, it sends a SIGKILL signal. It does not wait further after sending the SIGKILL signal.
Reads a file where shell environment variables are stored, and obtains the environment variable names and values specified in the known_env_variables list. Useful when a user with high privileges (such as root) reads that user's environment variables from another user's files like source or .profile. It does not eval shell script statements inside the file.
home_dir
The $HOME value of the corresponding user.
env_file_path
The environment variable file path.
known_env_variables[]
The list of known environment variable names. The last element must be nullptr.
resolved_variables
OUT
Returns a key-value map with environment variable names as key names.
sources
The list of paths of other environment variable files referenced when referencing other environment variable files inside env_file_path.
When the /etc/profile file contents are as follows:
export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
if [ "$PS1" ]; then
if [ "`id -u`" -eq 0 ]; then
export PS1='# '
else
export PS1='$ '
fi
fi
export EDITOR='/bin/vi'
# Source configuration files from /etc/profile.d
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done
unset i
When wishing to know the PATH and EDITOR environment variable values:
const char *known_env_variables[] = { "PATH", "EDITOR", nullptr };
key_value_map_t vars;
std::list<std::string> sources;
loadEnvironmentVariables("/" , "/etc/profile" , known_env_variables , vars , sources);
dumpParameters("loadEnvironmentVariables", vars);
Executing it displays results like the following:
loadEnvironmentVariables parameters[PATH] /bin:/sbin:/usr/bin:/usr/sbin
loadEnvironmentVariables parameters[EDITOR] /bin/vi