Skip to content

Instantly share code, notes, and snippets.

@mrdomino
Created July 22, 2015 02:57
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mrdomino/0db639dca1958ffa1769 to your computer and use it in GitHub Desktop.
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static const char slash[] = "/";
int main(__attribute__((unused)) int argc, char* argv[]) {
char *self;
if (*argv[0] == '/' || !strchr(argv[0], '/')) {
self = strdup(argv[0]);
} else {
self = getcwd(NULL, 0);
self = realloc(self, strlen(self) + 1 + strlen(argv[0]) + 1);
strcat(self, slash);
strcat(self, argv[0]);
}
printf("\r%s %p", self, main);
fflush(stdout);
execvp(self, argv);
err(1, "execvp");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment