summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 21aeb22..1f7a546 100644
--- a/src/util.c
+++ b/src/util.c
@@ -65,3 +65,19 @@ char *util_executableRelativePath(char const *const path, char const *const exec
memcpy(filePath + dirLength, path, fileLength);
return filePath;
}
+
+int util_stringToColor(struct color *color, char const *const str) {
+ if (str[0] != '#' || strnlen(str, 10) != 9) {
+ return 1;
+ }
+ char *out;
+ unsigned long colorint = strtoul(str + 1, &out, 16);
+ if (out != str + 9) {
+ return 1;
+ }
+ color->r = colorint >> 24;
+ color->g = colorint >> 16;
+ color->b = colorint >> 8;
+ color->a = colorint >> 0;
+ return 0;
+}