summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2014-10-09 10:59:08 -0300
committerLucas De Marchi <lucas.demarchi@intel.com>2014-10-09 11:00:21 -0300
commit52c9c9905683c781e611a5bf3c61fcdc22ab5429 (patch)
tree7ff0f6675fcf605feefc29c46469cb6e04f75ed1 /shared
parent2c5bc218bef191504e02a4f1e9071a2b5387f221 (diff)
downloadkmod-52c9c9905683c781e611a5bf3c61fcdc22ab5429.tar.gz
kmod-52c9c9905683c781e611a5bf3c61fcdc22ab5429.tar.bz2
kmod-52c9c9905683c781e611a5bf3c61fcdc22ab5429.zip
Log error on failed underscores(), moving it to shared/
Move underscores() to shared/. It's the same as alias_normalize(), but it rather operates in place, with the same string being passed. The difference now that it's in shared/ is that it's a non-logging function. This makes us a little bit more verbose: we don't accept partially correct module and aliases names in kcmdline and in configuration files. We log an error instead.
Diffstat (limited to 'shared')
-rw-r--r--shared/util.c31
-rw-r--r--shared/util.h1
2 files changed, 32 insertions, 0 deletions
diff --git a/shared/util.c b/shared/util.c
index 3902823..dac70ed 100644
--- a/shared/util.c
+++ b/shared/util.c
@@ -114,6 +114,37 @@ finish:
return 0;
}
+/*
+ * Replace dashes with underscores.
+ * Dashes inside character range patterns (e.g. [0-9]) are left unchanged.
+ *
+ * For convenience, it returns error if @s is NULL
+ */
+int underscores(char *s)
+{
+ unsigned int i;
+
+ if (!s)
+ return -EINVAL;
+
+ for (i = 0; s[i]; i++) {
+ switch (s[i]) {
+ case '-':
+ s[i] = '_';
+ break;
+ case ']':
+ return -EINVAL;
+ case '[':
+ i += strcspn(&s[i], "]");
+ if (!s[i])
+ return -EINVAL;
+ break;
+ }
+ }
+
+ return 0;
+}
+
char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t *len)
{
size_t s;
diff --git a/shared/util.h b/shared/util.h
index ef3881a..e013d08 100644
--- a/shared/util.h
+++ b/shared/util.h
@@ -21,6 +21,7 @@ void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
#define KMOD_EXTENSION_UNCOMPRESSED ".ko"
int alias_normalize(const char *alias, char buf[static PATH_MAX], size_t *len) _must_check_ __attribute__((nonnull(1,2)));
+int underscores(char *s) _must_check_;
char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t *len) __attribute__((nonnull(1, 2)));
char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) __attribute__((nonnull(2)));
bool path_ends_with_kmod_ext(const char *path, size_t len) __attribute__((nonnull(1)));