summaryrefslogtreecommitdiff
path: root/tools/tracing/rtla/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/tracing/rtla/src/utils.c')
-rw-r--r--tools/tracing/rtla/src/utils.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index d6ab15dcb490..9cf5a0098e9a 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -57,6 +57,21 @@ void debug_msg(const char *fmt, ...)
}
/*
+ * fatal - print an error message and EOL to stderr and exit with ERROR
+ */
+void fatal(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+
+ exit(ERROR);
+}
+
+/*
* get_llong_from_str - get a long long int from a string
*/
long long get_llong_from_str(char *start)
@@ -959,3 +974,29 @@ int auto_house_keeping(cpu_set_t *monitored_cpus)
return 1;
}
+
+/**
+ * parse_optional_arg - Parse optional argument value
+ *
+ * Parse optional argument value, which can be in the form of:
+ * -sarg, -s/--long=arg, -s/--long arg
+ *
+ * Returns arg value if found, NULL otherwise.
+ */
+char *parse_optional_arg(int argc, char **argv)
+{
+ if (optarg) {
+ if (optarg[0] == '=') {
+ /* skip the = */
+ return &optarg[1];
+ } else {
+ return optarg;
+ }
+ /* parse argument of form -s [arg] and --long [arg]*/
+ } else if (optind < argc && argv[optind][0] != '-') {
+ /* consume optind */
+ return argv[optind++];
+ } else {
+ return NULL;
+ }
+}