aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/utils.h24
-rw-r--r--src/utils.c3
2 files changed, 27 insertions, 0 deletions
diff --git a/include/utils.h b/include/utils.h
index a3d244a..4f7c3a4 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -365,4 +365,28 @@ long get_cpu_count();
*/
int mkdirs(const char *_path, mode_t mode);
+/**
+ * Return pointer to a (possible) version specifier
+ *
+ * ```c
+ * char s[] = "abc==1.2.3";
+ * char *spec_begin = find_version_spec(s);
+ * // spec_begin is "==1.2.3"
+ *
+ * char package_name[255];
+ * char s[] = "abc";
+ * char *spec_pos = find_version_spec(s);
+ * if (spec_pos) {
+ * strncpy(package_name, spec_pos - s);
+ * // use spec
+ * } else {
+ * // spec not found
+ * }
+ *
+ * @param str a pointer to a buffer containing a package spec (i.e. abc==1.2.3, abc>=1.2.3, abc)
+ * @return a pointer to the first occurrence of a version spec character
+ * @return NULL if not found
+ */
+char *find_version_spec(char *package_name);
+
#endif //STASIS_UTILS_H
diff --git a/src/utils.c b/src/utils.c
index e037088..6381cea 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -814,3 +814,6 @@ int mkdirs(const char *_path, mode_t mode) {
return status;
}
+char *find_version_spec(char *str) {
+ return strpbrk(str, "@~=<>!");
+}