Next: , Previous: , Up: System Management   [Contents][Index]


31.2 Platform Type Identification

You can use the uname function to find out some information about the type of computer your program is running on. This function and the associated data type are declared in the header file sys/utsname.h.

As a bonus, uname also gives some information identifying the particular system your program is running on. This is the same information which you can get with functions targeted to this purpose described in Host Identification.

Data Type: struct utsname

The utsname structure is used to hold information returned by the uname function. It has the following members:

char sysname[]

This is the name of the operating system in use.

char release[]

This is the current release level of the operating system implementation.

char version[]

This is the current version level within the release of the operating system.

char machine[]

This is a description of the type of hardware that is in use.

Some systems provide a mechanism to interrogate the kernel directly for this information. On systems without such a mechanism, the GNU C Library fills in this field based on the configuration name that was specified when building and installing the library.

GNU uses a three-part name to describe a system configuration; the three parts are cpu, manufacturer and system-type, and they are separated with dashes. Any possible combination of three names is potentially meaningful, but most such combinations are meaningless in practice and even the meaningful ones are not necessarily supported by any particular GNU program.

Since the value in machine is supposed to describe just the hardware, it consists of the first two parts of the configuration name: ‘cpu-manufacturer’. For example, it might be one of these:

"sparc-sun", "i386-anything", "m68k-hp", "m68k-sony", "m68k-sun", "mips-dec"

char nodename[]

This is the host name of this particular computer. In the GNU C Library, the value is the same as that returned by gethostname; see Host Identification.

 gethostname() is implemented with a call to uname().

char domainname[]

This is the NIS or YP domain name. It is the same value returned by getdomainname; see Host Identification. This element is a relatively recent invention and use of it is not as portable as use of the rest of the structure.

Function: int uname (struct utsname *info)

Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

The uname function fills in the structure pointed to by info with information about the operating system and host machine. A non-negative value indicates that the data was successfully stored.

-1 as the value indicates an error. The only error possible is EFAULT, which we normally don’t mention as it is always a possibility.


Next: , Previous: , Up: System Management   [Contents][Index]