home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff319.lzh / CNewsSrc / cnews.orig.lzh / libcnews / hostname.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  980b  |  45 lines

  1. /*
  2.  * hostname - return the Usenet name of this machine
  3.  *
  4.  * One interesting possibility would be to assume that the first
  5.  * name in the sys file is our Usenet name, unless it is "ME",
  6.  * which would require our current strategy anyway.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <sys/types.h>
  11.  
  12. #include "libc.h"
  13. #include "news.h"
  14. #include "config.h"
  15.  
  16. /* 2BSD funniness */
  17. #ifdef BSD2_10
  18. # include <short_names.h>
  19. #endif
  20.  
  21. #ifndef NAMEFILE
  22. #define NAMEFILE ctlfile("whoami")
  23. #endif
  24.  
  25. char *
  26. hostname()            /* return this Usenet machine's name */
  27. {
  28.     static char name[MAXHOST];
  29.  
  30.     if (name[0] == '\0') {    /* try to get the "news hostname" */
  31.         register FILE *fp;
  32.  
  33.         fp = fopenclex(NAMEFILE, "r");
  34.         if (fp != NULL) {
  35.             (void) fgets(name, sizeof name, fp);
  36.             (void) nfclose(fp);
  37.             if (name[0] != '\0' && name[strlen(name) - 1] == '\n')
  38.                 name[strlen(name) - 1] = '\0';
  39.         }
  40.     }
  41.     if (name[0] == '\0')    /* else use the ordinary hostname */
  42.         (void) gethostname(name, sizeof name);
  43.     return name;
  44. }
  45.