diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-12-02 09:01:21 +0000 |
---|---|---|
committer | <> | 2014-12-04 16:11:25 +0000 |
commit | bdab5265fcbf3f472545073a23f8999749a9f2b9 (patch) | |
tree | c6018dd03dea906f8f1fb5f105f05b71a7dc250a /libntp/findconfig.c | |
download | ntp-dev-4.2.7p482.tar.gz |
Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz.ntp-dev-4.2.7p482
Diffstat (limited to 'libntp/findconfig.c')
-rw-r--r-- | libntp/findconfig.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/libntp/findconfig.c b/libntp/findconfig.c new file mode 100644 index 0000000..1785ff7 --- /dev/null +++ b/libntp/findconfig.c @@ -0,0 +1,74 @@ + +#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 */ + strlcpy(result, base, sizeof(result)); + if (stat(result, &sbuf) == 0) { + if (S_ISDIR(sbuf.st_mode)) { + + /* First choice is my hostname */ + if (gethostname(hostname, BUFSIZ) >= 0) { + snprintf(result, sizeof(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; + snprintf(result, sizeof(result), "%s/default.%s", base, cp); + if (stat(result, &sbuf) == 0) { + goto outahere; + } else { + + /* Last choice is just default */ + snprintf(result, sizeof(result), "%s/default", base); + if (stat(result, &sbuf) == 0) { + goto outahere; + } else { + strlcpy(result, + "/not/found", + sizeof(result)); + } + } + } + } + } + } + outahere: + return(result); +} +#else +#include "ntp_stdlib.h" + +const char * +FindConfig( + const char *base + ) +{ + return base; +} +#endif |