]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Move remaining functions from libkmod-util to shared
authorLucas De Marchi <lucas.demarchi@intel.com>
Thu, 9 Oct 2014 04:14:16 +0000 (01:14 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 9 Oct 2014 04:26:39 +0000 (01:26 -0300)
Makefile.am
libkmod/docs/Makefile.am
libkmod/libkmod-internal.h
libkmod/libkmod-util.c [deleted file]
libkmod/libkmod-util.h [deleted file]
shared/util.c
shared/util.h
testsuite/testsuite.c
tools/depmod.c
tools/modinfo.c

index 87702ee21c60d5738c911ff521713f16f30b3998..46972b3d595efdfeba6281caf4195941c96adead 100644 (file)
@@ -51,9 +51,7 @@ libkmod_libkmod_util_la_SOURCES = \
        shared/hash.c \
        shared/hash.h \
        shared/util.c \
-       shared/util.h \
-       libkmod/libkmod-util.c \
-       libkmod/libkmod-util.h
+       shared/util.h
 
 include_HEADERS = libkmod/libkmod.h
 lib_LTLIBRARIES = libkmod/libkmod.la
index cd3bb162e87ffd7d0e27f970841b5a109d192cb5..06f65c8983b0252494856ce988b62b01b58140b0 100644 (file)
@@ -21,7 +21,6 @@ HFILE_GLOB = $(top_srcdir)/libkmod/libkmod.h
 CFILE_GLOB = $(top_srcdir)/libkmod/libkmod.c $(top_srcdir)/libkmod/libkmod-module.c $(top_srcdir)/libkmod/libkmod-list.c
 
 IGNORE_HFILES = libkmod-internal.h \
-               libkmod-util.h \
                libkmod-index.h
 
 content_files = version.xml
index 83a5bc2f3debbaa751f0f8d669efe6d6ed0a7bda..417f232d09f62453713b29b0054e5889fa6284d0 100644 (file)
@@ -189,5 +189,3 @@ struct kmod_signature_info {
        const char *algo, *hash_algo, *id_type;
 };
 bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info) _must_check_ __attribute__((nonnull(1, 2)));
-/* util functions */
-#include "libkmod-util.h"
diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c
deleted file mode 100644 (file)
index ec6ee40..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * libkmod - interface to kernel module operations
- *
- * Copyright (C) 2011-2013  ProFUSION embedded systems
- * Copyright (C) 2012  Lucas De Marchi <lucas.de.marchi@gmail.com>
- * Copyright (C) 2013  Intel Corporation. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include <ctype.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <shared/util.h>
-
-#include "libkmod.h"
-#include "libkmod-internal.h"
-
-static const struct kmod_ext {
-       const char *ext;
-       size_t len;
-} kmod_exts[] = {
-       {KMOD_EXTENSION_UNCOMPRESSED, sizeof(KMOD_EXTENSION_UNCOMPRESSED) - 1},
-#ifdef ENABLE_ZLIB
-       {".ko.gz", sizeof(".ko.gz") - 1},
-#endif
-#ifdef ENABLE_XZ
-       {".ko.xz", sizeof(".ko.xz") - 1},
-#endif
-       { }
-};
-
-inline char *modname_normalize(const char *modname, char buf[PATH_MAX],
-                                                               size_t *len)
-{
-       size_t s;
-
-       for (s = 0; s < PATH_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[PATH_MAX], size_t *len)
-{
-       char *modname;
-
-       modname = basename(path);
-       if (modname == NULL || modname[0] == '\0')
-               return NULL;
-
-       return modname_normalize(modname, buf, len);
-}
-
-bool path_ends_with_kmod_ext(const char *path, size_t len)
-{
-       const struct kmod_ext *eitr;
-
-       for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
-               if (len <= eitr->len)
-                       continue;
-               if (streq(path + len - eitr->len, eitr->ext))
-                       return true;
-       }
-
-       return false;
-}
diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h
deleted file mode 100644 (file)
index 46db70d..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-
-#include <limits.h>
-#include <stdbool.h>
-#include <stddef.h>
-
-#include <shared/macro.h>
-
-#define KMOD_EXTENSION_UNCOMPRESSED ".ko"
-
-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)));
index f6ce61d1e5ad7f8a25ce63dd5e258865fbf6003c..390282326bb6f8be2f0941a1bc86be7d51a27497 100644 (file)
 #define USEC_PER_SEC  1000000ULL
 #define NSEC_PER_USEC 1000ULL
 
+static const struct kmod_ext {
+       const char *ext;
+       size_t len;
+} kmod_exts[] = {
+       {KMOD_EXTENSION_UNCOMPRESSED, sizeof(KMOD_EXTENSION_UNCOMPRESSED) - 1},
+#ifdef ENABLE_ZLIB
+       {".ko.gz", sizeof(".ko.gz") - 1},
+#endif
+#ifdef ENABLE_XZ
+       {".ko.xz", sizeof(".ko.xz") - 1},
+#endif
+       { }
+};
+
 /* string handling functions and memory allocations                         */
 /* ************************************************************************ */
 
@@ -100,6 +114,53 @@ finish:
        return 0;
 }
 
+char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t *len)
+{
+       size_t s;
+
+       for (s = 0; s < PATH_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[static PATH_MAX], size_t *len)
+{
+       char *modname;
+
+       modname = basename(path);
+       if (modname == NULL || modname[0] == '\0')
+               return NULL;
+
+       return modname_normalize(modname, buf, len);
+}
+
+bool path_ends_with_kmod_ext(const char *path, size_t len)
+{
+       const struct kmod_ext *eitr;
+
+       for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
+               if (len <= eitr->len)
+                       continue;
+               if (streq(path + len - eitr->len, eitr->ext))
+                       return true;
+       }
+
+       return false;
+}
+
 /* read-like and fread-like functions                                       */
 /* ************************************************************************ */
 ssize_t read_str_safe(int fd, char *buf, size_t buflen)
index 53a2d295b11a4e0e8f9e209da4a251ad0e0a373b..ef3881a7bc4f9b4fa7ee30ee111da372dcf4ed3d 100644 (file)
@@ -18,7 +18,12 @@ void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
 
 /* module-related functions                                                 */
 /* ************************************************************************ */
+#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)));
+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)));
 
 /* read-like and fread-like functions                                       */
 /* ************************************************************************ */
index d8acf6802d8a5d5da422aec9e68468d10a83dfc5..c7843748f551d47f28cfdff7af9d25c3f12da699 100644 (file)
@@ -34,8 +34,6 @@
 
 #include <shared/util.h>
 
-#include <libkmod-util.h>
-
 #include "testsuite.h"
 
 static const char *ANSI_HIGHLIGHT_GREEN_ON = "\x1B[1;32m";
index e812ae62bdb9831e9777ad48f677f937fc19ee44..fec458c18195410fd4d0988ed8ea9167da1884f3 100644 (file)
@@ -37,7 +37,6 @@
 #include <shared/util.h>
 
 #include <libkmod.h>
-#include <libkmod-util.h>
 
 #include "kmod.h"
 
index 72ac03cbca6779eb6c8492cb9fcbcdb2c2930176..74ec183410be1449839aa67060dc52be5ec25f1d 100644 (file)
@@ -27,8 +27,9 @@
 #include <sys/stat.h>
 #include <sys/utsname.h>
 
+#include <shared/util.h>
+
 #include <libkmod.h>
-#include <libkmod-util.h>
 
 #include "kmod.h"