]> granicus.if.org Git - postgresql/blob - src/port/gethostname.c
Revise psql pattern-matching switches as per discussion. The rule is now
[postgresql] / src / port / gethostname.c
1 /*-------------------------------------------------------------------------
2  *
3  * gethostname.c
4  *        gethostname using uname
5  *
6  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  *        $PostgreSQL: pgsql/src/port/gethostname.c,v 1.8 2006/03/05 15:59:10 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14
15 #include "c.h"
16
17 #include <sys/utsname.h>
18
19 int
20 gethostname(char *name, int namelen)
21 {
22         static struct utsname mname;
23         static int      called = 0;
24
25         if (!called)
26         {
27                 called++;
28                 uname(&mname);
29         }
30         strncpy(name, mname.nodename, (SYS_NMLN < namelen ? SYS_NMLN : namelen));
31
32         return 0;
33 }