launch.c 813 B

1234567891011121314151617181920212223242526272829303132333435
  1. #define PROFILE_BASE_DIR "/mono/lib/mono/4.0"
  2. #define MONO_BINARY "/mono/bin/mono"
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <malloc.h>
  7. int
  8. main (int argc, char *argv [])
  9. {
  10. char **nargv = (char **) malloc (sizeof (char *) * (argc + 1));
  11. char *last = strrchr (argv [0], '/');
  12. char *command;
  13. int i, len;
  14. if (last == NULL){
  15. fprintf (stderr, "Do not know how to invoke the program given [%s]\n", argv [0]);
  16. return 1;
  17. }
  18. len = strlen (last) + strlen (PROFILE_BASE_DIR) + 1;
  19. command = malloc (len);
  20. if (command == NULL){
  21. fprintf (stderr, "Error allocating memory");
  22. return 1;
  23. }
  24. strcpy (command, PROFILE_BASE_DIR);
  25. strcat (command, last);
  26. nargv [0] = command;
  27. nargv [1] = command;
  28. for (i = 1; i < argc; i++)
  29. nargv [1+i] = argv [i];
  30. execvp (MONO_BINARY, nargv);
  31. }