getdnnm.c 715 B

1234567891011121314151617181920212223242526272829303132333435363738
  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(strlen)
  13. libc_hidden_proto(strcpy)
  14. libc_hidden_proto(uname)
  15. int
  16. getdomainname(char *name, size_t len)
  17. {
  18. struct utsname uts;
  19. if (name == NULL) {
  20. __set_errno(EINVAL);
  21. return -1;
  22. }
  23. if (uname(&uts) == -1) return -1;
  24. if (strlen(uts.domainname)+1 > len) {
  25. __set_errno(EINVAL);
  26. return -1;
  27. }
  28. strcpy(name, uts.domainname);
  29. return 0;
  30. }
  31. libc_hidden_proto(getdomainname)
  32. libc_hidden_def(getdomainname)