libkmod_libkmod_util_la_SOURCES = libkmod/libkmod-hash.c \
libkmod/libkmod-hash.h \
libkmod/libkmod-array.c \
- libkmod/libkmod-array.h
+ libkmod/libkmod-array.h \
+ libkmod/libkmod-util.c \
+ libkmod/libkmod-util.h
include_HEADERS = libkmod/libkmod.h
lib_LTLIBRARIES = libkmod/libkmod.la
libkmod/libkmod.c \
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 \
#ifndef _LIBKMOD_UTIL_H_
#define _LIBKMOD_UTIL_H_
+#include "macro.h"
+
+#include <limits.h>
+#include <stdio.h>
+#include <sys/types.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)));
+#define strstartswith(a, b) (strncmp(a, b, strlen(b)) == 0)
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)));
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "libkmod.h"
+#include "libkmod-array.h"
+#include "libkmod-hash.h"
+#include "libkmod-util.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <ctype.h>
-#include "libkmod.h"
-#include "libkmod-hash.h"
-#include "libkmod-array.h"
-
-#define streq(a, b) (strcmp(a, b) == 0)
-#define strstartswith(a, b) (strncmp(a, b, strlen(b)) == 0)
#define DEFAULT_VERBOSE LOG_WARNING
static int verbose = DEFAULT_VERBOSE;
/* END: code from module-init-tools/index.c just modified to compile here.
*/
-/* utils (similar to libkmod-utils.c) *********************************/
-static const char *underscores(const char *input, char *output, size_t outputlen)
+/* utils (variants of libkmod-utils.c) *********************************/
+static const char *underscores2(const char *input, char *output, size_t outputlen)
{
size_t i;
return output;
}
-static 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);
-}
-
/* configuration parsing **********************************************/
struct cfg_override {
struct cfg_override *next;
return status == 0;
}
-/* same as libkmod-util.c */
-static char *getline_wrapped(FILE *fp, unsigned int *linenum)
-{
- int size = 256;
- int i = 0;
- char *buf = malloc(size);
-
- for(;;) {
- int ch = getc_unlocked(fp);
-
- switch(ch) {
- case EOF:
- if (i == 0) {
- free(buf);
- return NULL;
- }
- /* else fall through */
-
- case '\n':
- if (linenum)
- (*linenum)++;
- if (i == size)
- buf = realloc(buf, size + 1);
- buf[i] = '\0';
- return buf;
-
- case '\\':
- ch = getc_unlocked(fp);
-
- if (ch == '\n') {
- if (linenum)
- (*linenum)++;
- continue;
- }
- /* else fall through */
-
- default:
- buf[i++] = ch;
-
- if (i == size) {
- size *= 2;
- buf = realloc(buf, size);
- }
- }
- }
-}
-
static int cfg_file_parse(struct cfg *cfg, const char *filename)
{
char *line;
if (!streq(key, "alias"))
continue;
- alias = underscores(value, buf, sizeof(buf));
+ alias = underscores2(value, buf, sizeof(buf));
if (alias == NULL)
continue;