- 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);
+ FILE *file = xfopen("/proc/modules", "r");
+
+ printf("Module Size Used by");
+ check_tainted();
+#if ENABLE_FEATURE_LSMOD_PRETTY_2_6_OUTPUT
+ {
+ char *line;
+ while ((line = xmalloc_fgets(file)) != NULL) {
+ char *tok;
+
+ tok = strtok(line, " \t");
+ printf("%-19s", tok);
+ tok = strtok(NULL, " \t\n");
+ printf(" %8s", tok);
+ tok = strtok(NULL, " \t\n");
+ /* Null if no module unloading support. */
+ if (tok) {
+ printf(" %s", tok);
+ tok = strtok(NULL, "\n");
+ if (!tok)
+ tok = (char*)"";
+ /* New-style has commas, or -. If so,
+ truncate (other fields might follow). */
+ else if (strchr(tok, ',')) {
+ tok = strtok(tok, "\t ");
+ /* Strip trailing comma. */
+ if (tok[strlen(tok)-1] == ',')
+ tok[strlen(tok)-1] = '\0';
+ } else if (tok[0] == '-'
+ && (tok[1] == '\0' || isspace(tok[1]))
+ ) {
+ tok = (char*)"";
+ }
+ printf(" %s", tok);
+ }
+ bb_putchar('\n');
+ free(line);