Sync usage with man page.
[netbsd-mini2440.git] / dist / ntp / libntp / findconfig.c
blobf97375b032f3ff33c81e0777460f04b01c7d66d9
1 /* $NetBSD$ */
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
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>
16 const char *
17 FindConfig(
18 const char *base
21 static char result[BUFSIZ];
22 char hostname[BUFSIZ], *cp;
23 struct stat sbuf;
24 struct utsname unamebuf;
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)) {
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 {
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 {
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");
61 outahere:
62 return(result);
64 #else
65 #include "ntp_stdlib.h"
67 const char *
68 FindConfig(
69 const char *base
72 return base;
74 #endif