From e989e11f5cac82bd7fe1201de099855dbaa4908b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 24 Jun 2013 20:52:01 -0500 Subject: [PATCH] - update revision via popen() (via GZDoom OS X) --- tools/updaterevision/updaterevision.c | 31 +++++++-------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/tools/updaterevision/updaterevision.c b/tools/updaterevision/updaterevision.c index c1e3ccc8f..2ae577917 100644 --- a/tools/updaterevision/updaterevision.c +++ b/tools/updaterevision/updaterevision.c @@ -29,8 +29,7 @@ void stripnl(char *str) int main(int argc, char **argv) { - char *name; - char vertag[64], lastlog[64], lasthash[64], run[256], *hash = NULL; + char vertag[64], lastlog[64], lasthash[64], *hash = NULL; FILE *stream = NULL; int gotrev = 0, needupdate = 1; @@ -47,33 +46,19 @@ int main(int argc, char **argv) // on a tag, it returns that tag. Otherwise it returns --. // Use git log to get the time of the latest commit in ISO 8601 format and its full hash. - sprintf(run, "git describe --tags && git log -1 --format=%%ai*%%H", argv[1]); - if ((name = tempnam(NULL, "gitout")) != NULL) + stream = popen("git describe --tags && git log -1 --format=%ai*%H", "r"); + + if (NULL != stream) { -#ifdef __APPLE__ - // tempnam will return errno of 2 even though it is successful for our purposes. - errno = 0; -#endif - if((stream = freopen(name, "w+b", stdout)) != NULL && - system(run) == 0 && - errno == 0 && - fseek(stream, 0, SEEK_SET) == 0 && - fgets(vertag, sizeof vertag, stream) == vertag && - fgets(lastlog, sizeof lastlog, stream) == lastlog) + if (fgets(vertag, sizeof vertag, stream) == vertag && + fgets(lastlog, sizeof lastlog, stream) == lastlog) { stripnl(vertag); stripnl(lastlog); gotrev = 1; } - } - if (stream != NULL) - { - fclose(stream); - remove(name); - } - if (name != NULL) - { - free(name); + + pclose(stream); } if (gotrev)