docs: don't forget to pass -I m4 to aclocal
[mit.git] / lsmod.c
blob489078e3f83fdac6405c061241933ec740b5519d
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
18 #include <stdio.h>
19 #include <string.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <sys/mman.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <errno.h>
27 #include <ctype.h>
28 #include <asm/unistd.h>
30 #include "testing.h"
31 #include "backwards_compat.c"
33 static void print_usage(const char *progname)
35 fprintf(stderr, "Usage: %s\n", progname);
36 exit(1);
39 int main(int argc, char *argv[])
41 char line[4096];
42 FILE *file;
44 try_old_version("lsmod", argv);
46 if (argc != 1)
47 print_usage("lsmod");
49 file = fopen("/proc/modules", "r");
50 if (!file) {
51 perror("Opening /proc/modules");
52 exit(1);
55 printf("Module Size Used by\n");
56 while (fgets(line, sizeof(line), file)) {
57 char *tok;
59 tok = strtok(line, " \t");
60 printf("%-19s", tok);
61 tok = strtok(NULL, " \t\n");
62 printf(" %8s", tok);
63 tok = strtok(NULL, " \t\n");
64 /* Null if no module unloading support. */
65 if (tok) {
66 printf(" %s", tok);
67 tok = strtok(NULL, "\n");
68 if (!tok)
69 tok = "";
70 /* New-style has commas, or -. If so,
71 truncate (other fields might follow). */
72 else if (strchr(tok, ',')) {
73 tok = strtok(tok, "\t ");
74 /* Strip trailing comma. */
75 if (tok[strlen(tok)-1] == ',')
76 tok[strlen(tok)-1] = '\0';
77 } else if (tok[0] == '-'
78 && (tok[1] == '\0' || isspace(tok[1])))
79 tok = "";
80 printf(" %s", tok);
82 printf("\n");
84 fclose(file);
85 exit(0);