1
0

lubheap.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This program provides a wrapper to another command but ensuring that the
  3. * lubheap memory management system is used in preference to the native one
  4. */
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "lub/heap.h"
  9. void
  10. usage(const char *prog)
  11. {
  12. printf("%s [-l] command [args ...]\n"
  13. "\n"
  14. " This application invokes the specified\n"
  15. " command utilsing the lubheap memory management\n"
  16. " library.\n"
  17. "\n"
  18. " -l - enable leak detection\n"
  19. " command - the program to run\n\n",
  20. prog);
  21. exit(-1);
  22. }
  23. int
  24. main(int argc,
  25. char **argv,
  26. char **envp)
  27. {
  28. const char *prog = *argv;
  29. const char *path;
  30. --argc,++argv;
  31. if(!argc)
  32. {
  33. usage(prog);
  34. }
  35. path = *argv;
  36. /* check to see whether this program exists in the current path */
  37. /* replace the current process having first set up the memory management system */
  38. lub_heap_init(prog);
  39. return execve(path,argv,envp);
  40. }