getdomainname.c 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <features.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include <errno.h>
  11. #include <sys/utsname.h>
  12. #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
  13. /* Experimentally off - libc_hidden_proto(strlen) */
  14. /* Experimentally off - libc_hidden_proto(strcpy) */
  15. /* libc_hidden_proto(uname) */
  16. int getdomainname(char *name, size_t len)
  17. {
  18. struct utsname uts;
  19. if (name == NULL) {
  20. __set_errno(EINVAL);
  21. return -1;
  22. }
  23. if (uname(&uts) == -1) return -1;
  24. #ifdef __USE_GNU
  25. if (strlen(uts.domainname)+1 > len) {
  26. #else
  27. if (strlen(uts.__domainname)+1 > len) {
  28. #endif
  29. __set_errno(EINVAL);
  30. return -1;
  31. }
  32. #ifdef __USE_GNU
  33. strcpy(name, uts.domainname);
  34. #else
  35. strcpy(name, uts.__domainname);
  36. #endif
  37. return 0;
  38. }
  39. libc_hidden_def(getdomainname)
  40. #endif