]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Move util functions to libkmod-util.c
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 27 Dec 2011 16:38:26 +0000 (14:38 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 27 Dec 2011 20:11:58 +0000 (18:11 -0200)
These allow them to be later shared with tools.

Makefile.am
libkmod/libkmod-module.c
libkmod/libkmod-private.h
libkmod/libkmod-util.c
libkmod/libkmod-util.h [new file with mode: 0644]

index 59c6999394a553aa7910fa733605f452ac67ae51..1d67fc83bdd47aa14a5c8acc085a8bcfbc183a24 100644 (file)
@@ -55,6 +55,7 @@ libkmod_libkmod_la_SOURCES =\
        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 \
index 1ec29e5b10f0afae32172d0207ef989dfba997e2..64dda187c626557bdeeeb89de8e475d7b965d71a 100644 (file)
@@ -64,40 +64,6 @@ struct kmod_module {
        } 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])
 {
index 5c9eeaf7ab0d044309269bfa1c99f9f5dcb61b53..3c750f1ca7d1b94f4b0983e5362ecf287239d30f 100644 (file)
@@ -123,7 +123,6 @@ const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned in
 
 /* 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)));
@@ -157,19 +156,6 @@ int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) __must_che
 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
index 177b51a5883044f94748a9515900756a3dfd637a..50d4d9151d73a48a8ee56b008ea04646094dbaef 100644 (file)
@@ -157,6 +157,40 @@ finish:
        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;
 
diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h
new file mode 100644 (file)
index 0000000..f09c327
--- /dev/null
@@ -0,0 +1,20 @@
+#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