summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2014-10-09 00:43:01 -0300
committerLucas De Marchi <lucas.demarchi@intel.com>2014-10-09 01:26:39 -0300
commit2b0104fe3c47a9746b6296ed5646cd39e2ae010d (patch)
treee2a48b26104582e240994c61309f73eaf5a93664 /shared
parent66bf1a7ff94829d152f146180962bfb079d4561e (diff)
downloadkmod-2b0104fe3c47a9746b6296ed5646cd39e2ae010d.tar.gz
kmod-2b0104fe3c47a9746b6296ed5646cd39e2ae010d.tar.bz2
kmod-2b0104fe3c47a9746b6296ed5646cd39e2ae010d.zip
Move alias_normalize() to shared
Diffstat (limited to 'shared')
-rw-r--r--shared/util.c40
-rw-r--r--shared/util.h4
2 files changed, 44 insertions, 0 deletions
diff --git a/shared/util.c b/shared/util.c
index 8491b18..f6ce61d 100644
--- a/shared/util.c
+++ b/shared/util.c
@@ -60,6 +60,46 @@ char *strchr_replace(char *s, int c, char r)
return s;
}
+/* module-related functions */
+/* ************************************************************************ */
+int alias_normalize(const char *alias, char buf[static PATH_MAX], size_t *len)
+{
+ size_t i;
+
+ for (i = 0; i < PATH_MAX - 1; i++) {
+ const char c = alias[i];
+ switch (c) {
+ case '-':
+ buf[i] = '_';
+ break;
+ case ']':
+ return -EINVAL;
+ case '[':
+ while (alias[i] != ']' && alias[i] != '\0') {
+ buf[i] = alias[i];
+ i++;
+ }
+
+ if (alias[i] != ']')
+ return -EINVAL;
+
+ buf[i] = alias[i];
+ break;
+ case '\0':
+ goto finish;
+ default:
+ buf[i] = c;
+ }
+ }
+
+finish:
+ buf[i] = '\0';
+ if (len)
+ *len = i;
+
+ return 0;
+}
+
/* read-like and fread-like functions */
/* ************************************************************************ */
ssize_t read_str_safe(int fd, char *buf, size_t buflen)
diff --git a/shared/util.h b/shared/util.h
index 7fcb242..53a2d29 100644
--- a/shared/util.h
+++ b/shared/util.h
@@ -16,6 +16,10 @@
char *strchr_replace(char *s, int c, char r);
void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
+/* module-related functions */
+/* ************************************************************************ */
+int alias_normalize(const char *alias, char buf[static PATH_MAX], size_t *len) _must_check_ __attribute__((nonnull(1,2)));
+
/* read-like and fread-like functions */
/* ************************************************************************ */
ssize_t read_str_safe(int fd, char *buf, size_t buflen) _must_check_ __attribute__((nonnull(2)));