Add C launcher for Mono-shipped binaries
authorMiguel de Icaza <miguel@gnome.org>
Tue, 17 May 2011 13:29:47 +0000 (09:29 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Tue, 17 May 2011 13:30:11 +0000 (09:30 -0400)
scripts/launch.c [new file with mode: 0644]

diff --git a/scripts/launch.c b/scripts/launch.c
new file mode 100644 (file)
index 0000000..856f123
--- /dev/null
@@ -0,0 +1,35 @@
+#define PROFILE_BASE_DIR "/mono/lib/mono/4.0"
+#define MONO_BINARY "/mono/bin/mono"
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <malloc.h>
+
+int
+main (int argc, char *argv [])
+{
+       char **nargv = (char **) malloc (sizeof (char *) * (argc + 1));
+       char *last = strrchr (argv [0], '/');
+       char *command;
+       int i, len;
+
+       if (last == NULL){
+               fprintf (stderr, "Do not know how to invoke the program given [%s]\n", argv [0]);
+               return 1;
+       }
+       len = strlen (last) + strlen (PROFILE_BASE_DIR) + 1;
+       command = malloc (len);
+       if (command == NULL){
+               fprintf (stderr, "Error allocating memory");
+               return 1;
+       }
+       strcpy (command, PROFILE_BASE_DIR);
+       strcat (command, last);
+       nargv [0] = command;
+       nargv [1] = command;
+       
+       for (i = 1; i < argc; i++)
+               nargv [1+i] = argv [i];
+       
+       execvp (MONO_BINARY, nargv);
+}