]>
git.ipfire.org Git - thirdparty/kmod.git/blob - libkmod/libkmod-util.c
2 * libkmod - interface to kernel module operations
4 * Copyright (C) 2011-2013 ProFUSION embedded systems
5 * Copyright (C) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
6 * Copyright (C) 2013 Intel Corporation. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <shared/util.h>
34 #include "libkmod-internal.h"
36 const struct kmod_ext kmod_exts
[] = {
37 {".ko", sizeof(".ko") - 1},
39 {".ko.gz", sizeof(".ko.gz") - 1},
42 {".ko.xz", sizeof(".ko.xz") - 1},
47 inline int alias_normalize(const char *alias
, char buf
[PATH_MAX
], size_t *len
)
51 for (s
= 0; s
< PATH_MAX
- 1; s
++) {
52 const char c
= alias
[s
];
60 while (alias
[s
] != ']' && alias
[s
] != '\0') {
86 inline char *modname_normalize(const char *modname
, char buf
[PATH_MAX
],
91 for (s
= 0; s
< PATH_MAX
- 1; s
++) {
92 const char c
= modname
[s
];
95 else if (c
== '\0' || c
== '.')
109 char *path_to_modname(const char *path
, char buf
[PATH_MAX
], size_t *len
)
113 modname
= basename(path
);
114 if (modname
== NULL
|| modname
[0] == '\0')
117 return modname_normalize(modname
, buf
, len
);
120 bool path_ends_with_kmod_ext(const char *path
, size_t len
)
122 const struct kmod_ext
*eitr
;
124 for (eitr
= kmod_exts
; eitr
->ext
!= NULL
; eitr
++) {
125 if (len
<= eitr
->len
)
127 if (streq(path
+ len
- eitr
->len
, eitr
->ext
))