Back to index

glibc  2.9
gethostname.c File Reference
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>

Go to the source code of this file.


int __gethostname (char *name, size_t len)

Function Documentation

int __gethostname ( char *  name,
size_t  len 

Definition at line 28 of file gethostname.c.

  struct utsname buf;
  size_t node_len;

  if (uname (&buf))
    return -1;

  node_len = strlen (buf.nodename) + 1;
  memcpy (name, buf.nodename, len < node_len ? len : node_len);

  if (node_len > len)
      __set_errno (ENAMETOOLONG);
      return -1;
  return 0;

Here is the call graph for this function: