summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-08-11 13:31:50 -0400
committerDave Reisner <dreisner@archlinux.org>2012-08-21 11:48:26 -0400
commit383182b5c435dca06a3f4ba32c6d1be2d1e35881 (patch)
tree7ef08dc66e27e2e128b0b89091a9a23c57fb55b1 /src/shared/util.c
parentd8b78264a5245307babbf5af8e39d6d4a1ae095f (diff)
shared/util: refactor fstab_node_to_udev_node
Since this is purely duplicated logic, separate it out into a small static function.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c52
1 files changed, 19 insertions, 33 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 736cb15a5f..d94bc695c8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4126,52 +4126,38 @@ void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
}
}
-char *fstab_node_to_udev_node(const char *p) {
+static char *tag_to_udev_node(const char *tagvalue, const char *by) {
char *dn, *t, *u;
int r;
/* FIXME: to follow udev's logic 100% we need to leave valid
* UTF8 chars unescaped */
- if (startswith(p, "LABEL=")) {
-
- if (!(u = unquote(p+6, "\"\'")))
- return NULL;
-
- t = xescape(u, "/ ");
- free(u);
-
- if (!t)
- return NULL;
-
- r = asprintf(&dn, "/dev/disk/by-label/%s", t);
- free(t);
-
- if (r < 0)
- return NULL;
-
- return dn;
- }
+ u = unquote(tagvalue, "\"\'");
+ if (u == NULL)
+ return NULL;
- if (startswith(p, "UUID=")) {
+ t = xescape(u, "/ ");
+ free(u);
- if (!(u = unquote(p+5, "\"\'")))
- return NULL;
+ if (t == NULL)
+ return NULL;
- t = xescape(u, "/ ");
- free(u);
+ r = asprintf(&dn, "/dev/disk/by-%s/%s", by, t);
+ free(t);
- if (!t)
- return NULL;
+ if (r < 0)
+ return NULL;
- r = asprintf(&dn, "/dev/disk/by-uuid/%s", t);
- free(t);
+ return dn;
+}
- if (r < 0)
- return NULL;
+char *fstab_node_to_udev_node(const char *p) {
+ if (startswith(p, "LABEL="))
+ return tag_to_udev_node(p+6, "label");
- return dn;
- }
+ if (startswith(p, "UUID="))
+ return tag_to_udev_node(p+5, "uuid");
return strdup(p);
}