getdomainname.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #if !defined __UCLIBC_BSD_SPECIFIC__
  17. extern int getdomainname (char *__name, size_t __len)
  18. __THROW __nonnull ((1)) __wur;
  19. #endif
  20. extern __typeof(getdomainname) __libc_getdomainname;
  21. libc_hidden_proto(__libc_getdomainname)
  22. int __libc_getdomainname(char *name, size_t len)
  23. {
  24. struct utsname uts;
  25. if (name == NULL) {
  26. __set_errno(EINVAL);
  27. return -1;
  28. }
  29. if (uname(&uts) == -1) return -1;
  30. #ifdef __USE_GNU
  31. if (strlen(uts.domainname)+1 > len) {
  32. #else
  33. if (strlen(uts.__domainname)+1 > len) {
  34. #endif
  35. __set_errno(EINVAL);
  36. return -1;
  37. }
  38. #ifdef __USE_GNU
  39. strcpy(name, uts.domainname);
  40. #else
  41. strcpy(name, uts.__domainname);
  42. #endif
  43. return 0;
  44. }
  45. libc_hidden_def(__libc_getdomainname)
  46. #if defined __UCLIBC_BSD_SPECIFIC__
  47. libc_hidden_proto(getdomainname)
  48. weak_alias(__libc_getdomainname,getdomainname)
  49. libc_hidden_weak(getdomainname)
  50. #endif /* __UCLIBC_BSD_SPECIFIC__ */
  51. #endif