Header And Logo

PostgreSQL
| The world's most advanced open source database.

gethostname.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * gethostname.c
00004  *    gethostname using uname
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  * IDENTIFICATION
00010  *    src/port/gethostname.c
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 
00015 #include "c.h"
00016 
00017 #include <sys/utsname.h>
00018 
00019 int
00020 gethostname(char *name, int namelen)
00021 {
00022     static struct utsname mname;
00023     static int  called = 0;
00024 
00025     if (!called)
00026     {
00027         called++;
00028         uname(&mname);
00029     }
00030     strncpy(name, mname.nodename, (SYS_NMLN < namelen ? SYS_NMLN : namelen));
00031 
00032     return 0;
00033 }