postgresql/src/port/gethostname.c

36 lines
762 B
C
Raw Normal View History

2003-11-12 00:52:45 +01:00
/*-------------------------------------------------------------------------
*
* gethostname.c
* gethostname using uname
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
2003-11-12 00:52:45 +01:00
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/port/gethostname.c,v 1.6 2004/12/31 22:03:53 pgsql Exp $
2003-11-12 00:52:45 +01:00
*
*-------------------------------------------------------------------------
*/
#include "c.h"
#include <string.h>
#include <sys/utsname.h>
int
gethostname(char *name, int namelen)
{
static struct utsname mname;
static int called = 0;
if (!called)
{
called++;
uname(&mname);
}
strncpy(name, mname.nodename, (SYS_NMLN < namelen ? SYS_NMLN : namelen));
1998-09-01 05:29:17 +02:00
return 0;
}