From 91f329fcd0baafd21ceb178cfbae0235f5abbcb0 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 7 Jul 2011 19:59:03 +0200 Subject: path_id: add ID_PATH_TAG= to be used in udev tags --- extras/path_id/path_id.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'extras/path_id') diff --git a/extras/path_id/path_id.c b/extras/path_id/path_id.c index 9e77b8a7cc..98f0e40089 100644 --- a/extras/path_id/path_id.c +++ b/extras/path_id/path_id.c @@ -508,7 +508,37 @@ int main(int argc, char **argv) } out: if (path != NULL) { + char tag[UTIL_NAME_SIZE]; + size_t i; + const char *p; + + /* compose valid udev tag name */ + for (p = path, i = 0; *p; p++) { + if ((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'Z') || + (*p >= 'a' && *p <= 'z') || + *p == '-') { + tag[i++] = *p; + continue; + } + + /* skip all leading '_' */ + if (i == 0) + continue; + + /* avoid second '_' */ + if (tag[i-1] == '_') + continue; + + tag[i++] = '_'; + } + /* strip trailing '_' */ + while (i > 0 && tag[i-1] == '_') + i--; + tag[i] = '\0'; + printf("ID_PATH=%s\n", path); + printf("ID_PATH_TAG=%s\n", tag); free(path); rc = EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf