mach_name.c 770 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <unistd.h>
  2. #include <grass/gis.h>
  3. #include <grass/config.h>
  4. #ifdef HAVE_SYS_UTSNAME_H
  5. #include <sys/utsname.h>
  6. #endif
  7. /* this routine returns a name for the machine
  8. * it returns the empty string, if this info
  9. * not available (it never returns a NULL pointer)
  10. *
  11. * the name is stored in a static array and the pointer to this
  12. * array is returned.
  13. *
  14. */
  15. char *G__machine_name(void)
  16. {
  17. static char name[128];
  18. if (*name)
  19. return name;
  20. #if defined(HAVE_GETHOSTNAME)
  21. gethostname(name, sizeof(name));
  22. name[sizeof(name) - 1] = 0; /* make sure NUL terminated */
  23. #elif defined(HAVE_SYS_UTSNAME_H)
  24. {
  25. struct utsname attname;
  26. uname(&attname);
  27. strcpy(name, attname.nodename);
  28. }
  29. #elif
  30. strcpy(name, "unknown");
  31. #endif
  32. return name;
  33. }