mirror of
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
synced 2024-11-27 13:53:49 +08:00
Move alias_normalize() to shared
This commit is contained in:
parent
66bf1a7ff9
commit
2b0104fe3c
@ -47,45 +47,6 @@ static const struct kmod_ext {
|
||||
{ }
|
||||
};
|
||||
|
||||
inline int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len)
|
||||
{
|
||||
size_t s;
|
||||
|
||||
for (s = 0; s < PATH_MAX - 1; s++) {
|
||||
const char c = alias[s];
|
||||
switch (c) {
|
||||
case '-':
|
||||
buf[s] = '_';
|
||||
break;
|
||||
case ']':
|
||||
return -EINVAL;
|
||||
case '[':
|
||||
while (alias[s] != ']' && alias[s] != '\0') {
|
||||
buf[s] = alias[s];
|
||||
s++;
|
||||
}
|
||||
|
||||
if (alias[s] != ']')
|
||||
return -EINVAL;
|
||||
|
||||
buf[s] = alias[s];
|
||||
break;
|
||||
case '\0':
|
||||
goto finish;
|
||||
default:
|
||||
buf[s] = c;
|
||||
}
|
||||
}
|
||||
|
||||
finish:
|
||||
buf[s] = '\0';
|
||||
|
||||
if (len)
|
||||
*len = s;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline char *modname_normalize(const char *modname, char buf[PATH_MAX],
|
||||
size_t *len)
|
||||
{
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#define KMOD_EXTENSION_UNCOMPRESSED ".ko"
|
||||
|
||||
int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) _must_check_ __attribute__((nonnull(1,2)));
|
||||
char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2)));
|
||||
char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2)));
|
||||
bool path_ends_with_kmod_ext(const char *path, size_t len) __attribute__((nonnull(1)));
|
||||
|
@ -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)
|
||||
|
@ -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)));
|
||||
|
@ -23,9 +23,6 @@
|
||||
|
||||
#include <shared/util.h>
|
||||
|
||||
#include <libkmod.h>
|
||||
#include <libkmod-util.h>
|
||||
|
||||
#include "testsuite.h"
|
||||
|
||||
static int alias_1(const struct test *t)
|
||||
|
Loading…
Reference in New Issue
Block a user