getdomainname.c 1.0 KB

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