summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/gethostname.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gen/gethostname.c')
-rw-r--r--lib/libc/gen/gethostname.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libc/gen/gethostname.c b/lib/libc/gen/gethostname.c
index a5cd290..37b52ca 100644
--- a/lib/libc/gen/gethostname.c
+++ b/lib/libc/gen/gethostname.c
@@ -40,18 +40,21 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/sysctl.h>
+#include <errno.h>
+
int
gethostname(name, namelen)
char *name;
- int namelen;
+ size_t namelen;
{
int mib[2];
- size_t size;
mib[0] = CTL_KERN;
mib[1] = KERN_HOSTNAME;
- size = namelen;
- if (sysctl(mib, 2, name, &size, NULL, 0) == -1)
+ if (sysctl(mib, 2, name, &namelen, NULL, 0) == -1) {
+ if (errno == ENOMEM)
+ errno = ENAMETOOLONG;
return (-1);
+ }
return (0);
}
OpenPOWER on IntegriCloud