diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2011-07-07 19:59:03 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2011-07-07 19:59:03 +0200 |
commit | 91f329fcd0baafd21ceb178cfbae0235f5abbcb0 (patch) | |
tree | aa528d404747bcd69a31ccc9d0d8cac07170cf21 | |
parent | 8992abf5528fe332ca041f6c7d03df820406feb4 (diff) |
path_id: add ID_PATH_TAG= to be used in udev tags
-rw-r--r-- | extras/path_id/path_id.c | 30 |
1 files changed, 30 insertions, 0 deletions
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; } |