common_util
Loading...
Searching...
No Matches
Enumerations | Functions
sysutil.h File Reference

Common system utilities. More...

#include <cstdint>
#include <string>

Go to the source code of this file.

Enumerations

enum class  cutl::endian { little , big }
 Endianness type. More...
 
enum class  cutl::os_platform {
  os_windows , os_macos , os_linux , os_unix ,
  os_unknown
}
 Operating system platform type. More...
 

Functions

os_platform cutl::platform_type ()
 Get the platform type for the current operating system.
 
std::string cutl::architecture ()
 Get the architecture of the cpu processor(or operating system).
 
std::string cutl::platform_name (os_platform type)
 Get the platform name for the current operating system.
 
std::string cutl::cpp_stl_version ()
 Get the C++ standard library version.
 
uint16_t cutl::program_bit ()
 Get the program bit.
 
endian cutl::endian_type ()
 Get the program endianness.
 
uint16_t cutl::byteswap (uint16_t value)
 Byteswap a 16-bit value.
 
uint32_t cutl::byteswap (uint32_t value)
 Byteswap a 32-bit value.
 
uint64_t cutl::byteswap (uint64_t value)
 Byteswap a 64-bit value.
 
void cutl::byteswap (uint8_t *data, uint32_t size)
 Byteswap an array of bytes.
 
bool cutl::system (const std::string &cmd)
 Execute a system command.
 
bool cutl::callcmd (const std::string &cmd, std::string &result)
 Execute a system command and get the output.
 
std::string cutl::getenv (const std::string &name, const std::string &default_value)
 Get an environment variable.
 
std::string cutl::getcwd ()
 Get the working directory of the current excuting process.
 
std::string cutl::homedir ()
 Get the home dir for the current user.
 

Detailed Description

Common system utilities.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations.

Author
spencer.luo
Date
2024-05-13

Enumeration Type Documentation

◆ endian

enum class cutl::endian
strong

Endianness type.

Enumerator
little 

little endian

big 

big endian

◆ os_platform

enum class cutl::os_platform
strong

Operating system platform type.

Enumerator
os_windows 

Windows

os_macos 

macOS

os_linux 

Linux

os_unix 

Unix

os_unknown 

Unknown

Function Documentation

◆ architecture()

std::string cutl::architecture ( )

Get the architecture of the cpu processor(or operating system).

Returns
std::string the architecture.

◆ byteswap() [1/4]

uint16_t cutl::byteswap ( uint16_t value)

Byteswap a 16-bit value.

Parameters
valuethe value to byteswap.
Returns
uint16_t the byteswapped value.

◆ byteswap() [2/4]

uint32_t cutl::byteswap ( uint32_t value)

Byteswap a 32-bit value.

Parameters
valuethe value to byteswap.
Returns
uint32_t the byteswapped value.

◆ byteswap() [3/4]

uint64_t cutl::byteswap ( uint64_t value)

Byteswap a 64-bit value.

Parameters
valuethe value to byteswap.
Returns
uint64_t the byteswapped value.

◆ byteswap() [4/4]

void cutl::byteswap ( uint8_t * data,
uint32_t size )

Byteswap an array of bytes.

Parameters
datathe array of bytes to byteswap.
sizethe size of the array.

◆ callcmd()

bool cutl::callcmd ( const std::string & cmd,
std::string & result )

Execute a system command and get the output.

Parameters
cmdthe command to be executed.
resultthe output of the command.
Returns
true if the command is executed successfully, false otherwise.

◆ cpp_stl_version()

std::string cutl::cpp_stl_version ( )

Get the C++ standard library version.

Returns
std::string the C++ standard library version.

◆ endian_type()

endian cutl::endian_type ( )

Get the program endianness.

Returns
endian the program endianness.

◆ getcwd()

std::string cutl::getcwd ( )

Get the working directory of the current excuting process.

Returns
file path of the working directory

◆ getenv()

std::string cutl::getenv ( const std::string & name,
const std::string & default_value )

Get an environment variable.

Parameters
namethe name of the environment variable.
default_valuethe default value if the variable is not found.
Returns
std::string the value of the environment variable.

◆ homedir()

std::string cutl::homedir ( )

Get the home dir for the current user.

Returns
std::string the home directory.

◆ platform_name()

std::string cutl::platform_name ( os_platform type)

Get the platform name for the current operating system.

Parameters
typethe operating system platform type.
Returns
std::string the platform name.

◆ platform_type()

os_platform cutl::platform_type ( )

Get the platform type for the current operating system.

Returns
platform The operating system platform type.

◆ program_bit()

uint16_t cutl::program_bit ( )

Get the program bit.

Returns
uint16_t the program bit.

◆ system()

bool cutl::system ( const std::string & cmd)

Execute a system command.

Parameters
cmdthe command to be executed.
Returns
true if the command is executed successfully, false otherwise.