aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest/hostname.c
blob: ca7fccaf81ee8832589d04a17712de9c45e0212a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*****************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 */

#include <string.h>
#include <unistd.h>

#define HOSTNAME "curlhost"
#define HOSTNAME_LEN sizeof(HOSTNAME)

/* 
 * we force our own host name, in order to make some tests machine independent
 */
int gethostname(char *name, size_t namelen) {
  char buff[HOSTNAME_LEN + /* terminating zero */ 1];
  size_t max = (namelen < HOSTNAME_LEN)
    ? namelen
    : HOSTNAME_LEN;

  if(!name || !namelen)
    return -1;

  strcpy(buff, HOSTNAME);
  buff[max - 1] = '\0';
  strcpy(name, buff);
  return 0;
};