uname()

Get information about the operating system

Synopsis:

#include <sys/utsname.h>

int uname( struct utsname * name );

Arguments:

name
A pointer to a utsname where the function can store the information; see below.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The uname() function stores information about the current operating system in the structure pointed to by the argument name.

The system name structure, utsname, is defined in <sys/utsname.h>, and contains at least the following structure members:

char* sysname
The name of the OS.

Note: Although this member gives the name of the OS as “QNX”, its official product name is “QNX Neutrino”.

char* nodename
The name of this node.
char* release
The current release level.
char* version
The current version level.
char* machine
The hardware type.

Each of these items is a null-terminated character array.

Returns:

0
Success.
-1
An error occurred (errno is set).

Examples:

/*
 * The following program prints some information about the
 * system it's running on.
 */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/utsname.h>

int main( void )
  {
    struct utsname sysinfo;

    if( uname( &sysinfo ) == -1 ) {
       perror( "uname" );
       return EXIT_FAILURE;
    }
    printf( "system name  : %s\n", sysinfo.sysname );
    printf( "node name    : %s\n", sysinfo.nodename );
    printf( "release name : %s\n", sysinfo.release );
    printf( "version name : %s\n", sysinfo.version );
    return EXIT_SUCCESS;
  }

Classification:

POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

errno

uname in the Utilities Reference