1 /* $NetBSD: findconfig.c,v 1.1.1.1 2009/12/13 16:55:02 kardel Exp $ */ 2 3 4 #ifdef HAVE_CONFIG_H 5 # include <config.h> 6 #endif 7 8 #ifdef NEED_HPUX_FINDCONFIG 9 #include <string.h> 10 #include <stdio.h> 11 #include <sys/types.h> 12 #include <sys/stat.h> 13 #include <sys/utsname.h> 14 #include <unistd.h> 15 16 const char * 17 FindConfig( 18 const char *base 19 ) 20 { 21 static char result[BUFSIZ]; 22 char hostname[BUFSIZ], *cp; 23 struct stat sbuf; 24 struct utsname unamebuf; 25 26 /* All keyed by initial target being a directory */ 27 (void) strcpy(result, base); 28 if (stat(result, &sbuf) == 0) { 29 if (S_ISDIR(sbuf.st_mode)) { 30 31 /* First choice is my hostname */ 32 if (gethostname(hostname, BUFSIZ) >= 0) { 33 (void) sprintf(result, "%s/%s", base, hostname); 34 if (stat(result, &sbuf) == 0) { 35 goto outahere; 36 } else { 37 38 /* Second choice is of form default.835 */ 39 (void) uname(&unamebuf); 40 if (strncmp(unamebuf.machine, "9000/", 5) == 0) 41 cp = unamebuf.machine + 5; 42 else 43 cp = unamebuf.machine; 44 (void) sprintf(result, "%s/default.%s", base, cp); 45 if (stat(result, &sbuf) == 0) { 46 goto outahere; 47 } else { 48 49 /* Last choice is just default */ 50 (void) sprintf(result, "%s/default", base); 51 if (stat(result, &sbuf) == 0) { 52 goto outahere; 53 } else { 54 (void) strcpy(result, "/not/found"); 55 } 56 } 57 } 58 } 59 } 60 } 61 outahere: 62 return(result); 63 } 64 #else 65 #include "ntp_stdlib.h" 66 67 const char * 68 FindConfig( 69 const char *base 70 ) 71 { 72 return base; 73 } 74 #endif 75