postgresql/src/port/gethostname.c

36 lines
764 B
C
Raw Normal View History

2003-11-12 00:52:45 +01:00
/*-------------------------------------------------------------------------
*
* gethostname.c
* gethostname using uname
*
2004-08-29 06:13:13 +02:00
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
2003-11-12 00:52:45 +01:00
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
2004-08-29 06:13:13 +02:00
* $PostgreSQL: pgsql/src/port/gethostname.c,v 1.5 2004/08/29 04:13:12 momjian 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;
}