BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdls_osutil

Detailed Description

Outline

Purpose

Provide utilities related to the operating system.

Classes

See also

Description

This component provides a namespace, bdls::OsUtil, containing utility functions for retrieving information at runtime about the operating system in which this task is running.

Usage

This section illustrates intended use of this component.

Example 1: Display OS Name, Version and Patch Level

The following example demonstrates using getOsInfo to obtain information about the operating system at runtime and writing it to the console.

First, we create strings for the operating system name (osName), version (osVersion), and patch (osPatch), and then call getOsInfo to load these strings with values for the operating system the task is executing in:

bsl::string version;
Definition bslstl_string.h:1281

Then, we use the standard streams to write the operating system version information to the console, or an error message of failure:

const int rc = bdls::OsUtil::getOsInfo(&name, &version, &patch);
if (rc == 0) {
bsl::cout << "OS Name: " << name << "\n"
<< "Version: " << version << "\n"
<< "Patch: " << patch << "\n";
} else {
bsl::cout << "Cannot determine OS name and version\n";
}
static int getOsInfo(bsl::string *osName, bsl::string *osVersion, bsl::string *osPatch)

Finally, the resulting console output on the Red Hat Enterprise Linux Server 5.5 would be

OS Name: Linux
Version: 2.6.18-194.32.1.el5
Patch: #1 SMP Mon Dec 20 10:52:42 EST 2010

On Windows 7 SP1, the display would be

OS Name: Windows
Version: 6.1
Patch: Service Pack 1