Salome HOME
projects
/
modules
/
yacs.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
PR: merge branch CCAR_br1
[modules/yacs.git]
/
src
/
Utils
/
OpUtil.cxx
1
using namespace std;
2
#include "utilities.h"
3
#include "OpUtil.hxx"
4
#include <unistd.h>
5
#include <errno.h>
6
#include <string.h>
7
8
int gethostname(char *name, size_t len);
9
10
string GetHostname()
11
{
12
int ls = 100, r = 0;
13
char *s;
14
15
while (ls < 10000) {
16
ls *= 2;
17
s = new char[ls];
18
r = gethostname(s, ls-1);
19
switch (r)
20
{
21
case 0:
22
break;
23
default:
24
#ifdef EINVAL
25
case EINVAL:
26
#endif
27
#ifdef ENAMETOOLONG
28
case ENAMETOOLONG:
29
#endif
30
delete [] s;
31
continue;
32
}
33
}
34
35
if (r != 0) {
36
s = new char[50];
37
strcpy(s, "localhost");
38
}
39
40
// remove all after '.'
41
char *aDot = (strchr(s,'.'));
42
if (aDot) aDot[0] = '\0';
43
44
string p = s;
45
delete [] s;
46
return p;
47
}
48