Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void rebuild_if_modified(int argc, char *argv[])
- {
- assert(argc > 0);
- const char *binary = argv[0];
- const char *source = __FILE__;
- struct stat source_stat;
- stat(source, &source_stat);
- struct stat binary_stat;
- stat(binary, &binary_stat);
- if (source_stat.st_mtime > binary_stat.st_mtime) {
- printf("%s is modified. Rebuilding myself...\n", source);
- pid_t pid = fork();
- if (pid) {
- int status = 0;
- waitpid(pid, &status, 0);
- execlp(binary, binary, NULL);
- } else {
- printf("Building build\n");
- execlp("gcc", "gcc", "-o", binary, source, NULL);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement