blob: 59df566d9465625f28f47dcdaf979cf44c5681a7 [file] [log] [blame]
Rich Felkerc87584a2012-09-09 16:50:20 -04001#define _GNU_SOURCE
Rich Felker0b44a032011-02-12 00:22:29 -05002#include <unistd.h>
3#include <sys/utsname.h>
4#include <string.h>
Rich Felkerc87584a2012-09-09 16:50:20 -04005#include <errno.h>
Rich Felker0b44a032011-02-12 00:22:29 -05006
7int getdomainname(char *name, size_t len)
8{
Rich Felkerc87584a2012-09-09 16:50:20 -04009 struct utsname temp;
10 uname(&temp);
11 if (!len || strlen(temp.domainname) >= len) {
12 errno = EINVAL;
13 return -1;
14 }
15 strcpy(name, temp.domainname);
Rich Felker0b44a032011-02-12 00:22:29 -050016 return 0;
17}