training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

ex-6.3.c (707B)


      1 /*
      2  * Advanced Programming in the UNIX(r) Environment
      3  *
      4  * Exercise 6.3
      5  *
      6  * NOTE: operating system field has not been implemented
      7  *       since a Makefile is needed for this purpose.
      8 */
      9 
     10 #include <stdio.h>
     11 #include <stdlib.h>
     12 #include <sys/utsname.h>
     13 
     14 int
     15 main(void)
     16 {
     17    struct utsname un;
     18 
     19    /* Get the informations */
     20    if( uname(&un) == -1 ) {
     21       perror("uname");
     22       return EXIT_FAILURE;
     23    }
     24 
     25    /* Show the informations */
     26    printf("%s %s %s %s %s",
     27       un.sysname, un.nodename, un.release,
     28       un.version, un.machine);
     29    
     30 #if defined(__Linux__)
     31 # define _UTSNAME_DOMAIN_LENGHT 1
     32    printf(" %s", un.domainname);
     33 #endif
     34 
     35    printf("\n");
     36 
     37    return EXIT_SUCCESS;
     38 } /* eof main() */
     39