1999-07-03 16:30:16 +04:00
|
|
|
/* $NetBSD: findconfig.c,v 1.6 1999/07/03 12:30:30 simonb Exp $ */
|
1998-01-09 06:15:09 +03:00
|
|
|
|
1997-04-18 17:22:49 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NEED_HPUX_FINDCONFIG
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/utsname.h>
|
1998-03-06 21:17:13 +03:00
|
|
|
#include <unistd.h>
|
1997-04-18 17:22:49 +04:00
|
|
|
|
|
|
|
char *
|
|
|
|
FindConfig(base)
|
|
|
|
char *base;
|
|
|
|
{
|
|
|
|
static char result[BUFSIZ];
|
1998-07-06 10:45:41 +04:00
|
|
|
char hostname[MAXHOSTNAMELEN + 1], *cp;
|
1999-07-03 16:30:16 +04:00
|
|
|
struct stat sbuf;
|
|
|
|
struct utsname unamebuf;
|
1997-04-18 17:22:49 +04:00
|
|
|
|
|
|
|
/* All keyed by initial target being a directory */
|
|
|
|
(void) strcpy(result, base);
|
|
|
|
if (stat(result, &sbuf) == 0) {
|
|
|
|
if (S_ISDIR(sbuf.st_mode)) {
|
|
|
|
|
|
|
|
/* First choice is my hostname */
|
|
|
|
if (gethostname(hostname, BUFSIZ) >= 0) {
|
1998-07-06 10:45:41 +04:00
|
|
|
hostname[sizeof(hostname) - 1] = '\0';
|
1997-04-18 17:22:49 +04:00
|
|
|
(void) sprintf(result, "%s/%s", base, hostname);
|
|
|
|
if (stat(result, &sbuf) == 0) {
|
|
|
|
goto outahere;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Second choice is of form default.835 */
|
|
|
|
(void) uname(&unamebuf);
|
|
|
|
if (strncmp(unamebuf.machine, "9000/", 5) == 0)
|
|
|
|
cp = unamebuf.machine + 5;
|
|
|
|
else
|
|
|
|
cp = unamebuf.machine;
|
|
|
|
(void) sprintf(result, "%s/default.%s", base, cp);
|
|
|
|
if (stat(result, &sbuf) == 0) {
|
|
|
|
goto outahere;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Last choice is just default */
|
|
|
|
(void) sprintf(result, "%s/default", base);
|
|
|
|
if (stat(result, &sbuf) == 0) {
|
|
|
|
goto outahere;
|
|
|
|
} else {
|
|
|
|
(void) strcpy(result, "/not/found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-03 16:30:16 +04:00
|
|
|
}
|
|
|
|
}
|
1997-04-18 17:22:49 +04:00
|
|
|
}
|
|
|
|
outahere:
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#include "ntp_stdlib.h"
|
|
|
|
|
|
|
|
char *
|
|
|
|
FindConfig(base)
|
|
|
|
char *base;
|
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
#endif
|