* add xgethosturi() to allocate file://hostname
* add hyperlinkwanted_or_err() to parse --hyperlink={never,always,auto}
Signed-off-by: Karel Zak <kzak@redhat.com>
#include <stdio.h>
#include <errno.h>
#include <time.h>
+#include <stdbool.h>
#include "c.h"
const char *errmesg);
extern time_t strtotime_or_err(const char *str, const char *errmesg);
+extern bool hyperlinkwanted_or_err(const char *mode, const char *errmesg);
+
extern int isdigit_strend(const char *str, const char **end);
#define isdigit_string(_s) isdigit_strend(_s, NULL)
return name;
}
+static inline
+__attribute__((warn_unused_result))
+char *xgethosturi(const char *proto)
+{
+ char *n = xgethostname();
+ char *uri = NULL;
+
+ if (!proto)
+ proto = "file://";
+ if (!n)
+ return xstrdup(proto);
+
+ xasprintf(&uri, "%s%s", proto, n);
+ free(n);
+ return uri;
+}
+
#endif
return (time_t) user_input;
}
+bool hyperlinkwanted_or_err(const char *mode, const char *errmesg)
+{
+ if (mode && strcmp(mode, "never") == 0)
+ return false;
+
+ if (mode && strcmp(mode, "always") == 0)
+ return true;
+
+ if (!mode || strcmp(mode, "auto") == 0)
+ return isatty(STDOUT_FILENO) ? true : false;
+
+ errx(EXIT_FAILURE, "%s: '%s'", errmesg, mode);
+}
+
/*
* Converts stat->st_mode to ls(1)-like mode string. The size of "str" must
* be 11 bytes.