]> git.ipfire.org Git - thirdparty/kmod.git/blame - libkmod/libkmod-private.h
improve "const" keyword usage.
[thirdparty/kmod.git] / libkmod / libkmod-private.h
CommitLineData
586fc304
LDM
1#ifndef _LIBKMOD_PRIVATE_H_
2#define _LIBKMOD_PRIVATE_H_
3
4#include <stdbool.h>
4462c4ac 5#include <stdio.h>
586fc304
LDM
6#include <syslog.h>
7
88e9c12e 8#include "macro.h"
586fc304
LDM
9#include "libkmod.h"
10
f87081b4 11static __always_inline __printf_format(2, 3) void
586fc304
LDM
12 kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {}
13
14#define kmod_log_cond(ctx, prio, arg...) \
15 do { \
16 if (kmod_get_log_priority(ctx) >= prio) \
17 kmod_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg);\
18 } while (0)
19
20#ifdef ENABLE_LOGGING
21# ifdef ENABLE_DEBUG
ae6df84a 22# define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg)
586fc304 23# else
ae6df84a 24# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
586fc304 25# endif
ae6df84a
LDM
26# define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg)
27# define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg)
586fc304 28#else
ae6df84a
LDM
29# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
30# define INFO(ctx, arg...) kmod_log_null(ctx, ## arg)
31# define ERR(ctx, arg...) kmod_log_null(ctx, ## arg)
586fc304
LDM
32#endif
33
34#define KMOD_EXPORT __attribute__ ((visibility("default")))
35
36void kmod_log(struct kmod_ctx *ctx,
37 int priority, const char *file, int line, const char *fn,
38 const char *format, ...) __attribute__((format(printf, 6, 7)));
39
6924e47a
LDM
40struct list_node {
41 struct list_node *next, *prev;
42};
43
44struct kmod_list {
45 struct list_node node;
46 void *data;
47};
48
1ce08a56
GSB
49struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) __must_check;
50struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) __must_check;
6924e47a
LDM
51struct kmod_list *kmod_list_remove(struct kmod_list *list);
52struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
f87081b4 53 const void *data) __must_check;
62be7995
LDM
54struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
55 unsigned int n) __must_check;
60aa4d8b
LDM
56
57/* libkmod.c */
1ce08a56 58const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));
7f3eb0cc 59int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list);
9ba6f57b 60int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list);
49e61ca3 61int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list);
64700e47 62int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list);
221631d5 63
60aa4d8b 64/* libkmod-config.c */
7c2ab358
LDM
65struct kmod_config {
66 struct kmod_list *aliases;
81cf2060 67 struct kmod_list *blacklists;
7c2ab358
LDM
68};
69int kmod_parse_config_file(struct kmod_ctx *ctx, const char *filename, struct kmod_config *config);
70int kmod_parse_config(struct kmod_ctx *ctx, struct kmod_config *config);
71void kmod_free_config(struct kmod_ctx *ctx, struct kmod_config *config);
b0ef19f7
LDM
72const char *kmod_alias_get_name(const struct kmod_list *l);
73const char *kmod_alias_get_modname(const struct kmod_list *l);
7c2ab358 74
7636e72b
LDM
75/* libkmod-module.c */
76int kmod_module_parse_dep(struct kmod_module *mod, char *line);
77
60aa4d8b 78/* util functions */
4462c4ac 79char *getline_wrapped(FILE *fp, unsigned int *linenum);
8185fc91 80char *underscores(struct kmod_ctx *ctx, char *s);
44a5460f 81#define streq(a, b) (strcmp((a), (b)) == 0)
7e317da3 82bool startswith(const char *s, const char *prefix);
4462c4ac 83
586fc304 84#endif