From f6437cfaed1dd0acd1ec63e1c282d0e7edfa4522 Mon Sep 17 00:00:00 2001 From: davidwed <davidwe@posteo.de> Date: 周六, 07 9月 2019 21:54:13 +0800 Subject: [PATCH] Fix a compilier error with msys2-mingw64 ( ld.exe: cannot find -ldl ) (#35) --- src/tools/bootstrap/bootstrap.cpp | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tools/bootstrap/bootstrap.cpp b/src/tools/bootstrap/bootstrap.cpp index 6b22d59..98ad6b0 100644 --- a/src/tools/bootstrap/bootstrap.cpp +++ b/src/tools/bootstrap/bootstrap.cpp @@ -3,6 +3,7 @@ #include <string> #include <stdlib.h> #include <iostream> +#include <sys/stat.h> using namespace std; namespace license { @@ -17,7 +18,7 @@ fprintf(fp, "#define PUBLIC_KEY { \\\n"); fprintf(fp, "%s", pbPublicKey.c_str()); fprintf(fp, "}\n\n"); - int random = rand() % 1000; + const int random = rand() % 1000; fprintf(fp, "#define SHARED_RANDOM %d;\n", random); fprintf(fp, "#endif\n"); fclose(fp); @@ -73,6 +74,12 @@ } } +bool file_exists (const std::string & name) +{ + struct stat buffer; + return (stat (name.c_str(), &buffer) == 0); +} + int main(int argc, char** argv) { if (argc != 3) { @@ -84,8 +91,13 @@ printf("********************************************\n"); } - string private_fname = string(argv[1]); - string public_fname(argv[2]); + const string private_fname = string(argv[1]); + const string public_fname(argv[2]); + + if (file_exists(private_fname) || file_exists(public_fname)) { + printf("Key files exist, skipping key generation. Do 'make clean' to generate new keys.\n"); + exit(0); + } license::generatePk(private_fname, public_fname); return 0; -- Gitblit v1.9.1