gethostname.c (92986) | gethostname.c (119140) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 21 unchanged lines hidden (view full) --- 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) 35static char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; 36#endif /* LIBC_SCCS and not lint */ 37#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 21 unchanged lines hidden (view full) --- 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) 35static char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; 36#endif /* LIBC_SCCS and not lint */ 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/lib/libc/gen/gethostname.c 92986 2002-03-22 21:53:29Z obrien $"); | 38__FBSDID("$FreeBSD: head/lib/libc/gen/gethostname.c 119140 2003-08-19 20:38:44Z wollman $"); |
39 40#include <sys/param.h> 41#include <sys/sysctl.h> 42 | 39 40#include <sys/param.h> 41#include <sys/sysctl.h> 42 |
43#include <errno.h> 44 |
|
43int 44gethostname(name, namelen) 45 char *name; | 45int 46gethostname(name, namelen) 47 char *name; |
46 int namelen; | 48 size_t namelen; |
47{ 48 int mib[2]; | 49{ 50 int mib[2]; |
49 size_t size; | |
50 51 mib[0] = CTL_KERN; 52 mib[1] = KERN_HOSTNAME; | 51 52 mib[0] = CTL_KERN; 53 mib[1] = KERN_HOSTNAME; |
53 size = namelen; 54 if (sysctl(mib, 2, name, &size, NULL, 0) == -1) | 54 if (sysctl(mib, 2, name, &namelen, NULL, 0) == -1) { 55 if (errno == ENOMEM) 56 errno = ENAMETOOLONG; |
55 return (-1); | 57 return (-1); |
58 } |
|
56 return (0); 57} | 59 return (0); 60} |