getdnnm.c 856 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. libc_hidden_proto(getdomainname)
  13. libc_hidden_proto(strlen)
  14. libc_hidden_proto(strcpy)
  15. libc_hidden_proto(uname)
  16. int
  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. libc_hidden_def(getdomainname)