diff options
Diffstat (limited to 'lsmod.c')
-rw-r--r-- | lsmod.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -5,6 +5,10 @@ * Copyright (C) 1999,2000 by Lineo, inc. * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> * + * Modified by Alcove, Julien Gaulmin <julien.gaulmin@alcove.fr> and + * Nicolas Ferre <nicolas.ferre@alcove.fr> to support pre 2.1 kernels + * (which lack the query_module() interface). + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -32,8 +36,15 @@ #include <assert.h> #include <getopt.h> #include <sys/utsname.h> +#include <sys/file.h> + +#if !defined(BB_FEATURE_LSMOD_NEW_KERNEL) && !defined(BB_FEATURE_LSMOD_OLD_KERNEL) +#error "Must have ether BB_FEATURE_LSMOD_NEW_KERNEL or BB_FEATURE_LSMOD_OLD_KERNEL defined" +#endif + +#ifdef BB_FEATURE_LSMOD_NEW_KERNEL struct module_info { @@ -120,3 +131,30 @@ extern int lsmod_main(int argc, char **argv) return( 0); } + +#else /*BB_FEATURE_LSMOD_OLD_KERNEL*/ + +#if ! defined BB_FEATURE_USE_PROCFS +#error Sorry, I depend on the /proc filesystem right now. +#endif + +extern int lsmod_main(int argc, char **argv) +{ + int fd, i; + char line[128]; + + puts("Module Size Used by"); + fflush(stdout); + + if ((fd = open("/proc/modules", O_RDONLY)) >= 0 ) { + while ((i = read(fd, line, sizeof(line))) > 0) { + write(fileno(stdout), line, i); + } + close(fd); + return 0; + } + fatalError("/proc/modules: %s\n", strerror(errno)); + return 1; +} + +#endif /*BB_FEATURE_LSMOD_OLD_KERNEL*/ |