X-Git-Url: https://bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=test%2Ftest_x509.c;h=6f75febdef8854773311369219687f68ddb382a3;hp=344f8d92476e5e71ed72ffc8c1edb185e51e7bd1;hb=3f00688b9d9f483a6ca97e659eea104995ea15b7;hpb=2f454aad577ae53798935cc32438a2d3f02ba31f diff --git a/test/test_x509.c b/test/test_x509.c index 344f8d9..6f75feb 100644 --- a/test/test_x509.c +++ b/test/test_x509.c @@ -27,6 +27,12 @@ #include #include +#ifdef _WIN32 +#include +#else +#include +#endif + #include "bearssl.h" #define STR(x) STR_(x) @@ -1976,10 +1982,59 @@ test_name_extraction(void) } int -main(void) +main(int argc, const char *argv[]) { size_t u; +#ifdef SRCDIRNAME + /* + * We want to change the current directory to that of the + * executable, so that test files are reliably located. We + * do that only if SRCDIRNAME is defined (old Makefile would + * not do that). + */ + if (argc >= 1) { + const char *arg, *c; + + arg = argv[0]; + for (c = arg + strlen(arg);; c --) { + int sep, r; + +#ifdef _WIN32 + sep = (*c == '/') || (*c == '\\'); +#else + sep = (*c == '/'); +#endif + if (sep) { + size_t len; + char *dn; + + len = 1 + (c - arg); + dn = xmalloc(len + 1); + memcpy(dn, arg, len); + dn[len] = 0; +#ifdef _WIN32 + r = _chdir(dn); +#else + r = chdir(dn); +#endif + if (r != 0) { + fprintf(stderr, "warning: could not" + " set directory to '%s'\n", dn); + } + xfree(dn); + break; + } + if (c == arg) { + break; + } + } + } +#else + (void)argc; + (void)argv; +#endif + process_conf_file(CONFFILE); max_dp_usage = 0;