These allow them to be later shared with tools.
libkmod/libkmod-list.c \
libkmod/libkmod-config.c \
libkmod/libkmod-util.c \
+ libkmod/libkmod-util.h \
libkmod/libkmod-index.c \
libkmod/libkmod-index.h \
libkmod/libkmod-module.c \
} init;
};
-inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
- size_t *len)
-{
- size_t s;
-
- for (s = 0; s < NAME_MAX - 1; s++) {
- const char c = modname[s];
- if (c == '-')
- buf[s] = '_';
- else if (c == '\0' || c == '.')
- break;
- else
- buf[s] = c;
- }
-
- buf[s] = '\0';
-
- if (len)
- *len = s;
-
- return buf;
-}
-
-static char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len)
-{
- char *modname;
-
- modname = basename(path);
- if (modname == NULL || modname[0] == '\0')
- return NULL;
-
- return modname_normalize(modname, buf, len);
-}
-
static inline const char *path_join(const char *path, size_t prefixlen,
char buf[PATH_MAX])
{
/* libkmod-module.c */
int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod);
-char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(1, 2)));
int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2)));
void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
int kmod_elf_strip_vermagic(struct kmod_elf *elf) __must_check __attribute__((nonnull(1)));
/* util functions */
-char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1)));
-char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2)));
-#define streq(a, b) (strcmp((a), (b)) == 0)
-bool startswith(const char *s, const char *prefix) __attribute__((nonnull(1, 2)));
-void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
-
-ssize_t read_str_safe(int fd, char *buf, size_t buflen) __must_check __attribute__((nonnull(2)));
-int read_str_long(int fd, long *value, int base) __must_check __attribute__((nonnull(2)));
-int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attribute__((nonnull(2)));
-char *strchr_replace(char *s, int c, char r);
-bool path_is_absolute(const char *p) __must_check __attribute__((nonnull(1)));
-char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull(1)));
-int alias_normalize(const char *alias, char buf[NAME_MAX], size_t *len) __must_check __attribute__((nonnull(1,2)));
-
+#include "libkmod-util.h"
#endif
return 0;
}
+inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
+ size_t *len)
+{
+ size_t s;
+
+ for (s = 0; s < NAME_MAX - 1; s++) {
+ const char c = modname[s];
+ if (c == '-')
+ buf[s] = '_';
+ else if (c == '\0' || c == '.')
+ break;
+ else
+ buf[s] = c;
+ }
+
+ buf[s] = '\0';
+
+ if (len)
+ *len = s;
+
+ return buf;
+}
+
+char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len)
+{
+ char *modname;
+
+ modname = basename(path);
+ if (modname == NULL || modname[0] == '\0')
+ return NULL;
+
+ return modname_normalize(modname, buf, len);
+}
+
bool startswith(const char *s, const char *prefix) {
size_t sl, pl;
--- /dev/null
+#ifndef _LIBKMOD_UTIL_H_
+#define _LIBKMOD_UTIL_H_
+
+char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1)));
+char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2)));
+#define streq(a, b) (strcmp((a), (b)) == 0)
+bool startswith(const char *s, const char *prefix) __attribute__((nonnull(1, 2)));
+void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
+
+ssize_t read_str_safe(int fd, char *buf, size_t buflen) __must_check __attribute__((nonnull(2)));
+int read_str_long(int fd, long *value, int base) __must_check __attribute__((nonnull(2)));
+int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attribute__((nonnull(2)));
+char *strchr_replace(char *s, int c, char r);
+bool path_is_absolute(const char *p) __must_check __attribute__((nonnull(1)));
+char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull(1)));
+int alias_normalize(const char *alias, char buf[NAME_MAX], size_t *len) __must_check __attribute__((nonnull(1,2)));
+char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(1, 2)));
+char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(2)));
+
+#endif