/* * This function queries pg_config to check for specific * configure flags used to build PostgreSQL. It can be * easily modified to return true/false to the caller. * This example tests thread safety. */ #include #include #define PG_CONFIG_CMD "pg_config --configure" /* * pg_config's output should fit in one string because we don't want * the search string to split across reads. */ #define POPEN_READ 8192 int main(int argc, char *argv[]) { FILE *p; char str[POPEN_READ]; if ((p = popen(PG_CONFIG_CMD, "r")) == NULL || fgets(str, POPEN_READ, p) == NULL) { fprintf(stderr, "Cannot run \"%s\", perhaps incorrect $PATH", PG_CONFIG_CMD); if (p) pclose(p); exit(2); } pclose(p); if (strstr(str, "--enable-thread-safety") != NULL) { puts("threading enabled"); return 0; } else { puts("threading not enabled"); return 1; } }