diff --git a/tools/mkversion.c b/tools/mkversion.c index 92b9fc9fc4d..75c251fbc24 100644 --- a/tools/mkversion.c +++ b/tools/mkversion.c @@ -50,7 +50,6 @@ static inline char *getfilepath(const char *name) static void show_usage(const char *progname) { fprintf(stderr, "USAGE: %s \n", progname); - exit(1); } /**************************************************************************** @@ -61,25 +60,29 @@ int main(int argc, char **argv, char **envp) { char *filepath; FILE *stream; + int ret = 0; if (argc != 2) { fprintf(stderr, "Unexpected number of arguments\n"); show_usage(argv[0]); + exit(1); } filepath = getfilepath(argv[1]); - if (!filepath) + if (filepath == NULL) { fprintf(stderr, "getfilepath failed\n"); - exit(2); + ret = 2; + goto exit; } stream = fopen(filepath, "r"); - if (!stream) + if (stream == NULL) { fprintf(stderr, "open %s failed: %s\n", filepath, strerror(errno)); - exit(3); + ret = 3; + goto exit; } printf("/* version.h -- Autogenerated! Do not edit. */\n\n"); @@ -92,8 +95,7 @@ int main(int argc, char **argv, char **envp) printf("#endif /* __INCLUDE_NUTTX_VERSION_H */\n"); fclose(stream); - /* Exit (without bothering to clean up allocations) */ - +exit: free(filepath); - return 0; + return ret; }