return result;
}
-static bool
-is_ko (const FTSENT *f, size_t namelen)
+static size_t
+check_suffix (const FTSENT *f, size_t namelen)
{
-#define has_suffix(f, sfx, namelen) \
- ((namelen ? f->fts_namelen == namelen + sizeof sfx - 1 \
- : f->fts_namelen >= sizeof sfx) \
- && !memcmp (f->fts_name + f->fts_namelen - (sizeof sfx - 1), \
- sfx, sizeof sfx))
-
- return (has_suffix (f, ".ko", namelen)
+#define TRY(sfx) \
+ if ((namelen ? f->fts_namelen == namelen + sizeof sfx - 1 \
+ : f->fts_namelen >= sizeof sfx) \
+ && !memcmp (f->fts_name + f->fts_namelen - (sizeof sfx - 1), \
+ sfx, sizeof sfx)) \
+ return sizeof sfx - 1
+
+ TRY (".ko");
#if USE_ZLIB
- || has_suffix (f, ".ko.gz", namelen)
+ TRY (".ko.gz");
#endif
#if USE_BZLIB
- || has_suffix (f, ".ko.bz2", namelen)
+ TRY (".ko.bz2");
#endif
- );
-#undef has_suffix
+ return 0;
+
+#undef TRY
}
/* Report a kernel and all its modules found on disk, for offline use.
{
case FTS_F:
case FTS_SL:
- case FTS_NSOK:
+ case FTS_NSOK:;
/* See if this file name matches "*.ko". */
- if (is_ko (f, 0))
+ const size_t suffix = check_suffix (f, 0);
+ if (suffix)
{
/* We have a .ko file to report. Following the algorithm
by which the kernel makefiles set KBUILD_MODNAME, we
names. To handle that, we would have to look at the
__this_module.name contents in the module's text. */
- char name[f->fts_namelen - 3 + 1];
+ char name[f->fts_namelen - suffix + 1];
for (size_t i = 0; i < f->fts_namelen - 3U; ++i)
if (f->fts_name[i] == '-' || f->fts_name[i] == ',')
name[i] = '_';
else
name[i] = f->fts_name[i];
- name[f->fts_namelen - 3] = '\0';
+ name[f->fts_namelen - suffix] = '\0';
if (predicate != NULL)
{
continue;
}
- if (dwfl_report_offline (dwfl, name,
- f->fts_path, -1) == NULL)
+ if (dwfl_report_offline (dwfl, name, f->fts_path, -1) == NULL)
{
result = -1;
break;
case FTS_SL:
case FTS_NSOK:
/* See if this file name is "MODULE_NAME.ko". */
- if (is_ko (f, namelen)
+ if (check_suffix (f, namelen)
&& (!memcmp (f->fts_name, module_name, namelen)
|| !memcmp (f->fts_name, alternate_name, namelen)))
{