aboutsummaryrefslogtreecommitdiffstats
path: root/lib/strutils.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2024-12-11 18:54:04 +0100
committerKarel Zak <kzak@redhat.com>2024-12-11 18:54:04 +0100
commite1bc7d39174de89b7fcf36b0459b552ef41dbf73 (patch)
tree9e6a5d9b24abef7f4d42a7250c1ead7f56233362 /lib/strutils.c
parente555740b45a9e54cae30817c56d40bc493077bb1 (diff)
parent5d0edf55b62f8f9ac9d58539014ea5c292df8291 (diff)
downloadutil-linux-e1bc7d39174de89b7fcf36b0459b552ef41dbf73.tar.gz
Merge branch 'PR/libsmartcols-hyperlinks' of https://github.com/karelzak/util-linux-work
* 'PR/libsmartcols-hyperlinks' of https://github.com/karelzak/util-linux-work: lsblk: add --hyperlink command line option findmnt: add --hyperlink command line option include: add functions to implement --hyperlink libsmartcols: add support for terminal hyperlinks include/ttyutils: add terminal hyperlink ESC sequences
Diffstat (limited to 'lib/strutils.c')
-rw-r--r--lib/strutils.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/strutils.c b/lib/strutils.c
index 4590aa9114..0cf0da96b6 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -524,6 +524,20 @@ time_t strtotime_or_err(const char *str, const char *errmesg)
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.