1 /* lsmod.c: list the status of kernel modules.
2 Copyright (C) 2002 Rusty Russell, IBM Corporation.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/types.h>
28 #include <asm/unistd.h>
30 #include "backwards_compat.c"
32 static void print_usage(const char *progname
)
34 fprintf(stderr
, "Usage: %s\n", progname
);
38 int main(int argc
, char *argv
[])
43 try_old_version("lsmod", argv
);
48 file
= fopen("/proc/modules", "r");
50 perror("Opening /proc/modules");
54 printf("Module Size Used by\n");
55 while (fgets(line
, sizeof(line
), file
)) {
58 tok
= strtok(line
, " \t");
60 tok
= strtok(NULL
, " \t\n");
62 tok
= strtok(NULL
, " \t\n");
63 /* Null if no module unloading support. */
66 tok
= strtok(NULL
, "\n");
69 /* New-style has commas, or -. If so,
70 truncate (other fields might follow). */
71 else if (strchr(tok
, ',')) {
72 tok
= strtok(tok
, "\t ");
73 /* Strip trailing comma. */
74 if (tok
[strlen(tok
)-1] == ',')
75 tok
[strlen(tok
)-1] = '\0';
76 } else if (tok
[0] == '-'
77 && (tok
[1] == '\0' || isspace(tok
[1])))