getdomainname.c 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. int
  14. #ifndef __UCLIBC_BSD_SPECIFIC__
  15. attribute_hidden
  16. #endif
  17. getdomainname(char *name, size_t len)
  18. {
  19. struct utsname uts;
  20. if (name == NULL) {
  21. __set_errno(EINVAL);
  22. return -1;
  23. }
  24. if (uname(&uts) == -1) return -1;
  25. #ifdef __USE_GNU
  26. if (strlen(uts.domainname)+1 > len) {
  27. #else
  28. if (strlen(uts.__domainname)+1 > len) {
  29. #endif
  30. __set_errno(EINVAL);
  31. return -1;
  32. }
  33. #ifdef __USE_GNU
  34. strcpy(name, uts.domainname);
  35. #else
  36. strcpy(name, uts.__domainname);
  37. #endif
  38. return 0;
  39. }
  40. # ifdef __UCLIBC_BSD_SPECIFIC__
  41. libc_hidden_def(getdomainname)
  42. # endif
  43. #endif