home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xmu / GetHost.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-14  |  1.9 KB  |  59 lines

  1. /*
  2.  * $XConsortium: GetHost.c,v 1.2 90/12/14 19:24:38 converse Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Jim Fulton, MIT X Consortium
  24.  *
  25.  * _XGetHostname - similar to gethostname but allows special processing.
  26.  */
  27.  
  28. int XmuGetHostname (buf, maxlen)
  29.     char *buf;
  30.     int maxlen;
  31. {
  32.     int len;
  33.  
  34. #ifdef USG
  35. #define NEED_UTSNAME
  36. #endif
  37.  
  38. #ifdef NEED_UTSNAME
  39. #include <sys/utsname.h>
  40.     /*
  41.      * same host name crock as in server and xinit.
  42.      */
  43.     struct utsname name;
  44.  
  45.     uname (&name);
  46.     len = strlen (name.nodename);
  47.     if (len >= maxlen) len = maxlen - 1;
  48.     strncpy (buf, name.nodename, len);
  49.     buf[len] = '\0';
  50. #else
  51.     buf[0] = '\0';
  52.     (void) gethostname (buf, maxlen);
  53.     buf [maxlen - 1] = '\0';
  54.     len = strlen(buf);
  55. #endif /* hpux */
  56.     return len;
  57. }
  58.  
  59.