Main Page Class Hierarchy Compound List File List Compound Members File Members

# getsysname_ew.c

Go to the documentation of this file.

    00001
    00002 /*
    00003  *   THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE
    00004  *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
    00005  *
    00006  *    $Id: getsysname__ew_8c-source.html 2161 2006-05-19 16:55:03Z paulf $
    00007  *
    00008  *    Revision history:
    00009  *     $Log$
    00009  *     Revision 1.1  2006/05/19 16:55:02  paulf
    00009  *     first inclusion
    00009  *
    00010  *     Revision 1.1  2000/02/14 18:53:30  lucky
    00011  *     Initial revision
    00012  *
    00013  *
    00014  */
    00015
    00016 /*
    00017  *  getsysname_ew.c  - OS/2 version
    00018  *
    00019  *  Earthworm utility for getting the system name from the system
    00020  *
    00021  */
    00022
    00023 #include <stdio.h>
    00024 #include <stdlib.h>
    00025 #include <string.h>
    00026
    00027 int getsysname_ew( char *sysname, int length )
    00028 {
    00029    char *str;
    00030
    00031 /* Get system name from environment variable HOSTNAME
    00032    **************************************************/
    00033    str = getenv( "HOSTNAME" );
    00034
    00035    if ( str == (char *) NULL )
    00036    {
    00037       fprintf( stderr,
    00038               "getsysname_ew: Environment variable HOSTNAME not defined.\n" );
    00039       return( -1 );
    00040    }
    00041
    00042    if ( *str == '\0' )
    00043    {
    00044       fprintf( stderr, "getsysname_ew: Environment variable HOSTNAME" );
    00045       fprintf( stderr, " defined, but has no value.\n" );
    00046       return( -1 );
    00047    }
    00048
    00049 /* Copy system name to target address
    00050  ************************************/
    00051    if( strlen( str ) >= (size_t) length )
    00052    {
    00053       fprintf( stderr, "getsysname_ew: HOSTNAME too long for target address.\n" );
    00054       return( -1 );
    00055    }
    00056
    00057    strcpy( sysname, str );
    00058    return( 0 );
    00059 }
    00060
    00061