view toys/other/lsmod.c @ 1189:95ae2805622f draft

Add Szabolcs Nagy's deflate/inflate code from git://git.suckless.org/flate Confirmed with him on IRC it's ok to use under toybox license, glued the files together and hammered square peg into round hole, no other changes yet.
author Rob Landley <rob@landley.net>
date Fri, 31 Jan 2014 06:01:30 -0600
parents 786841fdb1e0
children 57f2a26fa92c
line wrap: on
line source

/* lsmod.c - Show the status of modules in the kernel
 *
 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>

USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_BIN))

config LSMOD
  bool "lsmod"
  default y
  help
    usage: lsmod

    Display the currently loaded modules, their sizes and their dependencies.
*/

#include "toys.h"

void lsmod_main(void)
{
  char *modfile = "/proc/modules";
  FILE * file = xfopen(modfile, "r");

  xprintf("%-23s Size  Used by\n", "Module");

  while (fgets(toybuf, sizeof(toybuf), file)) {
    char *name = strtok(toybuf, " "), *size = strtok(NULL, " "),
         *refcnt = strtok(NULL, " "), *users = strtok(NULL, " ");

    if(users) {
      int len = strlen(users)-1;
      if (users[len] == ',' || users[len] == '-') users[len] = 0;
      xprintf("%-19s %8s  %s %s\n", name, size, refcnt, users);
    } else perror_exit("bad %s", modfile);
  }
  fclose(file);
}