Actual source code: fhost.c
1: /*$Id: fhost.c,v 1.49 2001/03/23 23:20:45 balay Exp $*/
2: /*
3: Code for manipulating files.
4: */
5: #include petsc.h
6: #include petscsys.h
7: #if defined(PETSC_HAVE_STDLIB_H)
8: #include <stdlib.h>
9: #endif
10: #if !defined(PARCH_win32)
11: #include <sys/utsname.h>
12: #endif
13: #if defined(PARCH_win32)
14: #include <windows.h>
15: #include <io.h>
16: #include <direct.h>
17: #endif
18: #if defined (PARCH_win32_gnu)
19: #include <windows.h>
20: #endif
21: #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
22: #include <sys/systeminfo.h>
23: #endif
24: #if defined(PETSC_HAVE_UNISTD_H)
25: #include <unistd.h>
26: #endif
27: #include "petscfix.h"
29: /*@C
30: PetscGetHostName - Returns the name of the host. This attempts to
31: return the entire Internet name. It may not return the same name
32: as MPI_Get_processor_name().
34: Not Collective
36: Input Parameter:
37: . nlen - length of name
39: Output Parameter:
40: . name - contains host name. Must be long enough to hold the name
41: This is the fully qualified name, including the domain.
43: Level: developer
45: Concepts: machine name
46: Concepts: host name
48: .seealso: PetscGetUserName()
49: @*/
50: int PetscGetHostName(char name[],int nlen)
51: {
52: char *domain;
53: int ierr;
54: PetscTruth flag;
55: #if defined(PETSC_HAVE_UNAME)
56: struct utsname utname;
57: #endif
58: #if defined(PETSC_HAVE_GETDOMAINNAME) && !defined(PETSC_HAVE_SYSINFO_3ARG)
59: PetscTruth match;
60: #endif
64: #if defined(PARCH_win32) || defined(PARCH_win32_gnu)
65: GetComputerName((LPTSTR)name,(LPDWORD)(&nlen));
66: #elif defined(PETSC_HAVE_UNAME)
67: uname(&utname);
68: PetscStrncpy(name,utname.nodename,nlen);
69: #elif defined(PETSC_HAVE_GETHOSTNAME)
70: gethostname(name,nlen);
71: #elif defined(PETSC_HAVE_SYSINFO_3ARG)
72: sysinfo(SI_HOSTNAME,name,nlen);
73: #endif
75: /* See if this name includes the domain */
76: PetscStrchr(name,'.',&domain);
77: if (!domain) {
78: int l;
79: PetscStrlen(name,&l);
80: if (l == nlen) {name[nlen-1] = 0; return(0);}
81: name[l++] = '.';
82: #if defined(PETSC_HAVE_SYSINFO_3ARG)
83: sysinfo(SI_SRPC_DOMAIN,name+l,nlen-l);
84: #elif defined(PETSC_HAVE_GETDOMAINNAME)
85: getdomainname(name+l,nlen - l);
86: /* change domain name if it is an ANL crap one */
87: PetscStrcmp(name+l,"qazwsxedc",&match);
88: if (match) {
89: PetscStrncpy(name+l,"mcs.anl.gov",nlen-12);
90: }
91: #endif
92: /*
93: Some machines (Linx) default to (none) if not
94: configured with a particular domain name.
95: */
96: PetscStrncmp(name+l,"(none)",6,&flag);
97: if (flag) {
98: name[l-1] = 0;
99: }
100: }
101: name[nlen-1] = 0;
102: return(0);
103: }