diff options
author | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
commit | ef64b99e8412f2273dd2e8b3291c2f78ffc4667f (patch) | |
tree | fc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp/findconfig.c | |
download | FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.zip FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.tar.gz |
Virgin import of ntpd 4.0.98f
Diffstat (limited to 'contrib/ntp/libntp/findconfig.c')
-rw-r--r-- | contrib/ntp/libntp/findconfig.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/findconfig.c b/contrib/ntp/libntp/findconfig.c new file mode 100644 index 0000000..ecf6a4b --- /dev/null +++ b/contrib/ntp/libntp/findconfig.c @@ -0,0 +1,72 @@ + +#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> +#include <unistd.h> + +const char * +FindConfig( + const char *base + ) +{ + static char result[BUFSIZ]; + char hostname[BUFSIZ], *cp; + struct stat sbuf; + struct utsname unamebuf; + + /* 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) { + (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"); + } + } + } + } + } + } + outahere: + return(result); +} +#else +#include "ntp_stdlib.h" + +const char * +FindConfig( + const char *base + ) +{ + return base; +} +#endif |