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 7 #include <features.h> 8 #include <stdlib.h> 9 #include <string.h> 10 #include <unistd.h> 11 #include <errno.h> 12 #include <sys/utsname.h> 13 14 #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98) 15 16 int 17 #ifndef __UCLIBC_BSD_SPECIFIC__ 18 attribute_hidden 19 #endif getdomainname(char * name,size_t len)20getdomainname(char *name, size_t len) 21 { 22 struct utsname uts; 23 24 if (name == NULL) { 25 __set_errno(EINVAL); 26 return -1; 27 } 28 29 if (uname(&uts) == -1) return -1; 30 31 #ifdef __USE_GNU 32 if (strlen(uts.domainname)+1 > len) { 33 #else 34 if (strlen(uts.__domainname)+1 > len) { 35 #endif 36 __set_errno(EINVAL); 37 return -1; 38 } 39 #ifdef __USE_GNU 40 strcpy(name, uts.domainname); 41 #else 42 strcpy(name, uts.__domainname); 43 #endif 44 return 0; 45 } 46 # ifdef __UCLIBC_BSD_SPECIFIC__ 47 libc_hidden_def(getdomainname) 48 # endif 49 #endif 50