getdnnm.c 716 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 <stdlib.h>
  7. #include <string.h>
  8. #include <unistd.h>
  9. #include <errno.h>
  10. #define __USE_GNU
  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. if (strlen(uts.domainname)+1 > len) {
  26. __set_errno(EINVAL);
  27. return -1;
  28. }
  29. strcpy(name, uts.domainname);
  30. return 0;
  31. }
  32. libc_hidden_def(getdomainname)